0

I found a similar answer for this question here, but I am using hardhat and ethers for my testing.

I am just sending erc20 to my contract and here is my test file:

it("Transferring Tokens to myContract",async function(){

      // const WETHTransferAmount10 = parseUnits("10", 18);
      const WETHTransferAmount10 = 10;

      console.log("myContract WETH Balance before Transfer: ",formatUnits(await WETHLocalContract.balanceOf(FactoryContract.address)));

      console.log("WETHAddress Eth Balance: ",formatUnits(await ethers.provider.getBalance(WETHcontractAddress)));

      // Approving FactoryContract with tokens
      await WETHLocalContract.connect(WETHSigner);
      await WETHLocalContract.approve(FactoryContract.address,WETHTransferAmount10);

      
      // await WETHSigner.sendTransaction(await WETHLocalContract.approve(FactoryContract.address,WETHTransferAmount10));
      
      // console.log("ALLowance is: ", formatUnits(await WETHLocalContract.allowance(WETHSigner.address,FactoryContract.address)));

      // Transferring the token
      console.log("Balance of WETH owner in WETH: ", formatUnits(await WETHLocalContract.balanceOf(WETHSigner.address)));
      await FactoryContract.connect(WETHSigner).stakeToken(WETHcontractAddress,WETHTransferAmount10)

stakeToken function has just this line for now

ERC20Interface(token).transferFrom(msg.sender, address(this), amount);
2
0

How much is your balance before sending the transaction. the error says that you don't have enough balance to pay for the transaction. also you should know that the balance must be equal to the balance you are setting as maximum.

so in your transaction, if you are setting a 20GWei price and 10GWei of gas Amount you will need to have in balance the equivalent of 200GWei (price * amount ) as balance before even sending the transaction.

in your case check hardHat's default config of price and amount set for all transactions.

Also, this error is thrown before the transaction is sent to the network, so it has nothing to do with the blockchain itself.

3
  • I have enough balance: WETHHolder Eth Balance: 6936711.957134258047662892 Balance of WETH owner in WETH: 123577.577905175390133903 Jul 14 at 18:56
  • How does the staking in your contract works? if the contract wallet doesn't have enough balance and it tries to make a transaction it will error out the same way you mentioned. Jul 14 at 19:00
  • Thanks. I updated my hardhat package and tried the main net forking block number which resolved the error. Jul 14 at 19:14
0

Make sure the mnemonic variable in truffle.js file matches the one from your local blockchain, Ganache.

New contributor
Fernando Maximo is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

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.