Skip to main content
After you read this page, you can deploy the 1-of-1 Safe of an owner, commit its first rule document, replace the document, and enable or disable the Safe adapter. A Safe account (kind safe_module) grants its permission when the Safe enables the Safe adapter as a module. The owner revokes the permission with disableModule. See the Safe adapter and the Safe account flow.

Relayed and owner-sent execution

Each owner operation of a Safe is one Safe transaction. The client sends it in one of two ways. The client reads the sponsorship before each operation. It never assumes it. A failed sponsorship read rejects the operation, with one exception: disableSafeModule falls back to the owner-sent way (see below). In the relayed way, the owner signs the SafeTx typed data (safeTxTypedData). The client then posts { network, account, execTransactionCalldata }. After the relay answers, the client waits up to 60 seconds for its own RPC to return the receipt (waitForRelayedTransaction). If the receipt does not arrive, confirmedBlock is null, and the method still resolves. In the owner-sent way, the owner sends execTransaction to the Safe with the pre-validated signature (buildSafePreValidatedSignature). The Safe accepts it only because msg.sender is the owner, so there is no typed-data prompt. The client waits up to 180 seconds for the receipt. A reverted receipt rejects with Error("owner transaction <hash> reverted"). Anafi relays only Safe transactions whose calls are on its list. The list has enableModule and disableModule of the configured Safe adapter at the Safe, and commitDsl and commitDslDirect at the DSL registry that name that adapter. On a network with an off-ramp handler, the list also has the off-ramp setup calls of the Safe. The calls can be alone or in a MultiSend. Each transaction must have value, gasPrice and safeTxGas at 0, as the client builds them. The Anafi API refuses other calls. For another call, use executeSafeOwnerCalls with ownerSent: true. See the API reference for the status codes of the route.

Single-owner limits

The client signs and sends Safe transactions for a Safe with threshold 1 only. Before an owner operation it reads getThreshold() and isOwner(eoa). It throws:
  • Error("Safe <safe> has threshold <n>; this client can submit only single-owner Safe transactions") when the threshold is not 1.
  • Error("<eoa> is not an owner of Safe <safe>") when eoa is not an owner.
A Safe with more owners and threshold 1 works. A Safe with threshold 2 or more does not work with these methods.

The arm flow

provisionPredictedSafe

Deploys the predicted 1-of-1 Safe of eoa, or returns the Safe that exists. Prompts: relayed 0, owner-sent 1 transaction (or 0 for already_deployed).

stageDsl

Sends the rule document to the engine for a stage, checks the reply, and returns everything that the commit needs. The owner signs nothing in the stage itself. The engine checks the document and signs an attestation for this exact commitment and adapter. A staged document commits only through commitStagedDsl.

What write changes

Order of work

  1. For arm of a Safe with no code: provisionPredictedSafe, then onProvisioned. The later checks read at or above the provision block.
  2. These checks, and the seal of the document, run at the same time:
    • adapter must equal delegationAdapters.safe, else Error("<adapter> is not this chain's configured Safe adapter").
    • The registry must list adapter, else Error("<adapter> is not the live configured safe_module adapter").
    • The adapter must admit the Safe (code hash and singleton), else Error("<safe> is not a Safe admitted by adapter <adapter>").
    • Threshold 1, and eoa is an owner (see single-owner limits).
    • isModuleEnabled(adapter) decides enableAdapter.
    • The seal reads engineEncKey() and seals 0x02 ‖ adapter ‖ parent ‖ salt ‖ yaml to the engine under dslSealInfo(network, safe).
  3. POST /api/wallets/:safe/dsl/commit/stage with { sealed }.
  4. The client checks the reply. The echoed adapter must equal adapter. The echoed commitment must equal dslCommitment(salt, yaml). attestationValidUntil must be in the future and at most 3600 seconds away. Each failed check throws an Error that starts with stageDsl:.
  5. The client opens the sealed warnings of the engine. If they cannot be opened, warnings is empty.

Return value: StagedSafeDsl

warnings holds findings that do not stop the commit, for example a rule that can never fire. Show them to the owner before the commit.

Throws

Prompts: 0, or the prompt of the provision for arm of a Safe with no code when Anafi does not pay.

commitStagedDsl

