我正在使用 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
网络是Polygon,客户端是Alchemy。
尝试提高汽油价格。根据当前区块链的 Gas Estimator 尝试 2-3 倍的价格,如果您使用的是 Metamask,Metamask 中有部分可以使用 Gas 发送。你可以检查一下。 Metamask 有一篇关于此的博客。请阅读该内容。