OZTransactionOperations
public final class OZTransactionOperations : OZManagerHelpers, @unchecked Sendable
Transaction-pipeline operations for OpenZeppelin Smart Accounts.
Builds, signs, and submits transactions for a connected smart account wallet. Drives the full simulate / sign / re-simulate / submit pipeline, including WebAuthn auth-entry signing, relayer-vs-RPC submission selection, and transaction-result polling.
When a relayer is configured, submission mode is auto-selected: Mode 1
(host function + auth entries, envelope unsigned) when all auth entries use
Address credentials; Mode 2 (signed envelope XDR forwarded to the relayer)
when any auth entry carries sourceAccount credentials. The forceMethod
parameter overrides auto-detection per call.
The transaction is re-simulated after the signing pass so that resource fees reflect the real WebAuthn signature payload size.
Instances are constructed by OZSmartAccountKit and accessed through
kit.transactionOperations.
-
Transfers tokens from the connected smart account to a recipient.
Compatible with any SEP-41 token (native asset via the Stellar Asset Contract, or custom Soroban tokens). The decimal amount is converted to the token’s base units before submission: the
decimalsvalue is used when supplied, otherwise the token’s on-chaindecimals()is fetched automatically viafetchTokenDecimals(tokenContract:). Delegates tocontractCall(target:targetFn:targetArgs:forceMethod:resolveContextRuleIds:)to drive the full simulate / sign / submit pipeline.Throws
NotConnectedwhen no wallet is connected;SmartAccountValidationExceptionfor invalid inputs or self-transfer;SmartAccountTransactionExceptionfor simulation, signing, or submission failures;WebAuthnExceptionfor biometric-authentication failures.Declaration
Swift
public func transfer( tokenContract: String, recipient: String, amount: String, decimals: Int? = nil, forceMethod: OZSubmissionMethod? = nil ) async throws -> OZTransactionResultParameters
tokenContractSEP-41 token contract address (
C…strkey).recipientRecipient address (
G…account orC…contract).amountDecimal amount string (for example
"10"or"100.5").decimalsThe token’s decimal scale used to convert
amountto base units. Whennil(default) the value is fetched on-chain viafetchTokenDecimals(tokenContract:). Supply it to avoid the extra RPC round trip when the scale is already known.forceMethodOptional submission-method override.
Return Value
OZTransactionResultdescribing the on-chain outcome. -
fetchTokenDecimals(tokenContract:Asynchronous) Reads the
decimals()value from a SEP-41 token contract.Simulates the token contract’s
decimalsfunction and returns the reportedu32scale.Throws
SmartAccountValidationExceptionwhentokenContractis not a valid contract address;SmartAccountTransactionExceptionwhen the simulation fails or the contract does not return a validu32value.Declaration
Swift
public func fetchTokenDecimals(tokenContract: String) async throws -> IntParameters
tokenContractSEP-41 token contract address (
C…strkey).Return Value
The token’s decimal scale.
-
Calls an arbitrary function on an external contract directly from the smart account.
The smart account authorizes the call via Soroban’s
require_authmechanism triggered by the target contract. Use this for any external contract interaction (token approvals, token transfers, DeFi protocol calls) where the smart account is the authorized party.Declaration
Swift
public func contractCall( target: String, targetFn: String, targetArgs: [SCValXDR] = [], forceMethod: OZSubmissionMethod? = nil, resolveContextRuleIds: OZResolveContextRuleIds? = nil ) async throws -> OZTransactionResultParameters
targetTarget contract address (
C…strkey).targetFnFunction name to invoke on the target contract.
targetArgsPre-encoded SCVal arguments forwarded to the function.
forceMethodOptional submission-method override.
resolveContextRuleIdsOptional override of the automatic context-rule resolution performed during the signing loop.
Return Value
OZTransactionResultdescribing the on-chain outcome. -
Executes an arbitrary function via the smart account contract’s
executeentry point.Calls
execute(target, target_fn, target_args)on the smart account contract; the contract dispatches the inner call on behalf of the smart account after evaluating its context rules and policies.Declaration
Swift
public func executeAndSubmit( target: String, targetFn: String, targetArgs: [SCValXDR] = [], forceMethod: OZSubmissionMethod? = nil, resolveContextRuleIds: OZResolveContextRuleIds? = nil ) async throws -> OZTransactionResultParameters
targetTarget contract address (
C…strkey).targetFnFunction name to invoke on the target contract.
targetArgsPre-encoded SCVal arguments forwarded to the inner call.
forceMethodOptional submission-method override.
resolveContextRuleIdsOptional context-rule resolver override.
Return Value
OZTransactionResultdescribing the on-chain outcome. -
Submits a host function through the full simulate / sign / re-simulate / submit pipeline.
This is the low-level entry point used by
transfer(tokenContract:recipient:amount:forceMethod:),contractCall(target:targetFn:targetArgs:forceMethod:resolveContextRuleIds:), andexecuteAndSubmit(target:targetFn:targetArgs:forceMethod:resolveContextRuleIds:). Callers that need to construct a host function manually use this method directly. The auth-entry signing pass writes the OpenZeppelin AuthPayload Map directly into the credentials’signaturefield; the transaction is re-simulated after signing because WebAuthn signatures are larger than the placeholders the initial simulation used.Declaration
Swift
public func submit( hostFunction: HostFunctionXDR, auth: [SorobanAuthorizationEntryXDR], forceMethod: OZSubmissionMethod? = nil, resolveContextRuleIds: OZResolveContextRuleIds? = nil ) async throws -> OZTransactionResultParameters
hostFunctionHost function to execute.
authAuthorization entries supplied as input to the simulation (typically empty — the simulation discovers them).
forceMethodOptional submission-method override.
resolveContextRuleIdsOptional context-rule resolver override.
Return Value
OZTransactionResultdescribing the on-chain outcome. -
fundWallet(nativeTokenContract:AsynchronousforceMethod: ) Funds the connected smart account wallet using Friendbot (testnet only).
Generates a fresh temporary keypair, funds it via Friendbot, queries its XLM balance via the native token contract, and transfers the surplus (balance minus the protocol minimum-balance reserve) to the smart account contract. Source-account authorization entries from the transfer simulation are converted to classical Ed25519
Addresscredentials so the relayer can substitute its own channel accounts for fee sponsoring.The conversion uses the classical Stellar Ed25519 signature shape (
Vec([Map({public_key, signature})])), NOT the OpenZeppelin AuthPayload Map written by the smart-account signing path — the temp keypair is a classical Stellar account, not a smart account.Declaration
Swift
public func fundWallet( nativeTokenContract: String, forceMethod: OZSubmissionMethod? = nil ) async throws -> StringParameters
nativeTokenContractNative token contract address (
C…strkey).forceMethodOptional submission-method override.
Return Value
Funded amount as a decimal XLM string (for example
"100"or"12.34567"). Trailing zeroes in the fractional component are trimmed.
-
Converts a positive decimal amount string to its base-units representation scaled by
decimalsdecimal places.Rejects scientific notation, empty or non-numeric strings, values less than or equal to zero, and values carrying more fractional digits than
decimalsallows. Accepted shape:^[0-9]+(\.[0-9]+)?$with at mostdecimalsfractional digits and a result greater than zero.Declaration
Swift
public static func amountToBaseUnits(_ amount: String, decimals: Int) throws -> StringParameters
amountPositive decimal string (for example
"10"or"100.5").decimalsThe token’s decimal scale. Must be in
0...maxTokenDecimals. A value of0accepts only integer amounts and rejects any fractional digit.Return Value
The base-units amount as a non-negative decimal integer string with no leading zeros (except the single digit
"0").
View on GitHub
Install in Dash