0

I have a smart contract that escrows and transfers a specific ERC20 token to and from users (with their approval). I'm a bit confused as to how to test transfers of existing tokens. Do I have to copy+paste the token contract into a dummy contract, migrate it, and use the deployed address in my contract? Or is there another feature of Truffle migrations and tests that I'm missing?

2 Answers 2

1

If you're looking to test locally (using for instance truffle and ganache) then see my answer here: https://ethereum.stackexchange.com/a/84015/3321

0

I assume you refer to testing on a public testnet? In which case a lot of tokens on there have a faucet to mint free tokens. (go to the project's website and change MetaMask to the testnet) Once you have the tokens, you can use them in your contract for testing.

If that doesn't exist or you talk about a local blockchain, then yeah you can just create an ERC-20 mock contract that allows you to mint free tokens. For any mainnet deployments you then have to use the real token address instead.

2
  • Thanks Markus! More generally, if the contract I want to test interacts with a non-token contract already deployed to kovan or mainnet, how should I interact with it from my local blockchain? Can my local send and call already-deployed contracts?
    – slider
    Commented May 29, 2020 at 3:49
  • @slider A local blockchain cannot communicate to public chains. For that you have to deploy your contract on the public chain itself. Commented May 29, 2020 at 4:54

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.