Commits a staged document with one Safe transaction.
  1. Throws Error("commitStagedDsl: the engine's attestation over this staged document has lapsed; stage it again") when attestationValidUntilUnixSeconds is now or earlier.
  2. Builds the call AnafiDslRegistry.commitDsl(commitment, validUntil, engineSig, adapter).
  3. Reads the Safe nonce(), at or above staged.minReadBlock, and reads the sponsorship.
  4. Builds the Safe transaction. With enableAdapter: true, it is a MultiSend delegatecall of 2 calls: Safe.enableModule(adapter), then commitDsl. Else it is one plain call of commitDsl.
  5. Calls onStep("safe") before the wallet prompt.
  6. Relayed: the owner signs the SafeTx, then onSigned(), then POST /api/wallets/:safe/safe/sponsor_exec. Owner-sent: the owner sends execTransaction, and onSigned() runs when the wallet returns the hash.
The commitDsl call reverts when the attestation deadline passes before inclusion, or when another commit landed since the stage. See the DSL registry.

armSafe

stageDsl with write: "arm", then commitStagedDsl. Use it for the first document of an account. The warnings of the stage are not returned. To show them before the commit, call the two methods yourself. Prompts in order, worst case (Anafi does not pay): 1 deploy transaction, then 1 execTransaction. Best case (Anafi pays): 1 typed-data signature.

commitDslFromSafe

stageDsl with write: "update", then commitStagedDsl. The Safe must have enabled the adapter. Prompts: 1. To pause all rules, commit a document with no rules (rules: {}). See update, pause and revoke.

readSafeModuleEnabled

Reads Safe.isModuleEnabled(adapter). With options, the read is pinned under the retry rule.

enableSafeModule

Enables the adapter as a module with one Safe transaction: Safe.enableModule(adapter), sent to the Safe itself. It commits no document. Use it to restore the permission after a disableSafeModule, with the same committed document. Checks: adapter is delegationAdapters.safe, the registry lists it, the adapter admits the Safe, threshold 1, and eoa is an owner. Prompts: 1.

disableSafeModule

Revokes the permission: one Safe transaction that calls Safe.disableModule(prevModule, adapter). After it lands, the adapter is no longer a module of the Safe. See the Safe adapter.
  1. Checks that adapter is delegationAdapters.safe and that the adapter admits the Safe. It does not need the adapter to be live for an owner-sent revoke.
  2. Reads the sponsorship. If that read fails, the client chooses the owner-sent way, so the revoke does not depend on the Anafi API. It then reads the native balance of eoa:
    • If the balance read fails, it throws an Error that says so.
    • If the balance is 0, it throws Error("This deployment could not say whether it pays for the revoke, and owner <eoa> holds no gas to send it. Use the self-funded path instead: disable the module from the Safe itself, for example in its own wallet UI.").
  3. For a relayed revoke, the registry must list the adapter. Else it throws Error("This deployment will not pay for the revoke because Safe adapter <adapter> is not live. Use the self-funded path instead: ...").
  4. Checks threshold 1 and that eoa is an owner.
  5. Reads the module list with getModulesPaginated (pages of 50, at most 20 pages) and finds the module before adapter. Throws Error("<safe> does not have adapter <adapter> enabled") when the adapter is not in the list.
  6. Sends the Safe transaction.
Prompts: 1. You can also revoke without Anafi and without this SDK: call disableModule from the Safe in any Safe wallet.

executeSafeOwnerCalls

Has the owner authorize your calls as one Safe transaction. One leg is a plain call. Two or more legs are a MultiSend batch of zero-value calls. The method resolves with the verdict of the Safe in success. It rejects on a reverted receipt of an owner-sent transaction. It does not check adapter or any other target: you are responsible for the calls.

waitForRelayedTransaction

Waits up to 60 seconds for your RPC to return the receipt of a transaction that the relay reported. It returns the receipt block, or null when the receipt did not arrive or had no valid block. It never rejects. The relay can read a node that is ahead of yours, so a read right after its answer can miss the write. This wait closes that gap. The client calls it after each relayed write.

Sponsorship

fetchWalletSponsorship(aa) returns { feesOn, sponsored }. The client relays an owner operation of a Safe when !feesOn || sponsored. See activity and fees.