Interacting with already deployed contracts on brownie framework

337 Views Asked by At

Just thought I would put this here for anyone with a similar issue to me.

I had deployed a contract on the seplia testnet in brownie, but could not figure out how to interact with my already-deployed contract. Reading through the docs seemed to confuse me further, but I figured it out in a bit.

When you deploy a contract locally, then disconnect from the network, the contract address is still stored in some sort of 'cahce' in brownie. You have to create a contract object to get its methods attached to the contract.

Example: def interact(): x = Contract("CONTRACT ADDRESS DEPLOYED AT ON SEPOLIA") y = x.getBalance("<PARAM>") print(y)

I was able to fix this issue and hopefully this helps someone else!

1

There are 1 best solutions below

0
Saikat Karmakar On

The correct syntax for reading a already deployed contract is like this

from brownie import <Contract name>

contract = Contract.at(<address>)
[..]