Stardust API Usage
This guide will walk you through the process of sending a transaction using the Stardust API and the 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
FileCreate 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:
This code imports 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:
Next, set up the RPC provider for the Ethereum Sepolia network:
3. Create Transaction
Create and encode the transaction using the ethers
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 the ethers
library.
5. Sign the Transaction
Send the unsigned serialized transaction to the Stardust API to get it signed for your given wallet:
This code constructs a payload with the wallet ID, chain type, and encoded transaction, and sends it to the Stardust API to get a signature.
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 using eth_sendRawTransaction
.
This code sends the signed transaction using the RPC provider.
8. Output
Successful output should look like the following:
Conclusion
You have successfully created, signed, and sent a transaction using the Stardust API and the ethers
library. You can now use this example to integrate transaction sending into your application. For more information, refer to the Stardust API documentation.
Was this page helpful?