ruby Eth::Client::ContractExecutionError - transaction underpriced

olqngx59  于 2023-10-17  发布在  Ruby
关注(0)|答案(1)|浏览(139)

我正在使用eth gem ruby库https://q9f.github.io/eth.rb/执行一个从ABI调用的函数,但它一直得到错误交易低估。我假设它与汽油价格有关,所以我设置了汽油价格,但仍然给我错误。请注意,调用依赖于获取信息的函数,如“balanceOf”,工作正常。
验证码:

def self.mint(mint_address, mint_amount)
      signer = Eth::Key.new(priv: @@private_key)

      client = Eth::Client.create "https://polygon-mainnet.g.alchemy.com/v2/API"
      
      contract_name = "WOW"
      wow_contract = Eth::Contract.from_abi(abi: @@abiWOW.to_json, address:  @@master_contract_address, name: contract_name)
      wow_contract.key = signer

      # Convert Gwei to Wei for the gas price. 1 Gwei = 1e9 Wei.
      gas_price = 170 * 1e9

      # Set gas_price for the contract
      wow_contract.gas_price = gas_price
      wow_contract.gas_limit = 200000

      puts "gas price: #{wow_contract.gas_price}"
           
      mint_amount_in_smallest_unit = (mint_amount.to_f * (10**18)).to_i

      tx_hash = client.transact_and_wait(wow_contract, "mint", mint_address, mint_amount_in_smallest_unit, sender_key: signer)

      if client.tx_mined?(tx_hash)
        puts "Transaction was successful!"
      else
        puts "Transaction failed!"
      end
  end

错误代码:

Eth::Client::ContractExecutionError - transaction underpriced

其他产出:

gas price: 170000000000.0

网络是多边形,客户端是炼金术。

aydmsdu9

aydmsdu91#

试着提高汽油价格。根据区块链当前的Gas Estimate,尝试2- 3倍的价格,如果您使用的是metamask,metamask中有一个部分可以使用gas发送。你可以查一下Metamask有一个关于这个的博客。请读一下

相关问题