Skip to content

Latest commit

 

History

History
57 lines (37 loc) · 1.84 KB

README.md

File metadata and controls

57 lines (37 loc) · 1.84 KB

TypeScript Example: IOTA Gas Station Integration

This example demonstrates how to interact with an instance of the IOTA Gas Station using the TypeScript SDK. It covers:

  1. Reserving gas from the gas station.
  2. Creating and signing a transaction locally.
  3. 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.

Prerequisites

  1. 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.
  2. Install dependencies for the project:

npm install

Configuration

  1. Copy .env.example to .env:
cp .env.example .env
  1. 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.

Run the Example

Once the setup is complete, you can run the example with:

npx ts-node gasStationTest.ts

Common Issues

If you encounter any problems please check Common Issues section.