Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit d4abafb

Browse files
committed
Add Links to Gas Estimation Docs
1 parent 4378e31 commit d4abafb

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

docs/docs/guides/04_transactions/gas-and-fees.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ const transaction: Transaction = {
8585
};
8686
```
8787

88-
The following example demonstrates creating an access list for a transaction that invokes a smart contract function:
88+
## Smart Contract Fees
89+
90+
The following example demonstrates specifying fee data and creating an access list for a transaction that invokes a [smart contract](/guides/smart_contracts/smart_contracts_guide) function:
8991

9092
```ts
9193
const transfer: NonPayableMethodObject = erc20.methods.transfer(receiver.address, 1);
@@ -94,9 +96,15 @@ const transferOpts: NonPayableCallOptions = { from: sender.address };
9496
const accessListResult: AccessListResult = await transfer.createAccessList(transferOpts);
9597
const transactionDraft: Transaction = transfer.populateTransaction(transferOpts);
9698

99+
const feeData: FeeData = await web3.eth.calculateFeeData();
100+
97101
const transferTxn: Transaction = {
98102
...transactionDraft,
103+
maxFeePerGas: feeData.maxFeePerGas,
104+
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
99105
accessList: accessListResult.accessList,
100106
gas: accessListResult.gasUsed,
101107
};
108+
109+
const receipt: TransactionReceipt = await web3.eth.sendTransaction(transferTxn);
102110
```

docs/docs/guides/04_transactions/transactions.md

+4
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ Final receiver balance: 100n
231231

232232
Note that the sender's balance has decreased by more than the amount that was transferred to the receiver. This is because the sender's balance is also used to pay for the transaction's [gas fees](https://ethereum.org/en/developers/docs/gas/). The transaction receipt specifies the amount of gas that was used (`cumulativeGasUsed`) and the gas price in wei (`effectiveGasPrice`). The total amount deducted from the sender's balance is equal to the amount transferred plus the cost of the gas fees (`cumulativeGasUsed` multiplied by `effectiveGasPrice`).
233233

234+
:::info
235+
Gas and other fees are important topics for Ethereum developers to understand. Refer to the [Gas and Priority Fees guide](/guides/transactions/gas-and-fees) to learn more.
236+
:::
237+
234238
## Step 5: Send a Transaction and Subscribe to Its Events
235239

236240
In the previous example, the `transaction-receipt.js` script demonstrates sending a transaction to the network and reviewing the results after it has been successfully received. However, there are more stages to the [transaction lifecycle](https://ethereum.org/en/developers/docs/transactions/#transaction-lifecycle) and Web3.js makes it easy to subscribe to these lifecycle stages and create custom handlers for each one. Web3.js supports subscriptions for the following transaction lifecycle events:

docs/docs/guides/05_smart_contracts/mastering_smart_contracts.md

+4
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ contract.methods.METHOD_NAME(METHOD_PARAMETERS).send({ from: '0x...' });
200200
contract.methods.METHOD_NAME(METHOD_PARAMETERS).call();
201201
```
202202

203+
:::tip
204+
Refer to the [Gas and Priority Fees guide](/guides/transactions/gas-and-fees#smart-contract-fees) to learn how to control and optimize fees when using Web3.js to interact with smart contracts.
205+
:::
206+
203207
- **events**: An object mapping your contract's events, allowing you to subscribe to them.
204208

205209
And here is an example on how to use it:

docs/docs/guides/05_smart_contracts/smart_contracts_guide.md

+4
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ interact();
362362

363363
This code uses the previously generated ABI and contract address to instantiate a [`Contract`](/api/web3-eth-contract/class/Contract) object for interacting with the `MyContract` smart contract. It gets the current value of `myNumber` from `MyContract`, logs it, updates it, and gets its updated value. It logs the updated `myNumber` value and the [transaction hash](https://help.coinbase.com/en-au/coinbase/getting-started/crypto-education/what-is-a-transaction-hash-hash-id) to the console.
364364

365+
:::info
366+
For the purposes of this tutorial, the above script uses relatively arbitrary values for `gas` and `gasPrice` when demonstrating how to interact with a smart contract. Refer to the [Gas and Priority Fees guide](/guides/transactions/gas-and-fees#smart-contract-fees) to learn how to properly set these values.
367+
:::
368+
365369
Run the following command to interact with the smart contract:
366370

367371
```bash

0 commit comments

Comments
 (0)