ethers
library. By following this example, you’ll be able to create, sign, and send a transaction on the Ethereum Sepolia network.
Prerequisites
- Node.js installed on your system
- An Ethereum wallet with some Sepolia testnet ETH
- You can request testnet ETH at Alchemy Faucet
- Stardust API key and wallet ID
dotenv
,axios
, andethers
libraries
Setup
-
Install Dependencies
First, you need to install the required dependencies:
-
Create a
.env
File Create a.env
file in your project root directory and add your Stardust API key and wallet ID:
Code Example
1. Import Libraries and Configure Environment
First, import the necessary libraries and configure your environment using the.env
file:
dotenv
, axios
, and ethers
libraries and sets up the environment variables.
2. Setup Configuration
Next, set up the API key and wallet ID from the environment variables:3. Create Transaction
Create and encode the transaction using theethers
library. This example uses an EIP-1559 transaction. More information about EIP-1559 can be found here or here.
If you are interacting with a contract, you will need to encode the data to interact with the contract according to the data field
4. Serialize/Encode the Transaction
Serialize the transaction using theethers
library.
source
5. Sign the Transaction
Send the unsigned serialized transaction to the Stardust API to get it signed for your given wallet:6. Serialize the Signed Transaction for Sending
This step appends the signature to the transaction for verification on the network:7. Send the Signed Transaction
Send the signed transaction to the Ethereum Sepolia network usingeth_sendRawTransaction
.
source
8. Output
Successful output should look like the following:Conclusion
You have successfully created, signed, and sent a transaction using the Stardust API and theethers
library. You can now use this example to integrate transaction sending into your application. For more information, refer to the Stardust API documentation.