Given an interface that refers to an ERC20 token contract named XYZ, and a constructor that refers to a variable of type XYZ, how do you refer to the XYZ token contract in a contract deployment function?

Here is the interface and contract:

interface XYZ {}

contract MyContract {
    XYZ public token;

        XYZ _token
    ) public {
        token = _token;

I've been trying to use the contract address of the XYZ token contract but I don't think it's working. I tried passing it as an integer and a string, but can't find anything online that talks about what to use for deployment. Here is my deployment function (using Truffle with a mainnet fork on ganache-cli):

const MyContract = artifacts.require("MyContract");
module.exports = async function (deployer) {
   await deployer.deploy(MyContract, 0x587242da6dde74aA602AF3595d271333421c7E20);

What should take the place of 0x587242da6dde74aA602AF3595d271333421c7E20 (the XYZ token contract address)? Thanks!


Javascript doesn't support integers of arbitrary length yet.

You need to pass addresses as a string.

const MyContract = artifacts.require("MyContract");
module.exports = async function (deployer) {
   await deployer.deploy(MyContract, "0x587242da6dde74aA602AF3595d271333421c7E20");
  • Ok awesome thanks. But is an address string what should be passed as a parameter for that variable type? I tried it as a string and the contract still won't deploy with truffle on a mainnet fork I'm using from Infura. Maybe it's a Truffle problem? I first deploy my own token contract, grab the address for that and then use that to deploy another contract like the one above. But nothing gets deployed, Truffle is just saying there is nothing to compile, everything is up to date. I guess the problem lies elswhere?
    – JohnWLIV
    Feb 19 at 7:03
  • @JohnWLIV From javascript contracts has to be passed as addresses, if you try to pass as an object web3 will fail. Truffle keeps a record of last successful migrations and won't migrate a step that previously succeeded if there were no changes. You can try to force them adding --reset switch, but I never tried that on a fork. The nuclear options is to remove build/ directory that will force truffle to recompile everything and then restart the forked ganache instance.
    – Ismael
    Feb 19 at 14:54

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.