Web3:我的部署被困在测试ETH网络上。 [错误:未能检查交易收据:使用Contract.Deploy()]

发布于 2025-02-01 07:51:58 字数 2215 浏览 1 评论 0 原文

我试图使用节点部署合同。我正在关注YouTube教程

我会根据本教程关注所有内容,但是每次运行“ node decloy.js”时,我都会收到超时错误:(注意我还没有使用任何松露框架。)

process["on"]("unhandledRejection", function (reason) { throw reason; });
                                                            ^

Error: Failed to check for transaction receipt:
{}
    at Object._fireError (C:\Users\schit\Desktop\Solidity Dapp\inbox\node_modules\web3-utils\lib\index.js:49:17)
    at C:\Users\schit\Desktop\Solidity Dapp\inbox\node_modules\web3-core-method\lib\index.js:246:23

我的代码如下:

const HDWalletProvider = require('@truffle/hdwallet-provider');
const Web3 = require('web3');
const interface = require('./compile.js');

let abi = interface.abi;
let bytecode = interface.bytecode;

var mnemonic = '12-word mnemonic';
var endpoint = 'https://ropsten.infura.io/v3/<key>';


const provider = new HDWalletProvider({
    mnemonic: {
      phrase: mnemonic
    },
    providerOrUrl: endpoint
  });

console.log('********DEBUG*LOG**********2');
const options = {
  transactionConfirmationBlocks: 1
};
const web3 = new Web3(provider, null, options);

console.log('********DEBUG*LOG**********3')

const deploy = async () => {
    const accounts = await web3.eth.getAccounts();
    var balance = await web3.eth.getBalance(accounts[0]);
    console.log('Account balance: ', web3.utils.fromWei(balance, "ether"));
    

    console.log('Attempting to deploy from account', accounts[0]);
    var contract = new web3.eth.Contract(abi);
    **const result = await contract
                   .deploy({data: '0x' + bytecode, arguments: ['Hi there!']})
                   .send({from: accounts[0], gas: '1000000'})
                   .on ('error', console.error)
                   .on ('transactionHash', console.log)      
                   .on ('receipt', console.log);**     
 
    console.log('Contract deployed to', result.options.address);
  
};

deploy();

I trying to deploy my contract using node. I am following a youtube tutorial https://www.youtube.com/watch?v=3oaJynB0nKc&list=PLzb46hGUzitDd39YzB1YvZqeIXXtmBrHX&index=26.

I'm following everything according to this tutorial but every time I run "node deploy.js", I either get timeout error: (Note I am not using any truffle framework yet.)

process["on"]("unhandledRejection", function (reason) { throw reason; });
                                                            ^

Error: Failed to check for transaction receipt:
{}
    at Object._fireError (C:\Users\schit\Desktop\Solidity Dapp\inbox\node_modules\web3-utils\lib\index.js:49:17)
    at C:\Users\schit\Desktop\Solidity Dapp\inbox\node_modules\web3-core-method\lib\index.js:246:23

My code is as follows:

const HDWalletProvider = require('@truffle/hdwallet-provider');
const Web3 = require('web3');
const interface = require('./compile.js');

let abi = interface.abi;
let bytecode = interface.bytecode;

var mnemonic = '12-word mnemonic';
var endpoint = 'https://ropsten.infura.io/v3/<key>';


const provider = new HDWalletProvider({
    mnemonic: {
      phrase: mnemonic
    },
    providerOrUrl: endpoint
  });

console.log('********DEBUG*LOG**********2');
const options = {
  transactionConfirmationBlocks: 1
};
const web3 = new Web3(provider, null, options);

console.log('********DEBUG*LOG**********3')

const deploy = async () => {
    const accounts = await web3.eth.getAccounts();
    var balance = await web3.eth.getBalance(accounts[0]);
    console.log('Account balance: ', web3.utils.fromWei(balance, "ether"));
    

    console.log('Attempting to deploy from account', accounts[0]);
    var contract = new web3.eth.Contract(abi);
    **const result = await contract
                   .deploy({data: '0x' + bytecode, arguments: ['Hi there!']})
                   .send({from: accounts[0], gas: '1000000'})
                   .on ('error', console.error)
                   .on ('transactionHash', console.log)      
                   .on ('receipt', console.log);**     
 
    console.log('Contract deployed to', result.options.address);
  
};

deploy();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文