Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

152
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda