I'm trying to create a Farming smart-contract. I'm completely new to solidity so i want to know if there's a way i can import an existing token from the blockchain, then call methods on that token's contract from my farm.

In tutorials I've seen, i see them create a "Fake token" then import it from same directory. My curiosity is; what if the token i want the users to deposit is already deployed to the network, how do i import that token so i can be able to call methods like transfer/transfer from on it.


Assuming you're using EVM compatible blockchain, you can interact with any deployed tokens on the network if you have the token ABI (if it's just simple ERC20 token you can use ERC20 abi) and the contract address.

If you want to allow your contract to call another token, first include the token contract interface in your code, initialise a token contract instance, then call a method using the instance. The code would look like this:

import './IERC20.sol';

contract MyContract {

  IERC20 private someToken = IERC20("0x..") // Token contract address

  function Foo() public {
  • Thank you, I will implement this in my contract and see if it fixes my problem, really appreciate your feedback. Sep 12 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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