ethers.js and web3.js both let you set it. This guide uses ethers.js.
Prerequisites
- You understand transactions, gas, and gas pricing on EVM networks.
- You have Node.js and
ethers.jsinstalled. - You have a funded account and the peaq RPC endpoint.
- You keep secrets in environment variables, for example in a
.envfile.
Instructions
1. Set up the environment
- Install dependencies:
- Set ESM module:
Add the following to your
package.jsonto allow for ESM modules.
- Configure environment variables:
Create a
.envfile with the following content:
.env file in .gitignore so it is never checked into version control.
2. Set up the provider and wallet
Create asendTransaction.js file, load the environment variables, initialize the provider with the peaq RPC endpoint, and load the wallet from the private key.
3. Decide on a gas limit
Choose a suitable gas limit. Start with a safe upper bound, and adjust later as needed.4. Craft the transaction
Include thegasLimit in the transaction object.
5. Send the transaction
Send the transaction and wait for it to be mined. If it runs out of gas, thetry/catch block catches the error.
6. Adjust gas limits over time
- If your transactions run out of gas, raise the limit.
- If you consistently use much less gas than the limit, lower it.
- For scripts that send transactions regularly, a predefined gas limit protects you against sudden gas spikes.
- To set the limit from the transaction itself instead of a fixed number, see Estimating Gas Fees.

