Predict Accounts SDK
The account functions create a trader's shared AccountWrapper, move USDC in and out of it, and attach a builder code, and the /account subpath exposes the account primitive underneath for transactions you compose yourself. Accounts and Custody explains the custody mechanism: the wrapper, the Auth hot potato, settlement, and the account events.
The client.predict calls assume the client from DeepBook Predict SDK.
Derive the wrapper ID
Every Predict call that acts on an account takes the owner's AccountWrapper object ID as its wrapper argument. The account registry derives the wrapper from the owner address, so the SDK computes its ID offchain with no chain read, and the ID is valid before the account exists. The facade derives it from the owner you pass, so you need the ID yourself only to compose transactions or to look up the object. Derive the IDs before you create covers the Move side, and Wrapper ID and account ID explains why the wrapper ID is not the account ID that events carry.
wrapperIdFor
Use client.predict.wrapperIdFor to get the wrapper ID for an owner under the client's deployment. It returns the ID as a string.
It takes this parameter:
owner: The address that owns the account.
packages/deepbook-v3/src/predict/client.ts. You probably need to run `pnpm prebuild` and restart the site.deriveAccountWrapperId
Use deriveAccountWrapperId from @mysten/deepbook-v3/predict when you hold a Predict configuration but no client, for example in a backend that builds transactions for many owners. It runs the same derivation as wrapperIdFor and returns the ID as a string.
It takes these parameters:
cfg: ThePredictConfigfor the deployment, such as thegetConfigresult for Mainnet.owner: The address that owns the account.
packages/deepbook-v3/src/predict/tx/common.ts. You probably need to run `pnpm prebuild` and restart the site.The following function derives the ID from the Mainnet configuration:
import { deriveAccountWrapperId, getConfig } from '@mysten/deepbook-v3/predict';
// Returns the same ID as client.predict.wrapperIdFor(owner), with no client.
export function wrapperIdOf(owner: string): string {
return deriveAccountWrapperId(getConfig('mainnet'), owner);
}
To derive the ID from the account package IDs alone, without a Predict configuration, use AccountContract.deriveAccountWrapperId.
Account functions
Each account builder returns a new, unsigned Transaction that holds only that builder's commands, so you sign and execute each one separately. To combine account commands with others in a single programmable transaction block (PTB), use the /account subpath or the composition helpers in DeepBook Predict SDK.
tx.deposit and tx.withdraw mint an Auth bound to the transaction sender, and the contract aborts with EInvalidOwner unless the sender owns the account, so the owner must sign them. The Auth hot potato describes that check.
tx.createManager
Use tx.createManager to create the signer's account wrapper and share it. It returns a Transaction that holds account_registry::new followed by account::share. The name survives from DeepBook balance managers, but the object it creates is the account wrapper.
It takes no parameters. The transaction sender becomes the owner, because account_registry::new records the sender. The builder does no chain read, so a second creation for the same owner aborts with EAccountAlreadyExists, as Create an account describes. To create and fund the account in the same transaction, use tx.deposit with { create: true }.
Neither tx.createManager nor tx.deposit attaches a referrer, and the contract accepts a referrer only at account creation. To create an account that pays a referrer, compose the call yourself, as Create an account with a referrer shows. Do this before the user creates an account any other way, because the first creation is the only chance.
packages/deepbook-v3/src/predict/client.ts. You probably need to run `pnpm prebuild` and restart the site.Decode the result with decode.createManager to read the new wrapper ID and account ID.
tx.deposit
Use tx.deposit to move USDC from the signer into the account's stored balance. It returns a Transaction. The SDK adds a coinWithBalance intent for the deployment's quote coin, which resolves when you build the transaction, drawing on the sender's coin objects and address balance. Without create, the transaction then calls account::deposit_funds on the wrapper at wrapperIdFor(owner), which settles pending funds before it deposits.
It takes these parameters:
owner: The address that owns the account. It must sign the transaction, and withoutcreatethe SDK derives the target wrapper from it.amountUsdc: The amount to deposit in USDC, as a decimalnumberorstringsuch as250or'12.5'. The SDK throwsPredictInputErrorfor a negative value or for more than 6 decimal places.opts.create: An optional flag. Whentrue, the transaction creates the account wrapper, deposits into it, and shares it last, in a single PTB. If you omit it, the SDK deposits into an existing account.
packages/deepbook-v3/src/predict/client.ts. You probably need to run `pnpm prebuild` and restart the site.With { create: true }, the contract derives the new wrapper from the transaction sender, not from owner, so a different signer creates and funds its own account instead. The builder does no chain read, so the transaction aborts with EAccountAlreadyExists when the account already exists: check for an object at wrapperIdFor(owner) first, or retry without create after that abort.
Sharing comes last because a wrapper that the PTB creates is reachable only through the handle account_registry::new returns, as AccountContract.createAccountAndDeposit explains. Decode the result with decode.deposit, and also with decode.createManager when you pass create.