View Source Signet.Transaction.V1 (Signet v0.1.7)

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

Link to this section 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.

Link to this section 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

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

Examples

iex> "E80185174876E800830186A094000000000000000000000000000000000000000102830102032A8080"
...> |> Base.decode16!()
...> |> 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

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

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.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

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

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)
...> Base.encode16(address)
"47643AC1194D7E8C6D04DD631D456137028BBC1F"

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"}