0

I'm creating a dapp that charges users a specific amount of eth depending on their input.

Whenever I attempt to create the transaction, I specify the amount of Eth in Wei. It throws an Error with no description as to why it couldn't fulfill the transaction

Error: Error Minting New NFT at MintNewNFT (Transactions.js:68) at Object.onClick (index.js:62)

(Line 62 is the catch block)

AmountIn is 0.02166 ETH

Here is my code :

 export const MintNewNFT = async (WalletABI,address, network, mediaID, amountIn) => {

  try {
    
    
    //adjust this to take an argument for media id
    
    const web3 = new Web3('https://rinkeby.infura.io/v3/key');
    const weiValue = Web3.utils.toWei(amountIn.toString(), 'ether');
    console.log(weiValue , mediaID);
    
    const transactionParameters = {
      to: WalletABI._address, // Required except during contract publications.
      from: address, // must match user's active address.
      value: weiValue.toString(), 
      data: web3.eth.abi.encodeFunctionCall(    
        {
          "inputs": [
          {
            "internalType": "bytes32",
            "name": "mediaID",
            "type": "bytes32"
          }
        ],
        "name": "mintNewNFT",
        "outputs": [],
        "stateMutability": "payable",
        "type": "function",
        "payable": true
        
      },[mediaID]),
      chainId: `0x${network}`, // Used to prevent transaction reuse across blockchains. Auto-filled by MetaMask.
    };
    
  
    
    // txHash is a hex string
    // As with any RPC call, it may throw an error
    await window.ethereum.request({
      method: 'eth_sendTransaction',
      params: [transactionParameters],
    }).then((result) => {

      // The result varies by by RPC method.
      // For example, this method will return a transaction hash hexadecimal string on success.

      console.log(`Transaction Result ${result}`)


    })
    .catch((error) => {
      // If the request fails, the Promise will reject with an error.

      console.log(`Transaction ERROR :  ${error.message}`)
    });

    

} catch (error) {
    throw Error("Error Minting New NFT", error)
}
}

Any indication as to what I may be doing wrong would be very much appreciated

3
  • What are the values of amountIn and weiValue ?
    – Ismael
    Commented Jun 4, 2021 at 18:51
  • Amount in : 0.02166 || toWei : 21660000000000000
    – 0xD1x0n
    Commented Jun 4, 2021 at 19:41
  • i changed data param to web3.eth.abi.encodeFunctionCall since it expects a parameter
    – 0xD1x0n
    Commented Jun 4, 2021 at 19:42

1 Answer 1

0

Well.... I fixed my issue. Turns out it was failing because i was using a bytes32 instead of a string for the argument. i cant really explain why this happened incase anyone else can

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.