Interacting with contract

#brownie has an accounts package
from brownie import accounts, config, SimpleStorage

#put all the deplyment logic in one fucntion:
def deploy_simple_storage():
    
    #local ganache accounts
    account = accounts[0]

    #import contract into script: from brownie import <name of contract>
    simple_storage = SimpleStorage.deploy({"from": account})

    #interact with smart contract, like remix
    stored_value = simple_storage.retrieve()  #view function, no need transaction - no need account
    print(stored_value)

    #updating state
    txn = simple_storage.store(3, {"from":account})
    txn.wait(1)
    updated_stored_value = simple_storage.retrieve()
    print(updated_stored_value)
    

def main():
    deploy_simple_storage()

retrieve: view function

    stored_value = simple_storage.retrieve()  
    print(stored_value)

retrieve is a view function in SimpleStorage.sol. view functions operate on calls, not transactions, so we do not need to define an account here.

store: mutable function

   #updating state
    txn = simple_storage.store(3, {"from":account})
    txn.wait(1)
    
    updated_stored_value = simple_storage.retrieve()
    print(updated_stored_value)

calling store requires a transaction and gas to be paid, so we need to define the account. the 3 is passed into uint favNum.

txn.wait is important for "mining".

Last updated