Method: Coinbase::ContractInvocation.create

Defined in:
lib/coinbase/contract_invocation.rb

.create(address_id:, wallet_id:, contract_address:, method:, network:, args: {}, amount: nil, abi: nil, asset_id: nil) ⇒ ContractInvocation

Creates a new ContractInvocation object.

Parameters:

  • address_id (String)

    The Address ID of the signing Address

  • wallet_id (String)

    The Wallet ID associated with the signing Address

  • contract_address (String)

    The contract address

  • abi (Array<Hash>) (defaults to: nil)

    The contract ABI

  • method (String)

    The contract method

  • amount (Integer, Float, BigDecimal) (defaults to: nil)

    The amount of the native Asset to send to a payable contract method.

  • asset_id (Symbol) (defaults to: nil)

    The ID of the Asset to send to a payable contract method. The Asset must be a denomination of the native Asset. For Ethereum, :eth, :gwei, and :wei are supported.

  • network (Coinbase::Network, Symbol)

    The Network or Network ID of the Asset

  • args (Hash) (defaults to: {})

    The arguments to pass to the contract method. The keys should be the argument names, and the values should be the argument values.

Returns:

Raises:

  • (Coinbase::ApiError)

    If the request to create the Contract Invocation fails



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/coinbase/contract_invocation.rb', line 24

def create(
  address_id:,
  wallet_id:,
  contract_address:,
  method:,
  network:,
  args: {},
  amount: nil,
  abi: nil,
  asset_id: nil
)
  req = {
    method: method,
    args: args.to_json,
    contract_address: contract_address
  }

  req[:abi] = abi.to_json unless abi.nil?

  # For payable contract invocations, convert the amount to atomic units of specified asset.
  if amount && asset_id && network
    asset = Coinbase::Asset.fetch(network, asset_id)

    req[:amount] = asset.to_atomic_amount(amount).to_i.to_s
  end

  model = Coinbase.call_api do
    contract_invocation_api.create_contract_invocation(wallet_id, address_id, **req)
  end

  new(model)
end