blockchain - ruby - eth.rb gem的使用(调用contract setter, getter) 亲测可用,直接用这个

访问量: 715

refer to: https://github.com/q9f/eth.rb

Gemfile:

#source "https://rubygems.org"
source "https://gems.ruby-china.com"

gem "forwardable"
gem "eth"
方法:

require "forwardable"
require "eth"

# 先提供key key = Eth::Key.new priv: "0xf1ccc8c50f9a1fcec081b0723410716f59a06cf2d06b1000ab7b8a0a????????"
# 创建client client = Eth::Client.create "https://api.avax-test.network/ext/bc/C/rpc"
# 提供 abi abi = '[{"inputs":[{"internalType":"string","name":"_greeting","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"greet","outputs":[{"internalType"
# contract address address = '0x4a67680683b27F55006Cfab73Ac9F7CECf8A99B6' # 给contract起个名字 name = 'Greeter' # 创建contract instance contract = Eth::Contract.from_abi(name: name, address: address, abi: abi) # 设置 gas price = 25g wei client.max_fee_per_gas = (27 * 1e9).to_i
# 这里的legacy: true 就是为了让 gas price 生效, 只能这样,否则就需要修改gem源代码 setter_result = client.transact_and_wait(contract, "setGreeting", "131", sender_key: key, legacy: true, gas_limit: 100000,)
# 先调用 setter puts "----- call setter result: #{setter_result.inspect}" sleep 8 # 再调用 getter puts "----- call getter result: #{client.call(contract, "greet")}"

亲测可用

订阅/RSS Feed

Subscribe