0

Suppose a contract,which is working with ERC20, lets call it contract-1, is already deployed onchain and functioning properly in real world. I want to add some functionality in it. But as we know smart contracts can't be changed after deployment so i decided to use the interface of that contract in newly created contract, lets call it contract-2, with added functionality. As i said contract-1 already has users and tokens are already distributed, so the added functionality will be like if some one mint 10000 token they will get reward,my question is, is it possible to get the current status, like who has how many tokens, of contract-1 from contract-2 [by calling functions from contract-2] ???? I want to do this. How can do it??

1 Answer 1

3

Yeah, this is super simple.

First, you will need the deployed contract address, and second, the contract interface.(interface makes things easier than using call method).

Then you can wrap the address inside the interface like this

interfaceName contract1 = interfaceName(ADDRESS);

And now the contract1 variable will contain every function of the deployed contract, and you can call them like this: (Suppose a function named Balance(address))

contract1.Balance(address);

This way you can call the functions, but remember only the external and public functions can be called.

Let me know if this was clear or I'll try to improve the answer.

3
  • Yeah i know that but i want to know if i wanna get the current status of any functionality of contract-1 is it possible using interface?? let say , it has a mapping like mapping(address->uint256) public balances, so if i query like this IContract-1(<contract-1_address).balances[user_address] from contract-2 can i get the balance??
    – Hacek
    May 28, 2023 at 13:07
  • If the mapping is public then yes you can. May 28, 2023 at 16:58
  • make sure to mark it as an answer if it helped. May 29, 2023 at 4:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.