Dapp web3 failed transaction

48 Views Asked by At

Hi I'm currently developing dapp and on button click user should be able to mint nft (safemint) from contract. The problem is: it goes all correct to almost the end. User gets prompted in metamask the transaction with calculated gas, and then when he confirms it's always gonna be failed transaction. I tested this on the Ethereum remix and it worked, so contract, abi,addresses are correct. Gas is also not a problem because I increased it manually and still no success. I'm doing it on the sepolia test network. Dont worry about lack of transforming metadata into metadata uri and hosting it on the remote server, in testing im using working metadataURI to test my function, and it worked in eth remix.

Code:

<script src="https://cdn.jsdelivr.net/npm/web3/dist/web3.min.js"></script>

<script>
    async function createNFT() 
    {
        event.preventDefault();
        const web3 = new Web3(window.ethereum);

        var form = document.getElementById('nftForm');
        var name = document.getElementById('inputName').value;
        
        var image = document.getElementById('inputImage').value;

        var metadata = {
            name: name,
            description: 'Your NFT description',
            image: image
        };

        var contractABI="contract abi"
        const contractAddress="contract of address user is interacting with";
        const contract = new web3.eth.Contract(contractABI, contractAddress);

        var account = '@User.Identity.Name';
        const metadataUri = "TEST METADATA URI";
        const gas = await contract.methods.safeMint(account, metadataUri).estimateGas({ from: account });

        contract.methods.safeMint(account, metadataUri)
            .send({ from: account, gas })
            .on('transactionHash', (hash) => {
                console.log('Transaction Hash:', hash);
            })
            .on('receipt', (receipt) => {
                console.log('Transaction Receipt:', receipt);
            }).on('error', console.error);

    }

</script>

The metamask itself doesn't say anything about the error or why it's failed, in console log I had this:

 Uncaught (in promise) : Transaction has been reverted by the EVM:
 {"blockHash":"0x4b0f00f15a98b9bc524d0dcd8c0555d7dd460ce741cd6f6824ac882e2bfb9e9b","blockNumber":"4924220","cumulativeGasUsed":"2045870","effectiveGasPrice":"28799071962","from":"0x6fd3cba8626a2d196d433e924471728e05aaf9d0","gasUsed":"21069","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","status":"0","to":"0x9d30fb334afa4d8973c3c3675633419007c1cd26","transactionHash":"0x7eede95e50886fdeb0e0e804550ec295c6620d974765ce4cbee9239f373ee2eb","transactionIndex":"44","type":"2"}
    r web3_error_base.js:29
    o transaction_errors.js:24
    <anonymous> transaction_errors.js:100
    getTransactionError get_transaction_error.js:45
    n get_transaction_error.js:24
    n get_transaction_error.js:20
    getTransactionError get_transaction_error.js:33
    handleResolve send_tx_helper.js:157
    n send_tx_helper.js:8
    n send_tx_helper.js:4
    handleResolve send_tx_helper.js:152
    c rpc_method_wrappers.js:363
    s rpc_method_wrappers.js:21
    promise callback*c rpc_method_wrappers.js:23
    s rpc_method_wrappers.js:21
    setTimeout handler*write/< inpage.js:19
    write inpage.js:19
    v inpage.js:19
    o inpage.js:19
    write inpage.js:19
    g inpage.js:19
    emit inpage.js:10
    _ inpage.js:19
    w inpage.js:19
    push inpage.js:19
    _write inpage.js:1
    v inpage.js:19
    o inpage.js:19
    write inpage.js:19
    d inpage.js:1
    emit inpage.js:10
    C inpage.js:1
    k inpage.js:1
    push inpage.js:1
    _onData inpage.js:1
    _onMessage inpage.js:1
0

There are 0 best solutions below