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

184
Views
web3.js Transaction failing but working directly on etherscan

The contract in reference can be found at - https://rinkeby.etherscan.io/address/0x0e04ca9e56af778424b94eb904da9d97a63582f8

I'm trying to call the payUser function where the user sends some eth and based on the amount of eth the user is transferred some tokens.

The code written in javascript is

var current_user_account = ""
var abi_token_contract = ""
var token_contract = ""
const address_token_contract = "0x0E04Ca9E56AF778424B94EB904Da9D97A63582F8"

const web = new Web3("https://rinkeby.infura.io/v3/XXXXXXXXXXXXXXXXX")

$.ajax({
    url: "https://api-rinkeby.etherscan.io/api?module=contract&action=getabi&address=0x0E04Ca9E56AF778424B94EB904Da9D97A63582F8&apikey=XXXXXXXXXXXXXXXXX",
    dataType: "json",
    success: function (data) {
        abi_token_contract = JSON.parse(data.result)
        token_contract = new web.eth.Contract(abi_token_contract, address_token_contract)
    }
});

window.addEventListener('load', async () => {

    if (window.ethereum) {
        try {
            const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
            current_user_account = accounts[0]
        } catch (error) {
            if (error.code === 4001) {
                // User rejected request
            }

            setError(error);
        }
        window.ethereum.on('accountsChanged', (accounts) => {
            current_user_account = accounts[0]
        });

    } else {
        window.alert(
            "Non-Ethereum browser detected. You should consider trying MetaMask!"
        );
    }
})


async function send(transaction, value = 0) {
    const params = [{
        from: current_user_account,
        to: transaction._parent._address,
        data: transaction.encodeABI(),
        gas: '0x186a0',
        gasPrice: null,
        value: web.utils.toHex(value)
    },]

    window.ethereum.request({
        method: 'eth_sendTransaction',
        params,
    })
}

function getTokens() {
    token_count_rs = parseFloat($("#token_num").val().trim()) * 10
    $.ajax({
        url: "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=INR&tsyms=ETH",
        dataType: "json",
        success: function (data) {
            amount_tobe_payed = (data.RAW.INR.ETH.OPEN24HOUR * token_count_rs).toFixed(18);
            send(token_contract.methods.payUser(address_token_contract, current_user_account), web.utils.toWei(amount_tobe_payed, "ether"))
        }
    });
}

I'm not understanding why the transaction is failing with javascript and working on etherscan "Write" section

about 4 years ago · Juan Pablo Isaza
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!