首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:事务在750秒内未被挖掘,请确保您的事务已正确发送。注意它可能还被埋在地雷里!

错误:事务在750秒内未被挖掘,请确保您的事务已正确发送。注意它可能还被埋在地雷里!
EN

Ethereum用户
提问于 2020-02-27 05:35:12
回答 2查看 10.8K关注 0票数 4

这是我的delpoy.js文件:

代码语言:javascript
复制
const HDWalletProvider = require("@truffle/hdwallet-provider");
const Web3 = require('web3');
const {abi , bytecode} = require('./compile');
const provider = new HDWalletProvider(
    'december blossom school two brief lunar siren truth purse violin car submit',
    'https://rinkeby.infura.io/v3/737d5964ada94e2a8d812f1414c89c4e'
)
const web3 = new Web3(provider)
async function scan(message) {
    process.stdout.write(message);
    return await new Promise(function(resolve, reject) {
        process.stdin.resume();
        process.stdin.once("data", function(data) {
            process.stdin.pause();
            resolve(data.toString().trim());
        });
    });
}

async function getGasPrice(web3) {
    while (true) {
        const nodeGasPrice = await web3.eth.getGasPrice();
        const userGasPrice = await scan(`Enter gas-price or leave empty to use ${nodeGasPrice}: `);
        if (/^\d+$/.test(userGasPrice))
            return userGasPrice;
        if (userGasPrice == "")
            return nodeGasPrice;
        console.log("Illegal gas-price");
    }
}

const deploy = async() =>{
    const accounts = await web3.eth.getAccounts();
    console.log('attempting to deploy from account',accounts[0])
    const result = await new web3.eth.Contract(abi)
        .deploy({data:'0x' +bytecode ,arguments: ['hii']})
        .send({from: accounts[0],gas: 1500000,gasPrice: await getGasPrice(web3)})
    console.log('contract deployed to', result.options.address);
}
deploy()

输出:

代码语言:javascript
复制
node deploy.js
attempting to deploy from account 0x010Ff624891610c8538824AB6F5AF4abfD1c3bfd
Enter gas-price or leave empty to use 1000000000: 1000000000
Error: Transaction was not mined within 750 seconds, please make sure your transaction was properly sent. Be aware that it might still be mined!
Error: Transaction was not mined within 750 seconds, please make sure your transaction was properly sent. Be aware that it might still be mined!
D:\github\blockchain\solidity-etherium\index\node_modules\solc\soljson.js:1
(function (exports, require, module, __filename, __dirname) { "use strict";var Module=typeof Module!=="undefined"?Module:{};var moduleOverrides={};var key;for(key in
Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var arguments_=[];var thisProgram="./this.program";var quit_=function(status,toThrow){throw toThrow};var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;var ENVIRONMENT_HAS_NODE=false;var ENVIRONMENT_IS_SHELL=false;ENVIRONMENT_IS_WEB=typeof window==="object";ENVIRONMENT_IS_WORKER=typeof importScripts==="function";ENVIRONMENT_HAS_NODE=typeof process==="object"&&typeof process.versions==="object"&&typeof process.versions.node==="string";ENVIRONMENT_IS_NODE=ENVIRONMENT_HAS_NODE&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;var scriptDirectory="";function locateFile(path){if(Modu

RuntimeError: abort(Error: Transaction was not mined within 750 seconds, please make sure your transaction was properly sent. Be aware that it might still be mined!). Build with -s ASSERTIONS=1 for more info.
    at process.abort (D:\github\blockchain\solidity-etherium\index\node_modules\solc\soljson.js:1:14506)
    at process.emit (events.js:189:13)
    at emitPromiseRejectionWarnings (internal/process/promises.js:119:20)
    at process._tickCallback (internal/process/next_tick.js:69:34)
EN

回答 2

Ethereum用户

发布于 2020-02-27 08:53:53

这是一个合法的情况,这是典型的情况下,以较高的天然气价格已经提交了大约与你的时间。

您可以扩展您的代码,以便稍后检查事务状态,或者增加天然气价格并重试执行事务。

请记住,在重试时要使用相同的NO一次性,这样您的事务就不会被执行两次。

另外,请记住,这两次尝试中的一次肯定会恢复,因此您也需要捕获并处理该错误。

正如您所理解的,处理所有执行事务的场景可能相当复杂。

特别是您当前处理的错误,因为尽管您得到了异常,但并不意味着您的事务已经恢复(也就是说,您需要处理的是“既不成功也不是失败”的场景)。

提高你们交易的天然气价格:

由于您没有在代码中指定它,所以您要发送给它的节点使用默认值,它是作为最后N个事务的某种加权平均值计算的。

因此,几个同时提交较高油价的交易可以“降低”交易的优先级,使其“陷入池中”。

因此,在执行事务之前找到默认值,然后使用更高的值。

例如:

代码语言:javascript
复制
const Web3 = require("web3");

async function scan(message) {
    process.stdout.write(message);
    return await new Promise(function(resolve, reject) {
        process.stdin.resume();
        process.stdin.once("data", function(data) {
            process.stdin.pause();
            resolve(data.toString().trim());
        });
    });
}

async function getGasPrice(web3) {
    while (true) {
        const nodeGasPrice = await web3.eth.getGasPrice();
        const userGasPrice = await scan(`Enter gas-price or leave empty to use ${nodeGasPrice}: `);
        if (/^\d+$/.test(userGasPrice))
            return userGasPrice;
        if (userGasPrice == "")
            return nodeGasPrice;
        console.log("Illegal gas-price");
    }
}

...

const web3 = new Web3(provider)
const deploy = async() =>{
    ...
    .send({
        gas: 1500000,
        gasPrice: await getGasPrice(),
        from: accounts[0]
    })
    ...
}
票数 4
EN

Ethereum用户

发布于 2021-02-06 20:08:07

嗨,我遇到了与您的代码错误相同的问题

代码语言:javascript
复制
const hdwalletprovider=require('truffle-hdwallet-provider');
const Web3=require('web3');
const {interface,bytecode}=require('./compile');

const provider=new hdwalletprovider(
    '', 
    'https://rinkeby.infura.io/v3/'

);

const web3=new Web3(provider);

const deploy=async() => {
    const accounts= await web3.eth.getAccounts();
    console.log(accounts[0]);

    const result=await new web3.eth.Contract(JSON.parse(interface))
    .deploy({data : bytecode})
    .send({gas: '1000000', from: accounts[0] });
    console.log(interface);
    console.log("HI");
    console.log(result.options.address);
};

deploy();

我得到了与您的代码相同的错误,我在这里做的错误是我发送了大量的气体,所以我将我的气体量减少到1百万,我的代码工作:)

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

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

复制
相关文章

相似问题

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