class Eth::Client
def transact(contract, function, *args, **kwargs)
-
(Object)
- returns the result of the transaction.
Parameters:
-
**tx_value
(Integer
) -- optional transaction value field filling. -
**nonce
(Integer
) -- optional specific nonce for transaction. -
**gas_limit
(Integer
) -- optional gas limit override for deploying the contract. -
**address
(Eth::Address
) -- contract address. -
**legacy
(Boolean
) -- enables legacy transactions (pre-EIP-1559). -
**sender_key
(Eth::Key
) -- the sender private key. -
*args
() -- optional function arguments.
-
function_name
(String
) -- method name to be executed. -
contract
(Eth::Contract
) -- the subject contract to write to. -
*args
() -- optional function arguments.
-
function
(String
) -- method name to be executed. -
contract
(Eth::Contract
) -- the subject contract to write to. -
function
(String
) -- method name to be executed. -
contract
(Eth::Contract
) -- the subject contract to write to.
Overloads:
-
transact(contract, function, *args, **kwargs)
-
transact(contract, function, *args)
-
transact(contract, function)
def transact(contract, function, *args, **kwargs) gas_limit = if kwargs[:gas_limit] kwargs[:gas_limit] else Tx.estimate_intrinsic_gas(contract.bin) + Tx::CREATE_GAS end fun = contract.functions.select { |func| func.name == function }[0] params = { value: kwargs[:tx_value] || 0, gas_limit: gas_limit, chain_id: chain_id, to: kwargs[:address] || contract.address, data: call_payload(fun, args), } if kwargs[:legacy] params.merge!({ gas_price: max_fee_per_gas, }) else params.merge!({ priority_fee: max_priority_fee_per_gas, max_gas_fee: max_fee_per_gas, }) end unless kwargs[:sender_key].nil? # use the provided key as sender and signer params.merge!({ from: kwargs[:sender_key].address, nonce: kwargs[:nonce] || get_nonce(kwargs[:sender_key].address), }) tx = Eth::Tx.new(params) tx.sign kwargs[:sender_key] return eth_send_raw_transaction(tx.hex)["result"] else # do not allow accessing accounts on remote connections raise ArgumentError, "The default account is not available on remote connections, please provide a :sender_key!" unless local? # use the default account as sender and external signer params.merge!({ from: default_account, nonce: kwargs[:nonce] || get_nonce(default_account), }) return eth_send_transaction(params)["result"] end end