This example demonstrates how to interact with an instance of the IOTA Gas Station
using the TypeScript SDK. It covers:
- Reserving gas from the gas station.
- Creating and signing a transaction locally.
- Submitting the transaction to the gas station for co-signing and on-chain execution.
In the example gasStationTest.ts
, the issued transaction calls a function in the system clock package:
- packageId =
0x2
- moduleName =
clock
- functionName =
timestamp_ms
- clockObjectId =
0x6
This system package is available on every IOTA network instance (devnet, testnet, mainnet, or local), ensuring that this transaction is universally executable across all networks. The purpose of this example is to demonstrate that the caller's address (user
) does not need to hold any funds (IOTA tokens) to execute a transaction using the gas station.
-
A running instance of the
IOTA Gas Station
is required. To learn how to set up the Gas Station, please follow this link.You should have:
- The URL of the gas station instance.
- A valid authentication bearer token for its API.
- Node.js v16+ installed on your machine.
-
Install dependencies for the project:
npm install
- Copy
.env.example
to.env
:
cp .env.example .env
- Edit the
.env
file:
- The private key that will interact with the IOTA Gas Station instance.
- URLs for Node, Explorer, IOTA Gas Station instance.
- The authentication bearer token for the Gas Station API authentication.
Once the setup is complete, you can run the example with:
npx ts-node gasStationTest.ts
If you encounter any problems please check Common Issues section.