1

I'm developing an Smart Contract based in the Openzeppelin's Crowdsale one. When I test the Crowdsale Smart Contract manually, sending ETH with metamask, the SC returns me the correct amount of tokens.

But when I try to do the same (send ETH to the Smart Contract's address) I always get an error on Metamask before sending the amount.

I have tried with: sendTransaction

web3.eth.sendTransaction({'to': toaddr, 'from': fromAddress, 'value': bnb_value})

(If I change the contract's address with a wallet address, the function sends the ETH correctly to the given wallet address, but not when the address is a contract addres).

buyTokens function

 ico_contract.methods.buyTokens(fromaddr).estimateGas({
          "value": bnb_value,
          "from": fromAddress
        })

I do not know how to continue...

1
  • What is the address you are sending the ETH from (In both cases?) Is it the same or?
    – Sky
    Commented Oct 12, 2021 at 8:51

1 Answer 1

0

I found the answer and everything was because of not providing gasLimit parameter (and also because of manually testing the contract ended with no tokens). I set the gasLimit param in the request with estimateGas() function and everything worked fine.

            let gaslimit;
            web3.eth.estimateGas({
              nonce: web3.utils.toHex(nonce),
              gasPrice: gasPrice,
              value: bnb_value,
              from: fromaddr,
              to: toaddr,
              chainId: web3.utils.toHex(97)
              })
              .then(function(gas) {
                gaslimit = web3.utils.toHex(gas);
              })
              .catch(function(error) {
                console.error(error);
              });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.