Skip to content

Commit a087075

Browse files
Update transaction-related content (#1927)
Co-authored-by: Christian Montoya <[email protected]>
1 parent 2f1258b commit a087075

File tree

6 files changed

+170
-36
lines changed

6 files changed

+170
-36
lines changed

services/concepts/transaction-types.md

+63-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ sidebar_position: 4
55

66
# Ethereum transaction types
77

8-
You can interact with the [Ethereum JSON-RPC API](../reference/ethereum/json-rpc-methods/index.md) using different transaction types (specified by the `type` parameter).
8+
You can interact with the [Ethereum JSON-RPC API](../reference/ethereum/json-rpc-methods/index.md) using different transaction types (specified by the
9+
[`transactionType`](https://eips.ethereum.org/EIPS/eip-2718) parameter).
910

1011
The following methods use a unique format depending on the transaction type:
1112

@@ -20,14 +21,50 @@ The following methods use a unique format depending on the transaction type:
2021

2122
Transactions with type `0x0` are legacy transactions that use the transaction format existing before typed transactions were introduced in [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718). They contain the parameters `nonce`, `gasPrice`, `gasLimit`, `to`, `value`, `data`, `v`, `r`, and `s`. Legacy transactions don’t use [access lists](../reference/ethereum/json-rpc-methods/eth_createaccesslist.mdx) or incorporate [EIP-1559 fee market changes](#eip-1559-transactions).
2223

24+
```js title="Legacy transaction object example"
25+
{
26+
nonce: "0x0", // Number of transactions made by the sender before this one.
27+
gasPrice: "0x09184e72a000", // Gas price, in wei, provided by the sender.
28+
gasLimit: "0x2710", // Maximum gas provided by the sender.
29+
to: "0x0000000000000000000000000000000000000000", // Address of the recipient. Not used in contract creation transactions.
30+
value: "0x0", // Value transferred, in wei.
31+
data: "0x7f7465737432000000000000000000000000000000000000000000000000000000600057", // Used for defining contract creation and interaction.
32+
v: "0x1", // ECDSA recovery ID.
33+
r: "0xa07fd6c16e169f0e54b394235b3a8201101bb9d0eba9c8ae52dbdf556a363388", // ECDSA signature r.
34+
s: "0x36f5da9310b87fefbe9260c3c05ec6cbefc426f1ff3b3a41ea21b5533a787dfc", // ECDSA signature s.
35+
}
36+
```
37+
2338
## Access list transactions
2439

2540
Transactions with type `0x1` are transactions introduced in [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930). They contain, along with the [legacy parameters](#legacy-transactions), an `accessList` parameter, which specifies an array of addresses and storage keys that the transaction plans to access (an _access list_). Access list transactions must specify an access list, and they don’t incorporate [EIP-1559 fee market changes](#eip-1559-transactions).
2641

27-
Also, access list transactions contain the `yParity` parameter. The returned values for this parameter can either be `0x0` or `0x1`. This is the parity (0 for even, 1 for odd) of the y-value of a [`secp256k1`](https://eips.ethereum.org/EIPS/eip-2098#:~:text=A%20secp256k1%20signature%20is%20made%20up%20of%203%20parameters%2C%20r%2C%20s%20and%20yParity.) signature.
42+
Also, access list transactions contain the `yParity` parameter. The returned values for this parameter can either be `0x0` or `0x1`. This is the parity (0 for even, 1 for odd) of the y-value of a [`secp256k1`](https://eips.ethereum.org/EIPS/eip-2098) signature.
2843

2944
Use the [`eth_createAccessList`](../reference/ethereum/json-rpc-methods/eth_createaccesslist.mdx) API to simulate a transaction which returns the addresses and storage keys that may be used to send the real transaction, and the approximate gas cost.
3045

46+
```js title="Access list transaction object example"
47+
{
48+
nonce: "0x0", // Number of transactions made by the sender before this one.
49+
gasPrice: "0x09184e72a000", // Gas price, in wei, provided by the sender.
50+
gasLimit: "0x2710", // Maximum gas provided by the sender.
51+
to: "0x0000000000000000000000000000000000000000", // Address of the recipient. Not used in contract creation transactions.
52+
value: "0x0", // Value transferred, in wei.
53+
data: "0x7f7465737432000000000000000000000000000000000000000000000000000000600057", // Used for defining contract creation and interaction.
54+
v: "0x1", // ECDSA recovery ID.
55+
r: "0xa07fd6c16e169f0e54b394235b3a8201101bb9d0eba9c8ae52dbdf556a363388", // ECDSA signature r.
56+
s: "0x36f5da9310b87fefbe9260c3c05ec6cbefc426f1ff3b3a41ea21b5533a787dfc", // ECDSA signature s.
57+
chainId: "0x1", // Chain ID of the transaction.
58+
accessList: [ // List of addresses and storage keys the transaction plans to access.
59+
{
60+
"address": "0xa02457e5dfd32bda5fc7e1f1b008aa5979568150",
61+
"storageKeys": ["0x0000000000000000000000000000000000000000000000000000000000000081"]
62+
}
63+
],
64+
yParity: "0x1" // Parity of the y-value of a secp256k1 signature.
65+
}
66+
```
67+
3168
:::info
3269

3370
View the [Infura article](https://blog.infura.io/post/optimizing-ethereum-transactions-with-eth_createaccesslist) that describes how `eth_createAccessList` can help optimize gas costs, reduce out-of-gas errors, and verify clients for infrastructure access.
@@ -42,8 +79,31 @@ EIP-1559 transactions don’t specify `gasPrice`, and instead use an in-protocol
4279

4380
EIP-1559 transactions contain the [`accessList` and `yParity` parameters](transaction-types.md#access-list-transactions) and [legacy parameters](transaction-types.md#legacy-transactions) (except for `gasPrice`).
4481

45-
They also contain a `maxPriorityFeePerGas` parameter, which specifies the maximum fee the sender is willing to pay per gas above the base fee (the maximum _priority fee_ per gas), and a `maxFeePerGas` parameter, which specifies the maximum total fee (base fee + priority fee) the sender is willing to pay per gas.
82+
They also contain a `maxPriorityFeePerGas` parameter, which specifies the maximum fee the sender is willing to pay per gas above the base fee, in order to get their transaction prioritized;
83+
and a `maxFeePerGas` parameter, which specifies the maximum total fee (base fee + priority fee) the sender is willing to pay per gas.
4684

4785
An EIP-1559 transaction always pays the base fee of the block it’s included in, and it pays a priority fee as priced by `maxPriorityFeePerGas` or, if the base fee per gas + `maxPriorityFeePerGas` exceeds `maxFeePerGas`, it pays a priority fee as priced by `maxFeePerGas` minus the base fee per gas. The base fee is burned, and the priority fee is paid to the miner that included the transaction. A transaction’s priority fee per gas incentivizes miners to include the transaction over other transactions with lower priority fees per gas.
4886

87+
```js title="EIP-1559 transaction object example"
88+
{
89+
nonce: "0x0", // Number of transactions made by the sender before this one.
90+
gasLimit: "0x2710", // Maximum gas provided by the sender.
91+
maxPriorityFeePerGas: "0x0", // Maximum fee, in wei, the sender is willing to pay per gas above the base fee.
92+
maxFeePerGas: "0x6f4d3132b", // Maximum total fee (base fee + priority fee), in wei, the sender is willing to pay per gas.
93+
to: "0x0000000000000000000000000000000000000000", // Address of the recipient. Not used in contract creation transactions.
94+
value: "0x0", // Value transferred, in wei.
95+
data: "0x7f7465737432000000000000000000000000000000000000000000000000000000600057", // Used for defining contract creation and interaction.
96+
v: "0x1", // ECDSA recovery ID.
97+
r: "0xa07fd6c16e169f0e54b394235b3a8201101bb9d0eba9c8ae52dbdf556a363388", // ECDSA signature r.
98+
s: "0x36f5da9310b87fefbe9260c3c05ec6cbefc426f1ff3b3a41ea21b5533a787dfc", // ECDSA signature s.
99+
chainId: "0x1", // Chain ID of the transaction.
100+
accessList: [], // List of addresses and storage keys the transaction plans to access.
101+
yParity: "0x1" // Parity of the y-value of a secp256k1 signature.
102+
}
103+
```
104+
105+
:::info
106+
49107
Read the [Consensys EIP-1559 primer](https://consensys.net/blog/quorum/what-is-eip-1559-how-will-it-change-ethereum/) for more information on how EIP-1559 changes Ethereum.
108+
109+
:::

snaps/features/transaction-insights.md

+3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ export const onTransaction: OnTransactionHandler = async ({
9999
</TabItem>
100100
</Tabs>
101101

102+
:::note
103+
Learn more about the [parameters of a submitted transaction](/wallet/how-to/send-transactions#transaction-parameters).
104+
:::
102105

103106
The Snap tab in the transaction confirmation window displays the transaction insights:
104107

snaps/learn/tutorials/transaction-insights.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,15 @@ export const onTransaction: OnTransactionHandler = async ({ transaction }) => {
301301
</TabItem>
302302
</Tabs>
303303

304-
:::tip
305-
If you have previously developed a dapp, you're likely familiar with accessing the Ethereum provider
304+
:::note Notes
305+
306+
- Learn more about the [parameters of a submitted transaction](/wallet/how-to/send-transactions#transaction-parameters).
307+
308+
- If you have previously developed a dapp, you're likely familiar with accessing the Ethereum provider
306309
using `window.ethereum`. In a Snap, the `window` object is not available. Instead, when you request
307310
the `endowment:ethereum-provider` permission, your Snap is granted access to the
308311
[`ethereum` global object](../about-snaps/apis.md#snap-requests).
312+
309313
:::
310314

311315
### 5. Build and test your Snap

snaps/reference/entry-points.md

+1
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ For MetaMask to call the Snap's `onTransaction` method, you must request the
498498
An object containing:
499499

500500
- `transaction` - The raw transaction payload.
501+
Learn more about the [parameters of a submitted transaction](/wallet/how-to/send-transactions#transaction-parameters).
501502
- `chainId` - The [CAIP-2](https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md)
502503
chain ID.
503504
- `transactionOrigin` - The transaction origin if

src/scss/theme/_admonition-type.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
[class*='admonition'] {
66
ul {
7-
list-style-position: inside;
7+
list-style-position: outside;
88
list-style-type: disc;
9-
margin: 1rem 0;
9+
margin: 1rem 1.6rem;
1010
}
1111
p {
1212
margin-top: 0.6rem;

wallet/how-to/send-transactions.md

+95-29
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
description: Send transactions using eth_sendTransaction.
33
---
44

5+
import Tabs from "@theme/Tabs";
6+
import TabItem from "@theme/TabItem";
7+
58
# Send transactions
69

710
You can send a transaction in MetaMask using the
@@ -17,26 +20,18 @@ const sendEthButton = document.querySelector(".sendEthButton");
1720

1821
let accounts = [];
1922

20-
// Send Ethereum to an address.
2123
sendEthButton.addEventListener("click", () => {
2224
provider // Or window.ethereum if you don't support EIP-6963.
2325
.request({
2426
method: "eth_sendTransaction",
25-
// The following sends an EIP-1559 transaction. Legacy transactions are also supported.
2627
params: [
2728
{
28-
// The user's active address.
29-
from: accounts[0],
30-
// Required except during contract publications.
31-
to: <recipient address>,
32-
// Only required to send ether to the recipient from the initiating external account.
33-
value: <value in wei to send>,
34-
// Customizable by the user during MetaMask confirmation.
35-
gasLimit: '0x5028',
36-
// Customizable by the user during MetaMask confirmation.
37-
maxPriorityFeePerGas: '0x3b9aca00',
38-
// Customizable by the user during MetaMask confirmation.
39-
maxFeePerGas: '0x2540be400',
29+
from: accounts[0], // The user's active address.
30+
to: "0x0000000000000000000000000000000000000000", // Address of the recipient. Not used in contract creation transactions.
31+
value: "0x0", // Value transferred, in wei. Only required to send ether to the recipient from the initiating external account.
32+
gasLimit: "0x5028", // Customizable by the user during MetaMask confirmation.
33+
maxPriorityFeePerGas: "0x3b9aca00", // Customizable by the user during MetaMask confirmation.
34+
maxFeePerGas: "0x2540be400", // Customizable by the user during MetaMask confirmation.
4035
},
4136
],
4237
})
@@ -63,6 +58,75 @@ The following HTML displays the buttons:
6358

6459
## Transaction parameters
6560

61+
The transaction parameters depend on the [transaction type](/services/concepts/transaction-types).
62+
The following are examples of transaction objects for each type:
63+
64+
<Tabs>
65+
<TabItem value="Legacy transaction">
66+
67+
```js
68+
{
69+
nonce: "0x0", // Number of transactions made by the sender before this one.
70+
gasPrice: "0x09184e72a000", // Gas price, in wei, provided by the sender.
71+
gasLimit: "0x2710", // Maximum gas provided by the sender.
72+
to: "0x0000000000000000000000000000000000000000", // Address of the recipient. Not used in contract creation transactions.
73+
value: "0x0", // Value transferred, in wei.
74+
data: "0x7f7465737432000000000000000000000000000000000000000000000000000000600057", // Used for defining contract creation and interaction.
75+
v: "0x1", // ECDSA recovery ID.
76+
r: "0xa07fd6c16e169f0e54b394235b3a8201101bb9d0eba9c8ae52dbdf556a363388", // ECDSA signature r.
77+
s: "0x36f5da9310b87fefbe9260c3c05ec6cbefc426f1ff3b3a41ea21b5533a787dfc", // ECDSA signature s.
78+
}
79+
```
80+
81+
</TabItem>
82+
<TabItem value="Access list transaction">
83+
84+
```js
85+
{
86+
nonce: "0x0", // Number of transactions made by the sender before this one.
87+
gasPrice: "0x09184e72a000", // Gas price, in wei, provided by the sender.
88+
gasLimit: "0x2710", // Maximum gas provided by the sender.
89+
to: "0x0000000000000000000000000000000000000000", // Address of the recipient. Not used in contract creation transactions.
90+
value: "0x0", // Value transferred, in wei.
91+
data: "0x7f7465737432000000000000000000000000000000000000000000000000000000600057", // Used for defining contract creation and interaction.
92+
v: "0x1", // ECDSA recovery ID.
93+
r: "0xa07fd6c16e169f0e54b394235b3a8201101bb9d0eba9c8ae52dbdf556a363388", // ECDSA signature r.
94+
s: "0x36f5da9310b87fefbe9260c3c05ec6cbefc426f1ff3b3a41ea21b5533a787dfc", // ECDSA signature s.
95+
chainId: "0x1", // Chain ID of the transaction.
96+
accessList: [ // List of addresses and storage keys the transaction plans to access.
97+
{
98+
"address": "0xa02457e5dfd32bda5fc7e1f1b008aa5979568150",
99+
"storageKeys": ["0x0000000000000000000000000000000000000000000000000000000000000081"]
100+
}
101+
],
102+
yParity: "0x1" // Parity of the y-value of a secp256k1 signature.
103+
}
104+
```
105+
106+
</TabItem>
107+
<TabItem value="EIP-1559 transaction">
108+
109+
```js
110+
{
111+
nonce: "0x0", // Number of transactions made by the sender before this one.
112+
gasLimit: "0x2710", // Maximum gas provided by the sender.
113+
maxPriorityFeePerGas: "0x0", // Maximum fee, in wei, the sender is willing to pay per gas above the base fee.
114+
maxFeePerGas: "0x6f4d3132b", // Maximum total fee (base fee + priority fee), in wei, the sender is willing to pay per gas.
115+
to: "0x0000000000000000000000000000000000000000", // Address of the recipient. Not used in contract creation transactions.
116+
value: "0x0", // Value transferred, in wei.
117+
data: "0x7f7465737432000000000000000000000000000000000000000000000000000000600057", // Used for defining contract creation and interaction.
118+
v: "0x1", // ECDSA recovery ID.
119+
r: "0xa07fd6c16e169f0e54b394235b3a8201101bb9d0eba9c8ae52dbdf556a363388", // ECDSA signature r.
120+
s: "0x36f5da9310b87fefbe9260c3c05ec6cbefc426f1ff3b3a41ea21b5533a787dfc", // ECDSA signature s.
121+
chainId: "0x1", // Chain ID of the transaction.
122+
accessList: [], // List of addresses and storage keys the transaction plans to access.
123+
yParity: "0x1" // Parity of the y-value of a secp256k1 signature.
124+
}
125+
```
126+
127+
</TabItem>
128+
</Tabs>
129+
66130
### Nonce
67131

68132
:::note
@@ -82,29 +146,31 @@ Nonces are easy to mess up, especially when a user is interacting with multiple
82146
pending transactions using the same account, potentially across multiple devices.
83147
Because of this, MetaMask doesn't allow dapp developers to customize nonces.
84148
Instead, MetaMask
85-
[assists the user in managing their transaction queue themselves](https://metamask.zendesk.com/hc/en-us/articles/360015489251).
149+
[assists the user in managing their transaction queue themselves](https://support.metamask.io/manage-crypto/transactions/how-to-speed-up-or-cancel-a-pending-transaction/).
86150

87151
### Gas price
88152

89-
Gas price is an optional parameter, and best used on private blockchains.
153+
`gasPrice` is an optional parameter.
154+
It is used in [legacy transactions](/services/concepts/transaction-types/#legacy-transactions) and specifies the gas price the sender is willing to pay for the transaction.
155+
MetaMask automatically configures gas settings, but [users can also customize these settings](https://support.metamask.io/configure/transactions/how-to-customize-gas-settings/).
90156

91-
In Ethereum, every transaction specifies a price for the gas it consumes.
92-
To maximize their profit, block producers pick pending transactions with higher gas prices first
93-
when creating the next block.
94-
This means that a high gas price usually causes your transaction to be processed faster, at the cost
95-
of greater transaction fees.
157+
### Gas limit
96158

97-
Some networks, such as Layer 2 networks, might have a constant gas price or no gas price.
98-
So while you can ignore this parameter on MetaMask's default networks, you might include it when
99-
your dapp knows more about the target network than MetaMask does.
100-
On the default networks, MetaMask allows users to choose between slow, medium, and fast options for
101-
their gas price.
159+
`gasLimit` is an optional parameter.
160+
It specifies the maximum amount of gas units the sender is willing to pay for the transaction.
161+
MetaMask automatically sets this parameter, but [users can also customize their gas settings](https://support.metamask.io/configure/transactions/how-to-customize-gas-settings/).
102162

103-
Read about [how to use advanced gas controls](https://metamask.zendesk.com/hc/en-us/articles/360022895972).
163+
### Max priority fee per gas
104164

105-
### Gas limit
165+
`maxPriorityFeePerGas` is an optional parameter.
166+
It is used in [EIP-1559 transactions](/services/concepts/transaction-types/#eip-1559-transactions) and specifies the maximum fee the sender is willing to pay per gas above the base fee, in order to get their transaction prioritized.
167+
MetaMask automatically sets this parameter, but [users can also customize their gas settings](https://support.metamask.io/configure/transactions/how-to-customize-gas-settings/).
168+
169+
### Max fee per gas
106170

107-
Gas limit is an optional parameter, since MetaMask automatically calculates a reasonable gas price.
171+
`maxFeePerGas` is an optional parameter.
172+
It is used in [EIP-1559 transactions](/services/concepts/transaction-types/#eip-1559-transactions) and specifies the maximum total fee (base fee + priority fee) the sender is willing to pay per gas.
173+
MetaMask automatically sets this parameter, but [users can also customize their gas settings](https://support.metamask.io/configure/transactions/how-to-customize-gas-settings/).
108174

109175
### To
110176

0 commit comments

Comments
 (0)