Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
How to transfer ERC20 to deployed contract with truffle?

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think this might cause issue:

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

you are passing the relative file location but you should be passing the name of the contract

const DemoNFT = artifacts.require("nameOfSolidityContract");

if its name is DemoNFT

artifacts.require("DemoNFT")

From the docs:

The name specified should match the name of the contract definition within that source file. Do not pass the name of the source file, as files can contain more than one contract.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!