View Source Signet.Transaction.V1 (Signet v1.3.8)

Represents a V1 or "Legacy" (that is, pre-EIP-1559) transaction.

Summary

Functions

Adds a signature to a transaction. This overwrites the [chain_id, 0, 0] fields, as per EIP-155.

Decode an RLP-encoded transaction.

Build an RLP-encoded transaction. Note: transactions can be encoded before they are signed, which uses [chain_id, 0, 0] in the signature fields, otherwise those fields are [v, r, s].

Recovers a signature from a transaction, if it's been signed. Otherwise returns an error.

Constructs a new V1 (Legacy) Ethereum transaction.

Recovers the signer from a given transaction, if it's been signed.

Types

@type t() :: %Signet.Transaction.V1{
  data: binary(),
  gas_limit: integer(),
  gas_price: integer(),
  nonce: integer(),
  r: integer(),
  s: integer(),
  to: <<_::160>>,
  v: integer(),
  value: integer()
}

Functions

Link to this function

add_signature(transaction, arg)

View Source

Adds a signature to a transaction. This overwrites the [chain_id, 0, 0] fields, as per EIP-155.

Examples

iex> Signet.Transaction.V1.new(1, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, :kovan)
...> |> Signet.Transaction.V1.add_signature(<<1::256, 2::256, 3::8>>)
%Signet.Transaction.V1{
  nonce: 1,
  gas_price: 100000000000,
  gas_limit: 100000,
  to: <<1::160>>,
  value: 2,
  data: <<1, 2, 3>>,
  v: 3,
  r: <<1::256>>,
  s: <<2::256>>
}

Decode an RLP-encoded transaction.

Examples

iex> use Signet.Hex
iex> ~h[0xE80185174876E800830186A094000000000000000000000000000000000000000102830102032A8080]
...> |> Signet.Transaction.V1.decode()
{:ok, %Signet.Transaction.V1{
  nonce: 1,
  gas_price: 100000000000,
  gas_limit: 100000,
  to: <<1::160>>,
  value: 2,
  data: <<1, 2, 3>>,
  v: 42,
  r: 0,
  s: 0
}}

Build an RLP-encoded transaction. Note: transactions can be encoded before they are signed, which uses [chain_id, 0, 0] in the signature fields, otherwise those fields are [v, r, s].

Examples

iex> Signet.Transaction.V1.new(1, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, :kovan)
...> |> Signet.Transaction.V1.encode()
...> |> Base.encode16()
"E80185174876E800830186A094000000000000000000000000000000000000000102830102032A8080"

Recovers a signature from a transaction, if it's been signed. Otherwise returns an error.

Examples

iex> Signet.Transaction.V1.new(1, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, :kovan)
...> |> Signet.Transaction.V1.add_signature(<<1::256, 2::256, 3::8>>)
...> |> Signet.Transaction.V1.get_signature()
{:ok, <<1::256, 2::256, 3::8>>}

iex> Signet.Transaction.V1.new(1, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, :kovan)
...> |> Signet.Transaction.V1.add_signature(<<1::256, 2::256, 0x05f5e0ff::32>>)
...> |> Signet.Transaction.V1.get_signature()
{:ok, <<1::256, 2::256, 0x05f5e0ff::32>>}

iex> Signet.Transaction.V1.new(1, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, :kovan)
...> |> Signet.Transaction.V1.get_signature()
{:error, "transaction missing signature"}
Link to this function

new(nonce, gas_price, gas_limit, to, value, data, chain_id \\ nil)

View Source

Constructs a new V1 (Legacy) Ethereum transaction.

Examples

iex> Signet.Transaction.V1.new(1, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, :kovan)
%Signet.Transaction.V1{
  nonce: 1,
  gas_price: 100000000000,
  gas_limit: 100000,
  to: <<1::160>>,
  value: 2,
  data: <<1, 2, 3>>,
  v: 42,
  r: 0,
  s: 0
}
Link to this function

recover_signer(transaction, chain_id)

View Source

Recovers the signer from a given transaction, if it's been signed.

Examples

iex> {:ok, address} =
...> Signet.Transaction.V1.new(1, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, :kovan)
...> |> Signet.Transaction.V1.add_signature(<<1::256, 2::256, 3::8>>)
...> |> Signet.Transaction.V1.recover_signer(:kovan)
...> Signet.Hex.to_address(address)
"0x47643AC1194d7e8C6d04dD631D456137028bBc1F"

iex> Signet.Transaction.V1.new(1, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, :kovan)
...> |> Signet.Transaction.V1.recover_signer(:kovan)
{:error, "transaction missing signature"}