View Source Signet.Transaction.V2 (Signet v1.0.0-beta7)
Represents a V2 or EIP-1559 transaction.
Summary
Functions
Adds a signature to a transaction. This overwrites the signature_y_parity
, signature_r
and signature_s
fields.
Decode an RLP-encoded transaction. Note: the signature must have been signed (i.e. properly encoded), not simply encoded for signing.
Build an RLP-encoded transaction. Note: if the transaction does not have a signature
set (that is, signature_y_parity
, signature_r
or signature_s
are nil
), then
we will encode a partial transaction (which can be used for signing).
Recovers a signature from a transaction, if it's been signed. Otherwise returns an error.
Constructs a new V2 (EIP-1559) Ethereum transaction.
Recovers the signer from a given transaction, if it's been signed.
Types
@type t() :: %Signet.Transaction.V2{ access_list: [<<_::160>>], amount: integer(), chain_id: integer(), data: binary(), destination: <<_::160>>, gas_limit: integer(), max_fee_per_gas: integer(), max_priority_fee_per_gas: integer(), nonce: integer(), signature_r: <<_::256>>, signature_s: <<_::256>>, signature_y_parity: boolean() }
Functions
Adds a signature to a transaction. This overwrites the signature_y_parity
, signature_r
and signature_s
fields.
Examples
iex> Signet.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], 1, 0x01, 0x02, :goerli)
...> |> Signet.Transaction.V2.add_signature(true, <<1::256>>, <<2::256>>)
%Signet.Transaction.V2{
chain_id: 5,
nonce: 1,
max_priority_fee_per_gas: 1000000000,
max_fee_per_gas: 100000000000,
gas_limit: 100000,
destination: <<1::160>>,
amount: 2,
data: <<1, 2, 3>>,
access_list: [<<2::160>>, <<3::160>>],
signature_y_parity: true,
signature_r: <<0x01::256>>,
signature_s: <<0x02::256>>
}
iex> Signet.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], 1, 0x01, 0x02, :goerli)
...> |> Signet.Transaction.V2.add_signature(<<1::256, 2::256, 1::8>>)
%Signet.Transaction.V2{
chain_id: 5,
nonce: 1,
max_priority_fee_per_gas: 1000000000,
max_fee_per_gas: 100000000000,
gas_limit: 100000,
destination: <<1::160>>,
amount: 2,
data: <<1, 2, 3>>,
access_list: [<<2::160>>, <<3::160>>],
signature_y_parity: true,
signature_r: <<0x01::256>>,
signature_s: <<0x02::256>>
}
iex> Signet.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], 1, 0x01, 0x02, :goerli)
...> |> Signet.Transaction.V2.add_signature(<<1::256, 2::256, 27::8>>)
%Signet.Transaction.V2{
chain_id: 5,
nonce: 1,
max_priority_fee_per_gas: 1000000000,
max_fee_per_gas: 100000000000,
gas_limit: 100000,
destination: <<1::160>>,
amount: 2,
data: <<1, 2, 3>>,
access_list: [<<2::160>>, <<3::160>>],
signature_y_parity: false,
signature_r: <<0x01::256>>,
signature_s: <<0x02::256>>
}
iex> Signet.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], 1, 0x01, 0x02, :goerli)
...> |> Signet.Transaction.V2.add_signature(<<1::256, 2::256, 38::8>>)
%Signet.Transaction.V2{
chain_id: 5,
nonce: 1,
max_priority_fee_per_gas: 1000000000,
max_fee_per_gas: 100000000000,
gas_limit: 100000,
destination: <<1::160>>,
amount: 2,
data: <<1, 2, 3>>,
access_list: [<<2::160>>, <<3::160>>],
signature_y_parity: true,
signature_r: <<0x01::256>>,
signature_s: <<0x02::256>>
}
iex> Signet.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], 1, 0x01, 0x02, :goerli)
...> |> Signet.Transaction.V2.add_signature(<<1::256, 2::256, 3838::16>>)
%Signet.Transaction.V2{
chain_id: 5,
nonce: 1,
max_priority_fee_per_gas: 1000000000,
max_fee_per_gas: 100000000000,
gas_limit: 100000,
destination: <<1::160>>,
amount: 2,
data: <<1, 2, 3>>,
access_list: [<<2::160>>, <<3::160>>],
signature_y_parity: true,
signature_r: <<0x01::256>>,
signature_s: <<0x02::256>>
}
Decode an RLP-encoded transaction. Note: the signature must have been signed (i.e. properly encoded), not simply encoded for signing.
Examples
iex> Signet.Transaction.V2.decode(Base.decode16!("02F8990501843B9ACA0085174876E800830186A09400000000000000000000000000000000000000010283010203EA94000000000000000000000000000000000000000294000000000000000000000000000000000000000301A00000000000000000000000000000000000000000000000000000000000000001A00000000000000000000000000000000000000000000000000000000000000002"))
{:ok, %Signet.Transaction.V2{
chain_id: 5,
nonce: 1,
max_priority_fee_per_gas: 1000000000,
max_fee_per_gas: 100000000000,
gas_limit: 100000,
destination: <<1::160>>,
amount: 2,
data: <<1, 2, 3>>,
access_list: [<<2::160>>, <<3::160>>],
signature_y_parity: true,
signature_r: 0x01,
signature_s: 0x02
}}
Build an RLP-encoded transaction. Note: if the transaction does not have a signature
set (that is, signature_y_parity
, signature_r
or signature_s
are nil
), then
we will encode a partial transaction (which can be used for signing).
Examples
iex> Signet.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], :goerli)
...> |> Signet.Transaction.V2.encode()
...> |> Base.encode16()
"02F8560501843B9ACA0085174876E800830186A09400000000000000000000000000000000000000010283010203EA940000000000000000000000000000000000000002940000000000000000000000000000000000000003"
iex> Signet.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], true, <<0x01::256>>, <<0x02::256>>, :goerli)
...> |> Signet.Transaction.V2.encode()
...> |> Base.encode16()
"02F8990501843B9ACA0085174876E800830186A09400000000000000000000000000000000000000010283010203EA94000000000000000000000000000000000000000294000000000000000000000000000000000000000301A00000000000000000000000000000000000000000000000000000000000000001A00000000000000000000000000000000000000000000000000000000000000002"
Recovers a signature from a transaction, if it's been signed. Otherwise returns an error.
Examples
iex> Signet.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], true, <<0x01::256>>, <<0x02::256>>, :goerli)
...> |> Signet.Transaction.V2.get_signature()
{:ok, <<1::256, 2::256, 1::8>>}
iex> Signet.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], :goerli)
...> |> Signet.Transaction.V2.get_signature()
{:error, "transaction missing signature"}
new(nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, destination, amount, data, access_list, chain_id \\ nil)
View SourceConstructs a new V2 (EIP-1559) Ethereum transaction.
Examples
iex> Signet.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], :goerli)
%Signet.Transaction.V2{
chain_id: 5,
nonce: 1,
max_priority_fee_per_gas: 1000000000,
max_fee_per_gas: 100000000000,
gas_limit: 100000,
destination: <<1::160>>,
amount: 2,
data: <<1, 2, 3>>,
access_list: [<<2::160>>, <<3::160>>],
signature_y_parity: nil,
signature_r: nil,
signature_s: nil
}
iex> Signet.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], true, <<0x01::256>>, <<0x02::256>>, :goerli)
%Signet.Transaction.V2{
chain_id: 5,
nonce: 1,
max_priority_fee_per_gas: 1000000000,
max_fee_per_gas: 100000000000,
gas_limit: 100000,
destination: <<1::160>>,
amount: 2,
data: <<1, 2, 3>>,
access_list: [<<2::160>>, <<3::160>>],
signature_y_parity: true,
signature_r: <<0x01::256>>,
signature_s: <<0x02::256>>
}
new(nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, destination, amount, data, access_list, signature_y_parity, signature_r, signature_s, chain_id \\ nil)
View SourceRecovers the signer from a given transaction, if it's been signed.
Examples
iex> {:ok, address} =
...> Signet.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], true, <<0x01::256>>, <<0x02::256>>, :goerli)
...> |> Signet.Transaction.V2.recover_signer()
...> Base.encode16(address)
"C002CA628F93E1550B5F30ED10902A9E7783364B"
iex> Signet.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], :goerli)
...> |> Signet.Transaction.V2.recover_signer()
{:error, "transaction missing signature"}