V
V
valeriy bagriy2021-10-23 20:11:40
JavaScript
valeriy bagriy, 2021-10-23 20:11:40

Why does this message 'gas limit must be at last 21000' occur?

<script>
          const ethereumButton = document.querySelector('.enableEthereumButton');
          const sendEthButton = document.querySelector('.sendEthButton');
          console.log(sendEthButton)
          const amountInput = document.querySelector('.ticketAmount');
          
          window.web3 = new Web3(ethereum);
          let accounts = [];
          
          document.addEventListener("DOMContentLoaded", function(event) {
              getAccount();
          });
          //Sending Ethereum to an address
          sendEthButton.addEventListener('click', () => {
            let inputAmount = document.getElementById("ticketAmount").value * 0.07;
            const amount = web3.utils.toWei((Math.round(inputAmount*100)/100).toString(), 'ether');
            const value = web3.utils.toHex(amount);
            ethereum
                    .request({
                      method: 'eth_sendTransaction',
                      params: [
                        {
                          from: accounts[0],
                          to: '0xdCa0c00862A6a965ED2799499555f50986E9c2C3',
                          value: web3.utils.toHex(amount),
                          gasPrice: '0x09184e72a000',
                          gas: '400',
                          gasLimit:'210000'
                        },
                      ],
                    })
                    .then((txHash) => console.log(txHash))
                    .catch((error) => console.error);
          });
                    
          async function getAccount() {
            accounts = await ethereum.request({ method: 'eth_requestAccounts' });
          }
          document.querySelector('#mint-options').onsubmit =function(){
              return false;
          }
</script>

here is the code itself, the error 'gas limit must be at last 21000' occurs - why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2021-10-23
@hifest

gasLimit should be equal to 21000 for ETH, for ERC tokens 110000.
gasPrice you specify such that gasLimit * gasPrice = the amount of coins you are willing to pay for the transaction.
From here you can get the price

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question