NEWTON

NEWTON


Popular tags

    The only way to invoke a contract is using migrations (this applies for both devnet and testnet?)

    Asked

    4 months ago

    124

    views


    0

    Some questions that could be answered separately.

    1. The only way to invoke a contract is using migrations (this applies for both devnet and testnet?)
    2. When doing a migration file I receive the “Hint is not whitelisted. This may indicate that this library function cannot be used in StarkNet contracts.” error. For example for this code:
    %lang starknet
    
    @external
    func up() {
        %{
            contract_address = deploy_contract(
                 "./build/main.json",
                 config={"wait_for_acceptance": True}
            ).contract_address
    
            invoke(
                contract_address,
                "initialize",
                {"new_authority": 123},
                config={
                    "auto_estimate_fee": True,
                    "wait_for_acceptance": True,
                }
            )
        %}
    
        return ();
    }
    

    This question was originally posted on StarkNet Discord

      discordcairo

    Newton

    asked

    4 months ago


    1 answers

    0

    Accepted answer

    1. Currently, invoke can be only used from migration scripts. We will add invoke and call commands in a future release. https://github.com/software-mansion/protostar/issues/883
    2. I couldn't replicate this problem. The migration script runner doesn't validate hints. I think the issue may be in the contract. Does this issue occur for the "main" contract generated by protostar init? Maybe the main.json is outdated. How do you run migration scripts?

    You can check our integration tests for the invoke cheatcode in the version 0.4.2: https://github.com/software-mansion/protostar/blob/53cb5dc5cda1a74a1ffb862d84e7035e44a5c56b/tests/integration/migrator/migrator_invoke_cheatcode_test.py (The deploy_contract cheatcode will be deprecated in the next release. Declare cheatcode should be used instead.)

    Regarding best practices, migration scripts are intended to be used with Proxy pattern. Protostar's migrations are inspired by Truffle. https://trufflesuite.com/docs/truffle/getting-started/running-migrations/

    FYI: migrations needs polishing. In 0.4.3 for example, you should be able to deploy or declare contract by specifying a contract name (e.g. declare("main")) to avoid using outdated compiled contract by accident.

    This answer was originally posted on StarkNet Discord

    Newton

    answered

    4 months ago

    Your answer

    NEWTON

    NEWTON