class Eth::Client

def deploy(contract, *args, **kwargs)

Raises:
  • (ArgumentError) - in case the contract does not have any source.

Returns:
  • (String) - the transaction hash.

Parameters:
  • **nonce (Integer) -- optional specific nonce for transaction.
  • **gas_limit (Integer) -- optional gas limit override for deploying the contract.
  • **legacy (Boolean) -- enables legacy transactions (pre-EIP-1559).
  • **sender_key (Eth::Key) -- the sender private key.
  • *args (optional) -- variable constructor parameter list.
  • contract (Eth::Contract) -- the contracts to deploy.
  • *args (optional) -- variable constructor parameter list.
  • contract (Eth::Contract) -- the contracts to deploy.
  • contract (Eth::Contract) -- contracts to deploy.

Overloads:
  • deploy(contract, *args, **kwargs)
  • deploy(contract, *args)
  • deploy(contract)
def deploy(contract, *args, **kwargs)
  raise ArgumentError, "Cannot deploy contract without source or binary!" if contract.bin.nil?
  raise ArgumentError, "Missing contract constructor params!" if contract.constructor_inputs.length != args.length
  data = contract.bin
  unless args.empty?
    data += encode_constructor_params(contract, args)
  end
  gas_limit = if kwargs[:gas_limit]
      kwargs[:gas_limit]
    else
      Tx.estimate_intrinsic_gas(data) + Tx::CREATE_GAS
    end
  params = {
    value: 0,
    gas_limit: gas_limit,
    chain_id: chain_id,
    data: data,
  }
  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?
    # Uses 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
    # Uses 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