Skip to content

Your first PTB in ten minutes

Deploy the stack, send one programmable transaction block (PTB) to the backend with curl, read the response and find the transaction in the explorer.

You will learn / You need

You will learn: how to start the backend, build a request body and read the response. You need: the repository, Docker, a .env and the keystore from Setup, and an address from the keystore that holds coins on the network you send to.

1. Deploy

bridge mode always includes the backend, which serves the API on port 5000, and never starts a load test. This page only uses the backend. (docker-compose.standalone.yml also runs a single backend, but deploy.sh never loads it; see Compose stacks.)

Run every command on this page from the repository root.

(cd stealth_name_service/backend && ./deploy.sh)

The first deploy builds the Rust images and takes several minutes.

bridge mode also starts event_listener and event_handler. Until the bridge settings from Track B or Track C are in place they may log errors or restart. That does not affect POST /api/SendPTB.

Resets Docker Swarm

deploy.sh leaves and re-creates the swarm. See Deploying the stack.

2. Wait for the backend

/health answers as soon as the server is bound. /ready answers READY once the gas-coin caches are warm and 503 with WARMING before. A request sent early still works but is slower (GET /ready).

until curl -sf http://localhost:5000/ready; do sleep 2; done

3. Pick a sender

auth.address must be an address whose key is in testing_backend/iota.keystore; the backend signs with it. Print the first one (this reads only the address field, never the key):

python3 -c "import json;print(json.load(open('stealth_name_service/backend/testing_backend/iota.keystore'))['keys'][0]['address'])"

Fund it

The sender pays the gas from its own coins. The backend looks for gas coins owned by auth.address on the network named in the request:

  • At startup the backend preloads a coin cache for the first NUM_AGENTS keystore addresses (1000 in the sample) on both testnet and devnet (warm_ptb_caches() in src/main.rs). A request from an address with a cache entry uses a cached coin.
  • An address with no cache entry, such as one that had no coins at startup, is looked up over RPC on each request. If it owns no coins the answer is a 500 with No gas coins available for sender <address>.

So fund the address first. With the IOTA CLI, iota client gas <address> lists its coins. To get test coins on testnet or devnet, use the network's web faucet: paste the address and solve the captcha. Alternatively, send coins from another funded address. Then run iota client gas <address> again to confirm the coins arrived.

CLI faucet

iota client faucet is deprecated: the faucet now requires the web page with a captcha, so the CLI command no longer funds an address.

If the address already had a cache entry before you funded it, redeploy ((cd stealth_name_service/backend && ./deploy.sh)) so the cache is rebuilt; a sender with no entry needs no restart.

4. Send the request

The sample stealth_name_service/backend/agent/payloads/get_time.json holds only the PTB: one call to 0x2::clock::timestamp_ms on testnet, with an empty auth.address. loadtest fills in the auth fields; with curl you provide all of them. address, request_number, agent_number and gas_budget are all required.

curl -s -X POST http://localhost:5000/api/SendPTB \
  -H 'Content-Type: application/json' \
  -d '{
    "auth": {
      "address": "<ADDRESS-FROM-STEP-3>",
      "request_number": 0,
      "agent_number": 0,
      "gas_budget": 10000000
    },
    "ptb": [{
      "network": "testnet",
      "calls": [{
        "target": "0x2::clock::timestamp_ms",
        "type_args": [],
        "args": [["immutable", "0x6"]]
      }]
    }]
  }'

Argument forms are explained in Writing a payload.

5. Read the response

A 200 has the shape {"transactions": [ ... ], "status_code": 200}:

Field Meaning
digest Transaction digest. Search for it in the explorer.
status Success, or Failure: <error> (a Move abort is still HTTP 200)
gas Computation, storage and net fees
network_type The network you sent to
total_time, network_latency, blockchain_processing_time Timings, in seconds (f64 fields in src/server.rs)
checkpoint_height Node checkpoint height when it answered; omitted when unknown

All fields: POST /api/SendPTB. A 500 carries {"error": "<message>", "status_code": 500}, for example No gas coins available for sender <address>.

6. Find it in the explorer

Open the IOTA explorer for the network you used (testnet here) and search for the digest.

Check it worked

  • curl http://localhost:5000/ready prints READY.
  • The response has "status_code": 200 and "status": "Success".
  • The explorer shows a transaction with that digest.

Clean up

docker stack rm stealth-name-service-backend_bridge

Next