ethers.js.
Prerequisites
- Node.js installed, and
npm install ethers dotenvin your project. - A funded account and its private key in an environment variable. Never put a private key or mnemonic in your source code.
- The RPC URL of the network you are using. See Connecting to peaq.
- The transaction details: recipient address, value, and call data if you are calling a contract.
Instructions
1. Import ethers.js
In your JavaScript file, import ethers.js:2. Set up a provider
Connect to the network:3. Configure a signer
Create a wallet instance to sign transactions:4. Define the transaction
Set up the transaction details:maxFeePerGas and maxPriorityFeePerGas out of the object and ethers reads the current fees from the node when it sends the transaction. To call a smart contract, add data.
5. Sign and submit the transaction
6. Verify the transaction
Look uptxResponse.hash on Subscan, or check the status in your code with provider.getTransactionReceipt.
Contracts
For a contract call, build the contract instance from its ABI and address and connect it to the wallet:contract.methodName.estimateGas(...args).
Putting it all Together
A complete script that ties the steps together, including environment variable handling.Running the script
- Add
"type": "module"to yourpackage.jsonso Node treats the file as an ES module. - Create a
.envfile in the root of your project:
- Replace
0xRecipientAddressHerewith the recipient’s address and adjustvalue. - Run it:

