Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!