我想通过WEB3JS与我的智能合同进行交互。目前,我面临的问题是,在铸造令牌,它失败了。
块资源管理器上的示例:https://mumbai.polygonscan.com/tx/0x5c51ea9807abb2b99e20ca6905d4039f7f8f9ccd4c0945b17f0b4b1623273f5f
这是当前的代码:
//Adding QuickNodeAPI
var web3 = new Web3('https://restless-warmhearted-tent.matic-testnet.discover.quiknode.pro/XXXXXXXXX/%27);
// Setting wallet variables
const privateKey = 'XXXXXXX';
var WalletID = '0xc7deAF4E3C5900a725c1d5D076859c9606395620';
web3.eth.accounts.wallet.add(privateKey);
// Use the web3 instance to create the contract instance
const Contract = new web3.eth.Contract(, '')
// Creating the transaction
const tx = {
gasLimit: 500000, // Use the minimum gas limit
gasPrice: web3.utils.toWei('20', 'gwei'), // Set the gas price to 20 gwei
nonce: web3.eth.getTransactionCount(WalletID),
data: Contract.methods.mint('0xc7deAF4E3C5900a725c1d5D076859c9606395620', web3.utils.toWei('3', 'ether')).encodeABI(),
};
//Signing transaction and error handeling
web3.eth.accounts.signTransaction(tx, privateKey).then(signed => {
web3.eth.sendSignedTransaction(signed.rawTransaction).on('transactionHash', txHash => {
web3.eth.getTransactionReceipt(txHash).then(receipt => {
if (receipt) {
console.log('Transaction confirmed')
} else {
console.log('Transaction pending')
}
});
});
}) 非常感谢你抽出时间。
发布于 2022-12-09 11:25:54
您需要将契约的地址(目的地)添加到您的事务中。
可能在这里
const tx = {
to: 'the-address-of-the-contract'
gasLimit: 500000, // Use the minimum gas limit
gasPrice: web3.utils.toWei('20', 'gwei'), // Set the gas price to 20 gwei
nonce: web3.eth.getTransactionCount(WalletID),
data: Contract.methods.mint('0xc7deAF4E3C5900a725c1d5D076859c9606395620', web3.utils.toWei('3', 'ether')).encodeABI(),
};如果没有正确的to,evm认为您正在尝试创建一个契约。你可以在多边形扫描仪上看到它写着“创建了合同0x022da72497c5e5f4476e6ca3123ae48a52a0e0”并失败了。

https://ethereum.stackexchange.com/questions/140908
复制相似问题