首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WEB3JS事务裁剪

WEB3JS事务裁剪
EN

Ethereum用户
提问于 2022-12-09 08:38:18
回答 1查看 46关注 0票数 0

我想通过WEB3JS与我的智能合同进行交互。目前,我面临的问题是,在铸造令牌,它失败了。

块资源管理器上的示例:https://mumbai.polygonscan.com/tx/0x5c51ea9807abb2b99e20ca6905d4039f7f8f9ccd4c0945b17f0b4b1623273f5f

这是当前的代码:

代码语言:javascript
复制
        //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')
              }
            });
          });
        }) 

非常感谢你抽出时间。

EN

回答 1

Ethereum用户

回答已采纳

发布于 2022-12-09 11:25:54

您需要将契约的地址(目的地)添加到您的事务中。

可能在这里

代码语言:javascript
复制
      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”并失败了。

票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/140908

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档