Web3.eth.abi.encodeFunctionCall Is not working



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

每当我试图创建交易时,我都会指定Eth在Wei中的金额。它抛出一个错误,没有说明为什么它不能完成事务

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

(第62行为捕获块(

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

非常感谢任何关于我可能做错了什么的指示

它失败了,因为我使用了字节32而不是字符串作为参数。我不知道为什么这是个问题。

最新更新