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
toP'
, other packages and clients that depend onP
will continue usingP
, not auto-update toP'
. Both dependent packages and client code must be explicitly updated to point atP'
. public
function signatures cannot be deleted or changed, butpublic(package)
andentry
functions can. Usepublic(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.
- Use dynamic field-backed collections (
- If your function
f
needs a payment in (e.g.) IOTA from the caller, usefun f(payment: Coin<IOTA>)
notfun 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 trustf
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))
, returnobj
from the current function. This allows a caller or programmable transaction block to useobj
.
Testing
- Use
iota::test_scenario
to mimic multi-transaction, multi-sender test scenarios. - Use the
iota::test_utils
module for better test error messages viaassert_eq
, debug printing viaprint
, and test-only destruction viadestroy
. - Use
iota move test --coverage
to compute code coverage information for your tests, andiota 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 toexecute_transactionBlock
on the app's full node, not use the wallet'ssignAndExecuteTransactionBlock
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.
Feedback Form