Skip to content

Writing a payload

The backend takes a JSON description of a PTB and builds, signs and submits it. This page covers every argument form, how one call's result feeds another, and the sample payloads in the repository. Only PTBs made of Move calls are supported.

You will learn / You need

You will learn: the shape of a SendPTB body, each argument kind with an example, how to use a call's result as an argument, and what the sample payloads call. You need: a running backend (Deploying the stack); the first PTB is the shortest path to one working request.

Endpoints

Endpoint Notes
POST http://localhost:5000/api/SendPTB Always available
POST http://localhost:5000/api/SendAAPTB Deprecated. Only with ENABLE_AA=true; see Legacy: the abstract_account path
GET http://localhost:5000/health Liveness

Request and response fields: HTTP endpoints.

Anatomy of a payload

A body has two top-level keys, auth and ptb (HttpPostPayload in stealth_name_service/backend/testing_backend/src/main.rs).

Key Required Meaning
auth.address yes Sender. Its key must be in the backend's iota.keystore; the backend signs with it.
auth.request_number yes Request index. Labels the CSV row; does not spawn anything.
auth.agent_number yes Agent index. Labels the CSV row.
auth.gas_budget yes Gas budget of the transaction.
ptb yes Array of PTB definitions. Only the first one is used.
ptb[].network yes testnet or devnet. Anything else is an error.
ptb[].calls yes Move calls, appended to the PTB in order.
calls[].target yes <package>::<module>::<function>.
calls[].type_args no Type arguments in Move notation, such as "0x2::iota::IOTA" or "u64". Defaults to empty.
calls[].args yes One JSON array per Move argument; see below.

A direct POST must carry all four auth fields: a body without them is rejected. loadtest overwrites address, request_number, agent_number and gas_budget on every request, so a file you give to loadtest is a template; see Running a load test.

This payload makes the agent at auth.address call 0x2::clock::timestamp_ms twice on Devnet. The address is an example; replace it with one of yours (next section).

{
  "auth": {
    "address": "0xfc74351b74b7fc6d8d2d94e3440fc1bf49a265436f9851a7f52389acbda7a275",
    "request_number": 0,
    "agent_number": 0,
    "gas_budget": 10000000
  },
  "ptb": [{
    "network": "devnet",
    "calls": [
      {"target": "0x2::clock::timestamp_ms", "type_args": [], "args": [["immutable", "0x6"]]},
      {"target": "0x2::clock::timestamp_ms", "type_args": [], "args": [["immutable", "0x6"]]}
    ]
  }]
}

Choosing the sender

Any address in the keystore works, as long as it owns gas coins on the network you name. To list the first few addresses (this prints addresses only, never key material):

jq -r '.keys[].address' stealth_name_service/backend/testing_backend/iota.keystore | head

loadtest maps agent i to the i-th address of that list. Fund the address before the first request: Fund it.

Argument kinds

Each element of args is a JSON array. Two elements are [type, value]; three elements are [command, type, data]. Any other length is rejected with Invalid array length, expect 2 or 3, got N (parse_argument() in stealth_name_service/backend/testing_backend/src/ptb_args.rs).

Form Example Becomes
["u8" \| "u16" \| "u32" \| "u64", n] ["u64", 2] A pure integer input.
["u128", n] ["u128", 7] A pure u128. The value is read as a JSON integer up to u64.
["u256", "<decimal>"] ["u256", "5"] A decimal string. See the warning below.
["bool", b] ["bool", true] A pure bool.
["string", s] ["string", "hello"] A pure 0x1::string::String.
["address", a] ["address", "0xabc…"] A pure address.
["object", id] ["object", "0x13a4…"] An object, requested as mutable.
["immutable", id] ["immutable", "0x6"] An object, requested as immutable. Resolved references to frozen or shared objects are cached per object id.
["result", cmd, res] ["result", 0, 0] The output of an earlier command. See below.
["vector", type, [e, …]] ["vector", "u8", [1, 2, 3]] Each element becomes its own input, joined by MakeMoveVec. One level only.
["vecmap", [k, v], [{key: value}, …]] ["vecmap", ["string", "string"], [{"a": "b"}]] A 0x2::vec_map::VecMap, built with from_keys_values. Each entry is an object with exactly one pair. Keys reach the parser as JSON strings, so use a key type that parses from a string, such as string; a u64 key fails with Expected u64 value.
["option", type, value] ["option", "u8", 5] 0x1::option::some. A null value gives 0x1::option::none.
["pure", type, value] ["pure", "vector<vector<u8>>", [...]] The whole value BCS-encoded off-chain as one pure input.

option also takes "vector" as its type, with the content as [type, values]: ["option", "vector", ["u8", [1, 2]]]; null values give none. "vecmap" is accepted too, but the parser returns the bare VecMap without wrapping it in option::some, so the result is a VecMap, not an Option. Avoid it.

u256 in the two-element form is 128 bits

get_argument_from_parsing() parses ["u256", "<decimal>"] into a 128-bit integer. The value is encoded as 16 bytes, not 32. For a full u256, use ["pure", "u256", "<decimal>"].

The type slot of vector, vecmap and option takes the scalar names above. An unknown name fails with Unsupported argument type: <name> or Unsupported move type: <name>; an unknown command in a three-element array fails with Unsupported command type: <name>.

Nested and encoded arguments

