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

123
Visualizações
Sending BNB with web3js won't log errors

I have this code that allows me to send bnb using web3.js using MetaMask I want to display a message when user rejects payment or there is any other error and if it is successful, display a success message. I can not find my way around it.

My Code is

$(".pay-button").click(async () => {
        await initWeb3('https://bsc-dataseed1.binance.org:443');
        // paymentAddress is where funds will be send to
        const web3 = new Web3('https://bsc-dataseed1.binance.org:443');
const reciever = '0x5c03906C1c6f737eF982BDdA481D2E04D0089155';

            ethereum.request({
            method: 'eth_sendTransaction',
            params: [
                {
                    from: ethereum.selectedAddress,
                    to: reciever,
                    value: web3.toHex(web3.toWei('0.001', 'ether')),
                     gas: '0x76c0', // 30400
    gasPrice: '', // 10000000000000
    
                },
            ],
            })
            .then((txHash) => console.log(txHash))
            .catch((error) => console.error);
   
      });

I am using this package https://unpkg.com/@metamask/legacy-web3@latest/dist/metamask.web3.min.js

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can try to check for the following error codes that are emitted by Metamask and tweak you UI accordingly.

Error codes given by metamask

https://docs.metamask.io/guide/ethereum-provider.html#events

If your transaction is success, i.e. when you receive the txHash, you can show success message in the UI https://github.com/skiran017/sol-tip-jar/blob/main/src/modules/TipWidget/TipWidget.tsx transaction status here is doing some similar job

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