Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

149
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda