【问题标题】:Error: transaction underpriced while deploying to rinkeby错误:部署到 rinkeby 时交易价格过低
【发布时间】:2022-01-25 06:10:29
【问题描述】:

下面的代码在控制台中的“尝试从帐户部署:..”行停止工作,一段时间后它给出“Trnsaction 未在 750 秒内开采,请确保您的交易已正确发送”,早些时候它是给出错误“交易低估”,我尝试添加gasPrice并提高gas价格,但仍然得到相同的结果。谁能帮帮我?

const hdWalletProvider = require('@truffle/hdwallet-provider')
const Web3 = require('web3')
const { interface, bytecode } = require('./compile')

const provider = new hdWalletProvider(
  'fee brass payment tiny edge spoon control trophy provide rather harbor course',
  'https://rinkeby.infura.io/v3/53ed6ca9c43446a98fb1f9f799d2ca8f'
)

const web3 = new Web3(provider)

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(JSON.parse(interface))
    .deploy({
      data: bytecode,
      arguments: ['hello there!'],
    })
    .send({ gas: '1000000', from: accounts[0] })

  console.log('Contract deployed to:' + result.options.address)
  provider.engine.stop()
}
deploy()

【问题讨论】:

    标签: javascript deployment ethereum web3 truffle


    【解决方案1】:

    改变这个:

    .deploy({
      data: bytecode,
      arguments: ['hello there!'],
    })
    

    到:

      .deploy({ data: "0x" + bytecode, arguments: ['hello there!'] })
      .send({ from: accounts[0], gas: "1000000" });
    

    【讨论】:

    • 嘿,谢谢伙计!
    • @ZohebAhmed 成功了
    猜你喜欢
    • 2019-01-07
    • 2021-09-23
    • 2021-10-22
    • 2022-06-24
    • 2018-07-14
    • 2021-11-07
    • 2022-07-21
    • 2021-11-23
    • 1970-01-01
    相关资源
    最近更新 更多