["pure", <type>, <value>] BCS-encodes a value off-chain and passes it as one pure input. That is how nested types such as vector<vector<u8>> are reached; ["vector", …] makes each element a separate input and cannot nest. It accepts u8 to u256, bool, address, string and vector<T> of any of them, at any depth. Large integers may be decimal strings. Source: encode_pure() in stealth_name_service/backend/testing_backend/src/pure_args.rs.

Inside a vector<u8>, these shorthands save hand-encoding bytes:

JSON Becomes
[104, 105] Those bytes
"bridge_target" UTF-8 bytes (not base64)
"0x627269..." Hex-decoded bytes
{"base64": "…"} Base64-decoded bytes
{"bcs": ["u64", 42]} BCS of that typed value, for args
{"type": "0x2::iota::IOTA"} BCS of the canonical type string, for type_args

An object shorthand must have exactly one key. The cross-chain request in stealth_name_service/backend/agent/payloads/bridge_request.json uses all of this to describe the destination call (bridge_target::record(1u64, 42u64, "hello")):

["pure", "vector<u8>", "bridge_target"],
["pure", "vector<u8>", "record"],
["pure", "vector<vector<u8>>", [{"bcs": ["u64", 1]}, {"bcs": ["u64", 42]}, {"bcs": ["string", "hello"]}]],
["pure", "vector<vector<u8>>", []]

Using one call's result in another

["result", cmd, res] passes output number res of command number cmd as an argument. It becomes a NestedResult(cmd, res) in the PTB (parse_nested_result() in src/ptb_args.rs). The command index counts every command of the PTB, in order, not only your calls.

Argument forms that build values on chain add commands before the call that uses them:

Argument Commands it adds
vector 1 (MakeMoveVec)
option 1 (option::some or option::none), plus 1 more for a vector content. With vecmap content: 3, and no option wrapper
vecmap 3 (two MakeMoveVec, then vec_map::from_keys_values)
pure, scalars, objects 0

Your call is the command after those. A call with no such arguments is the next command in sequence. This payload makes a value in call 0 and consumes it in call 1 (<PACKAGE>, make and consume are placeholders for your own module):

"calls": [
  {"target": "<PACKAGE>::module::make",    "type_args": [], "args": [["u64", 7]]},
  {"target": "<PACKAGE>::module::consume", "type_args": [], "args": [["result", 0, 0]]}
]

Here make takes only a scalar, so it is command 0. If make also took ["vector", "u8", [1, 2]], the MakeMoveVec would be command 0, make command 1, and the reference would be ["result", 1, 0].

Several calls and several PTBs

calls may hold any number of calls. They run in one transaction, in order, and the response has one transactions item for it.

ptb is an array, but the handler reads only its first element (payload.ptb.first() in execute_ptb_handler()); an empty array fails with No PTB definition provided. A second entry is ignored without an error. To send two transactions, send two requests.

Sample payloads

The repository keeps ready-made bodies in stealth_name_service/backend/agent/payloads/. Each top-level file holds one PTB. Package ids in them come from the authors' own deployments; call your own packages by replacing target and the object ids.

File Network What it calls
get_time.json testnet 0x2::clock::timestamp_ms with the clock object 0x6. The smallest useful payload and the default LOADTEST_JSON.
bridge_request.json testnet bridge_source::request: a cross-chain request for bridge_target::record. The sample used in the bench_sweep examples.
get_timestamp_PTB_AA.json devnet Deprecated. Two 0x2::clock::timestamp_ms calls, written for the legacy AA path. See Legacy.
create_new_document.json testnet manage_documents::create_document, with a vecmap and a vector.
heavy_new_doc.json testnet manage_documents::create_document with eight arguments: a larger body of the same call.
update_document.json testnet manage_documents::save_new_version, eight arguments including a vecmap.
access_document.json testnet manage_documents::request_doc.
create_did.json testnet intelligible_identity::new.
create_akn_iri.json testnet item::new_from_vecmaps. Uses the key ptbs; see the note below.
update_iter.json testnet coordinator::new_iter, twelve arguments. Uses the key ptbs.
test_akn.json, test_option.json testnet akn_ontology::elaborate_str, with option arguments.
utils_test.json testnet myutils::equals, with a vector argument.
sample_call_body.json testnet registry::add_record.
split_coin.json testnet A SplitCoins command object instead of a Move call.
ptb_AA/ devnet Deprecated. 41 files, ptb_0.json to ptb_40.json: 25 abstract_account::add_controller calls in each of ptb_0.json to ptb_39.json, one in ptb_40.json. See Legacy.
acl/ none Not requests. 30 files, acl_batch_00.json to acl_batch_29.json, of the form batch, account_id, source_chain_id, anchor, senders. Read by bridge_acl_add; see Managing the ACL.
events/ testnet Four further example payloads (coordinator::new_simple_iter, coordinator::new_iter, manage_documents::create_document, myutils::equals).

Files that the backend will not accept as they are

create_akn_iri.json and update_iter.json name the PTB list ptbs, but the backend requires ptb. split_coin.json uses SplitCoins, which is not a Move call, and has no auth fields beyond an empty address. Treat these three as notes, not as working inputs. Several others carry only auth.address: fine as loadtest templates, but not as a direct POST.

Check it worked

Send your payload with curl as in the first PTB. A good response is HTTP 200 with "status": "Success" in transactions[0]. A 500 carries the error text: an argument the parser could not encode, an unsupported network, or No gas coins available for sender <address>.

Next