Skip to main content

IOTA Developer Cheat Sheet

Quick reference on best practices for IOTA Network developers.

Move

General

  • Read about package upgrades and write upgrade-friendly code:
    • Packages are immutable, so buggy package code can be called forever. Add protections at the object level instead.
    • If you upgrade a package P to P', other packages and clients that depend on P will continue using P, not auto-update to P'. Both dependent packages and client code must be explicitly updated to point at P'.
    • public function signatures cannot be deleted or changed, but public(package) and entry functions can. Use public(package) or private visibility liberally unless you are exposing library functions that will live forever.
    • It is not possible to delete struct types, add new fields (though you can add dynamic fields), or add new abilities via an upgrade. Introduce new types carefully—they will live forever!
  • Use vector-backed collections (vector, VecSet, VecMap, PriorityQueue) with a known maximum size of ≤ 1000 items.
    • Use dynamic field-backed collections (Table, Bag, ObjectBag, ObjectTable, LinkedTable) for any collection that allows third-party addition, larger collections, and collections of unknown size.
    • Move objects have a maximum size of 250KB—any attempt to create a larger object leads to an aborted transaction. Ensure that your objects do not have an ever-growing vector-backed collection.
  • If your function f needs a payment in (e.g.) IOTA from the caller, use fun f(payment: Coin<IOTA>) not fun f(payment: &mut Coin<IOTA>, amount: u64). This is safer for callers—they know exactly how much they are paying, and do not need to trust f to extract the right amount.
  • Don't micro-optimize gas usage. IOTA computation costs are rounded up to the closest bucket, so only very drastic changes will make a difference. In particular, if your transaction is already in the lowest cost bucket, it can't get any cheaper.
  • Follow the Move coding conventions for consistent style.

Composability

  • Use the display standard to customize how your objects show up in wallets, apps, and explorers
  • Avoid “self-transfers”—whenever possible, instead of writing transfer::transfer(obj, tx_context::sender(ctx)), return obj from the current function. This allows a caller or programmable transaction block to use obj.

Testing

  • Use iota::test_scenario to mimic multi-transaction, multi-sender test scenarios.
  • Use the iota::test_utils module for better test error messages via assert_eq, debug printing via print, and test-only destruction via destroy.
  • Use iota move test --coverage to compute code coverage information for your tests, and iota move coverage source --module <name> to see uncovered lines highlighted in red. Push coverage all the way to 100% if feasible.

Apps

  • For optimal performance and data consistency, apps should submit writes and reads for the same full node. In the TS SDK, this means that apps should use the wallet's signTransactionBlock API, then submit the transaction via a call to execute_transactionBlock on the app's full node, not use the wallet's signAndExecuteTransactionBlock API. This ensures read-after-write-consistency--reads from the app's full node will reflect writes from the transaction right away instead of waiting for a checkpoint.
  • For lower latency, use executeTransactionBlock with "showEffects": false and "showEvents": false if your app needs to know that a transaction was confirmed, but does not immediately need to see the transaction effects or read the objects/events written by the transaction.
  • Apps should implement a local cache for frequently read data rather than over-fetching from the full node.
  • Whenever possible, use programmable transaction blocks to compose existing on-chain functionality rather than publishing new smart contract code. Programmable transaction blocks allow large-scale batching and heterogeneous composition, driving already-low gas fees down even further.
  • Apps should leave gas budget, gas price, and coin selection to the wallet. This gives wallets more flexibility, and it's the wallet's responsibility to dry run a transaction to ensure it doesn't fail.

Signing

  • Never sign two concurrent transactions that are touching the same owned object. Either use independent owned objects, or wait for one transaction to conclude before sending the next one. Violating this rule might lead to client equivocation, which locks up the owned objects involved in the two transactions until the end of the current epoch.
  • Any iota client command that crafts a transaction (e.g., iota client publish, iota client call) can accept the --serialize-output flag to output a base64 transaction to be signed.
  • IOTA supports several signature schemes for transaction signing, including native multisig.