Skip to main content
RyvoClient is the primary entry point in @ryvonetwork/sdk. It wires the generated IDL to an AnchorProvider and exposes one typed method for every instruction in the on-chain program. Under the hood, each method returns an Anchor MethodsBuilder, so you can extend the call with .preInstructions(), .postInstructions(), .signers(), .rpc(), .transaction(), or .instruction() as needed.

Construction

Options

The SDK also re-exports two lower-level helpers if you want to bring your own Program:

Address helpers

RyvoClient memoises nothing; these are pure deterministic derivations and safe to call as often as you need. See PDAs & constants for the underlying formulas.

Account readers

Convenience wrappers over program.account.*.fetch that accept public keys of owners rather than PDAs where useful.

fetchChannel(params)

Resolves a channel in two ways:

channelAddressForOwners(payerOwner, payeeOwner, tokenId)

Same owner-based resolution, but returns only the PDA (no RPC for the channel itself). Useful when you want to pre-compute a channel address before anyone has opened it.
Every fetch* call hits the RPC configured on your AnchorProvider. For high-frequency reads, cache or batch them yourself.

Instruction builders

Each of the methods below returns an Anchor MethodsBuilder<RyvoProtocol, ...>. You must finish the chain with .rpc(), .transaction(), or .instruction() to actually do anything. All input amounts accept Amountish (bigint, number, string, or any { toString(): string }).

initializeProtocol(params)

Initialize GlobalConfig, only runnable once per deployment by the upgrade authority.

registerToken(params)

Register a settlement token in TokenRegistry. Restricted to the registry authority.
symbol is validated against /^[\x20-\x7E]{1,8}$/ (1–8 printable ASCII) and encoded as a 8-byte array via encodeSymbol() (also exported).

initializeParticipant(params)

Create a ParticipantAccount for owner. Pays the registration fee to feeRecipient (typically the protocol fee recipient).

createChannel(params)

Open a channel-v2 state account for a (payer, payee, token) triple. Either payeeOwner or payeeAccount is required.

deposit(params)

Move tokens from an owner’s SPL account into the participant’s protocol balance.

lockChannelFunds(params)

Allocate already-deposited balance to a specific channel. The SDK resolves the channel PDA automatically when channelState is omitted.

requestUnlockChannelFunds(params) / executeUnlockChannelFunds(params)

Two-phase unlock with the protocol’s unlock timelock in between. Same parameter shape as lockChannelFunds, except execute does not take an amount, the whole requested unlock is finalized at once.

requestWithdrawal(params) / executeWithdrawalTimelocked(params) / cancelWithdrawal(params)

Withdraw balance out of the protocol to an SPL destination. Honour the timelock defined in GlobalConfig.
cancelWithdrawal clears the pending request without touching balances.

updateInboundChannelPolicy(params)

Change how other participants are allowed to open channels to this participant.

Settlement

All three settlement flows take a submitter, the key that pays for the transaction and submits the signature pre-instruction.
All three wire the instructions sysvar (SYSVAR_INSTRUCTIONS_PUBKEY) automatically so the program can read the Ed25519 verification output from the transaction. See Settlement modes for when to use each one.

Account helpers

Two pure helpers complement the readers above.

getTokenBalance(participantData, tokenId)

Look up a specific token balance entry inside a fetched ParticipantAccount, with safe zero defaults when the entry does not exist yet:

nextCommitmentAmount(channelData, delta)

Compute the next committed_amount for a commitment, given an already-fetched channel state and an incremental delta:
Returns an Anchor BN so it composes with the other builders.

Error handling

Anchor raises its own error types for RPC and program errors. RyvoClient does not wrap them, let them bubble up and inspect error.error?.errorCode / error.logs as usual. The canonical list of protocol error codes is on Reference -> Errors.