How to transfer ERC20 to deployed contract with truffle?

Viewed 57

I'm using truffle to deploy a set of smart contracts.

These contracts need to be funded with an ERC20 token (LINK). The account that is deploying the contracts has LINK and should transfer an amount to the contract.

const DemoNFT = artifacts.require("./DemoNFT.sol");
const IdentityProvider = artifacts.require("./IdentityProvider.sol");

const Web3 = require("web3");
const allConfigs = require("../config.json");
const linkABI = require("../abi/link.abi");

module.exports = async function(deployer, network) {
    const config = allConfigs[network.replace(/-fork$/, '')] || allConfigs.default;

    const provider = await IdentityProvider.deployed();
    const linkToken = new web3.eth.Contract(linkABI, config.token);

    for (let i = 0; i < config.nfts.length; i++) {
        const settings = config.nfts[i];

        await deployer.deploy(DemoNFT, settings.name, settings.symbol);
        const nft = await DemoNFT.deployed();
        await nft.setupVerification(provider.address, config.token, config.oracle, config.jobId, Web3.utils.toBN(config.fee));

        await linkToken.methods.transfer(nft.address, Web3.utils.toBN(config.fee).muln(10)).send();
    }
};

Calling this results in an error, stating that no address has been supplied for send() and there's no default address.

   Replacing 'DemoNFT'
   -------------------
   > block number:        33383565
   > block timestamp:     1661007148
   > account:             0x7775fccbfa977fEA0676CD9e2768A19008d47C7F
   > balance:             100.946846325862723725
   > gas used:            5022789 (0x4ca445)
   > gas price:           2 gwei
   > value sent:          0 ETH
   > total cost:          0.010045578 ETH


Error: No "from" address specified in neither the given options, nor the default options.

I've configured a seed for the provider in truffle.js, which results in this address.

  provider: function() {
      return new HDWalletProvider(
         process.env.MNEMONIC,
         `https://rinkeby.infura.io/v3/${process.env.INFURA_ID}`
      )
  },

However, web3.eth.getCoinbase() (and web3.eth.getAccounts()) returns a completely different address.

How can I transfer tokens from the wallet configured for the provider to the newly deployed contract in this truffle migrate script?

0 Answers
Related