微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Web3.eth.abi.encodeFunctionCall 不起作用

如何解决Web3.eth.abi.encodeFunctionCall 不起作用

我正在创建一个 dapp,它根据用户的输入向用户收取特定数量的 eth。

每当我尝试创建交易时,我都会在 Wei 中指定 Eth 的数量。它抛出一个错误,没有说明为什么它无法完成交易

错误生成新 NFT 时出错 在 MintNewNFT (Transactions.js:68) 在 Object.onClick (index.js:62)

(第 62 行是 catch 块)

AmountIn 为 0.02166 ETH

这是我的代码

 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)
}
}

任何关于我可能做错了什么的迹象将不胜感激

解决方法

嗯……我解决了我的问题。原来它失败了,因为我使用的是 bytes32 而不是字符串作为参数。我真的无法解释为什么会发生这种情况,因为其他人可以

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?