How to call function of a deployed smart contract address?

Lets say i have one contract that is deployed on ropsten testnet.
I have its adress.
Now in contract B i want to instantiate the contract A adress in a variable then call its function.
Is it possible?
Or whats the best way to call function of another smart contract if you have only its address in solidity

Sep 22, 2020, 11:53 AM
You don't want to instantiate the contract - you want to create a reference to the contract. So here's how it happens, roughly:
1) You create an interface which has the functionality you need from the other contract
2) Add that interface code as part of your contract B deployment (probably in the same file)
3) Reference the contract A like this: InterfaceOfContractA ref = InterfaceOfContractA (addressOfContractA)
4) Because it uses the interface you can directly use the other contract's functionality like: ref.somefunction()

This is assuming that you know the functionality you want to call. If you don't...well.. what's the point of calling it? :)
Sep 22, 2020, 12:16 PM

© 2024 Draquery.com All rights reserved.