1
votes

Learning Solidity along with token development.

I'm having a hard time understanding how tokens with multiple smart contracts interact with each other.

I've read through other tokens with multiple contracts on GitHub and reviewed contracts on OpenZeppelin but they all appear somewhat orphaned.

Let's say we developed a token that has a supply and tracks wallet address to amount using a map. The contract is released and is given an address. Admin or privilege methods are protected via owner address validation. Then we release a second contract that needs to make apply a fee for transactions.

How does the second (token transaction fees) contract interact with the data stored on the first (token contract)? Does the second contract need to also verify ownership?

1

1 Answers

1
votes

Any contract on Ethereum can interact with any other contract by using Interfaces. You can call methods from the second contract on the first contract for an ERC20 token as below:

  1. Define ERC20 Interface
interface ERC20 {
    function balanceOf(address account) external view returns (uint256);
}
  1. Use the interface and token contract address to call methods on the first contract:
ERC20(tokenContractAddress).balanceOf(0xabcd....);

The similar approach can be used for any contracts