| title | Core / Soroban Primitives |
|---|---|
| description | Soroban smart-contract primitives — Address, contract IDs, and ScVal conversion helpers. |
class Address {
constructor(address: string);
static account(buffer: Uint8Array): Address;
static claimableBalance(buffer: Uint8Array): Address;
static contract(buffer: Uint8Array): Address;
static fromScAddress(scAddress: ScAddress): Address;
static fromScVal(scVal: ScVal): Address;
static fromString(address: string): Address;
static liquidityPool(buffer: Uint8Array): Address;
static muxedAccount(buffer: Uint8Array): Address;
readonly type: AddressType;
toBuffer(): Uint8Array;
toScAddress(): ScAddress;
toScVal(): ScVal;
toString(): string;
}Source: src/base/address.ts:32
constructor(address: string);Parameters
address—string(required) — aStrKeyof the address value
Source: src/base/address.ts:39
Creates a new account Address object from raw bytes.
static account(buffer: Uint8Array): Address;Parameters
buffer—Uint8Array(required) — The bytes of an address to parse.
Source: src/base/address.ts:74
Creates a new claimable balance Address object from raw bytes.
static claimableBalance(buffer: Uint8Array): Address;Parameters
buffer—Uint8Array(required) — The bytes of a claimable balance ID to parse.
Source: src/base/address.ts:92
Creates a new contract Address object from raw bytes.
static contract(buffer: Uint8Array): Address;Parameters
buffer—Uint8Array(required) — The bytes of an address to parse.
Source: src/base/address.ts:83
Convert this from an xdr.ScAddress type
static fromScAddress(scAddress: ScAddress): Address;Parameters
scAddress—ScAddress(required) — The xdr.ScAddress type to parse
Source: src/base/address.ts:131
Convert this from an xdr.ScVal type.
static fromScVal(scVal: ScVal): Address;Parameters
scVal—ScVal(required) — The xdr.ScVal type to parse
Source: src/base/address.ts:119
Parses a string and returns an Address object.
static fromString(address: string): Address;Parameters
address—string(required) — The address to parse. ex.GB3KJPLFUYN5VL6R3GU3EGCGVCKFDSD7BEDX42HWG5BWFKB3KQGJJRMA
Source: src/base/address.ts:65
Creates a new liquidity pool Address object from raw bytes.
static liquidityPool(buffer: Uint8Array): Address;Parameters
buffer—Uint8Array(required) — The bytes of an LP ID to parse.
Source: src/base/address.ts:101
Creates a new muxed account Address object from raw bytes.
static muxedAccount(buffer: Uint8Array): Address;Parameters
buffer—Uint8Array(required) — The bytes of an address to parse.
Source: src/base/address.ts:110
Return the type of this address.
readonly type: AddressType;Source: src/base/address.ts:232
Return the raw public key bytes for this address.
toBuffer(): Uint8Array;Source: src/base/address.ts:225
Convert this Address to an xdr.ScAddress type.
toScAddress(): ScAddress;Source: src/base/address.ts:193
Convert this Address to an xdr.ScVal type.
toScVal(): ScVal;Source: src/base/address.ts:186
Serialize an address to string.
toString(): string;Source: src/base/address.ts:166
Create a new Contract object.
Contract represents a single contract in the Stellar network, embodying the
interface of the contract. See
Contracts
for more information about how contracts work in Stellar.
class Contract {
constructor(contractId: string);
address(): Address;
call(method: string, ...params: ScVal[]): Operation;
contractId(): string;
getFootprint(): LedgerKey;
toString(): string;
}Source: src/base/contract.ts:20
constructor(contractId: string);Parameters
contractId—string(required) — ID of the contract (ex.CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE).
Source: src/base/contract.ts:27
Returns the wrapped address of this contract.
address(): Address;Source: src/base/contract.ts:50
Returns an operation that will invoke this contract call.
call(method: string, ...params: ScVal[]): Operation;Parameters
method—string(required) — name of the method to call...params—ScVal[](required) — arguments to pass to the method, as an array of xdr.ScVal
See also
-
- Operation.invokeHostFunction
- Operation.invokeContractFunction
- Operation.createCustomContract
- Operation.createStellarAssetContract
- Operation.uploadContractWasm
Source: src/base/contract.ts:66
Returns Stellar contract ID as a strkey, ex.
CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE.
contractId(): string;Source: src/base/contract.ts:40
Returns the read-only footprint entries necessary for any invocations to this contract, for convenience when manually adding it to your transaction's overall footprint or doing bump/restore operations.
getFootprint(): LedgerKey;Source: src/base/contract.ts:79
Returns the ID as a strkey (C...).
toString(): string;Source: src/base/contract.ts:45
Helper class to assist with formatting and parsing token amounts.
class Soroban {
constructor();
static formatTokenAmount(amount: string, decimals: number): string;
static parseTokenAmount(value: string, decimals: number): string;
}Source: src/base/soroban.ts:2
constructor();Given a whole number smart contract amount of a token and an amount of decimal places (if the token has any), it returns a "display" value.
All arithmetic inside the contract is performed on integers to avoid potential precision and consistency issues of floating-point.
static formatTokenAmount(amount: string, decimals: number): string;Parameters
amount—string(required) — the token amount you want to displaydecimals—number(required) — specify how many decimal places a token has
Throws
- if the given amount has a decimal point already
Example
formatTokenAmount("123000", 4) === "12.3";
formatTokenAmount("123000", 3) === "123.0";
formatTokenAmount("123", 3) === "0.123";Source: src/base/soroban.ts:19
Parse a token amount to use it on smart contract
This function takes the display value and its decimals (if the token has any) and returns a string that'll be used within the smart contract.
Returns the whole number token amount represented by the display value with the decimal places shifted over.
static parseTokenAmount(value: string, decimals: number): string;Parameters
value—string(required) — the token amount you want to use on a smart contract which you've been displaying in a UIdecimals—number(required) — the number of decimal places expected in the display value (different than the "actual" number, because suffix zeroes might not be present)
Example
const displayValueAmount = "123.4560"
const parsedAmtForSmartContract = parseTokenAmount(displayValueAmount, 5);
parsedAmtForSmartContract === "12345600"Source: src/base/soroban.ts:73
Supports building xdr.SorobanTransactionData structures with various
items set to specific values.
This is recommended for when you are building
Operation.extendFootprintTtl / Operation.restoreFootprint
operations and need to TransactionBuilder.setSorobanData to avoid
(re)building the entire data structure from scratch.
class SorobanDataBuilder {
constructor(sorobanData?: string | Uint8Array<ArrayBufferLike> | SorobanTransactionData);
static fromXdr(data: string | Uint8Array<ArrayBufferLike>): SorobanTransactionData;
appendFootprint(readOnly: LedgerKey[], readWrite: LedgerKey[]): SorobanDataBuilder;
build(): SorobanTransactionData;
getFootprint(): LedgerFootprint;
getReadOnly(): LedgerKey[];
getReadWrite(): LedgerKey[];
setFootprint(readOnly?: LedgerKey[] | null, readWrite?: LedgerKey[] | null): SorobanDataBuilder;
setReadOnly(readOnly?: LedgerKey[]): SorobanDataBuilder;
setReadWrite(readWrite?: LedgerKey[]): SorobanDataBuilder;
setResourceFee(fee: IntLike): SorobanDataBuilder;
setResources(cpuInstrs: number, diskReadBytes: number, writeBytes: number): SorobanDataBuilder;
}Example
// You want to use an existing data blob but override specific parts.
const newData = new SorobanDataBuilder(existing)
.setReadOnly(someLedgerKeys)
.setResourceFee("1000")
.build();
// You want an instance from scratch
const newData = new SorobanDataBuilder()
.setFootprint([someLedgerKey], [])
.setResourceFee("1000")
.build();Source: src/base/sorobandata_builder.ts:34
constructor(sorobanData?: string | Uint8Array<ArrayBufferLike> | SorobanTransactionData);Parameters
sorobanData—string | Uint8Array<ArrayBufferLike> | SorobanTransactionData(optional) — either a base64-encoded string that represents anxdr.SorobanTransactionDatainstance or an XDR instance itself (it will be copied); if omitted or "falsy" (e.g. an empty string), it starts with an empty instance
Source: src/base/sorobandata_builder.ts:43
Decodes and builds a xdr.SorobanTransactionData instance.
static fromXdr(data: string | Uint8Array<ArrayBufferLike>): SorobanTransactionData;Parameters
data—string | Uint8Array<ArrayBufferLike>(required) — raw input to decode
Source: src/base/sorobandata_builder.ts:74
Appends the given ledger keys to the existing storage access footprint.
appendFootprint(readOnly: LedgerKey[], readWrite: LedgerKey[]): SorobanDataBuilder;Parameters
readOnly—LedgerKey[](required) — read-only keys to addreadWrite—LedgerKey[](required) — read-write keys to add
Source: src/base/sorobandata_builder.ts:137
Returns a copy of the final data structure.
build(): SorobanTransactionData;Source: src/base/sorobandata_builder.ts:218
Returns the storage access pattern.
getFootprint(): LedgerFootprint;Source: src/base/sorobandata_builder.ts:237
Returns the read-only storage access pattern.
getReadOnly(): LedgerKey[];Source: src/base/sorobandata_builder.ts:227
Returns the read-write storage access pattern.
getReadWrite(): LedgerKey[];Source: src/base/sorobandata_builder.ts:232
Sets the storage access footprint to be a certain set of ledger keys.
You can also set each field explicitly via
SorobanDataBuilder.setReadOnly and
SorobanDataBuilder.setReadWrite or add to the existing footprint
via SorobanDataBuilder.appendFootprint.
Passing null|undefined to either parameter will IGNORE the existing
values. If you want to clear them, pass [], instead.
setFootprint(readOnly?: LedgerKey[] | null, readWrite?: LedgerKey[] | null): SorobanDataBuilder;Parameters
readOnly—LedgerKey[] | null(optional) — the set of ledger keys to set in the read-only portion of the transaction'ssorobanData, ornull | undefinedto keep the existing keysreadWrite—LedgerKey[] | null(optional) — the set of ledger keys to set in the read-write portion of the transaction'ssorobanData, ornull | undefinedto keep the existing keys
Source: src/base/sorobandata_builder.ts:161
Sets the read-only keys in the access footprint.
setReadOnly(readOnly?: LedgerKey[]): SorobanDataBuilder;Parameters
readOnly—LedgerKey[](optional) — read-only keys in the access footprint
Source: src/base/sorobandata_builder.ts:180
Sets the read-write keys in the access footprint.
setReadWrite(readWrite?: LedgerKey[]): SorobanDataBuilder;Parameters
readWrite—LedgerKey[](optional) — read-write keys in the access footprint
Source: src/base/sorobandata_builder.ts:200
Sets the resource fee portion of the Soroban data.
setResourceFee(fee: IntLike): SorobanDataBuilder;Parameters
fee—IntLike(required) — the resource fee to set (int64)
Source: src/base/sorobandata_builder.ts:95
Sets up the resource metrics.
You should almost NEVER need this, as its often generated / provided to you by transaction simulation/preflight from a Soroban RPC server.
setResources(cpuInstrs: number, diskReadBytes: number, writeBytes: number): SorobanDataBuilder;Parameters
cpuInstrs—number(required) — number of CPU instructionsdiskReadBytes—number(required) — number of bytes being read from diskwriteBytes—number(required) — number of bytes being written to disk/memory
Source: src/base/sorobandata_builder.ts:114
Actually authorizes an existing authorization entry using the given credentials and expiration details, returning a signed copy.
This "fills out" the authorization entry with a signature, indicating to the
Operation.invokeHostFunction its attached to that:
- a particular identity (i.e. signing
Keypairor other signer) - approving the execution of an invocation tree (i.e. a simulation-acquired
xdr.SorobanAuthorizedInvocationor otherwise built) - on a particular network (uniquely identified by its passphrase, see
Networks) - until a particular ledger sequence is reached.
This one lets you pass either a Keypair (or, more accurately,
anything with a sign(Uint8Array): Uint8Array method) or a callback function (see
SigningCallback) to handle signing the envelope hash.
authorizeEntry(entry: SorobanAuthorizationEntry, signer: Keypair | SigningCallback, validUntilLedgerSeq: number, networkPassphrase: string, forAddress?: string): Promise<SorobanAuthorizationEntry>Parameters
-
entry—SorobanAuthorizationEntry(required) — an unsigned authorization entry -
signer—Keypair | SigningCallback(required) — either aKeypairinstance or a function which takes axdr.HashIdPreimageSorobanAuthorizationinput payload and returns EITHER(a) an object containing a `signature` of the hash of the raw payload bytes as a `Uint8Array` and a `publicKey` string representing who just created this signature, or (b) just the naked signature of the hash of the raw payload bytes (where the signing key is implied to be the address in the `entry`).The latter option (b) is JUST for backwards compatibility and will be removed in the future.
-
validUntilLedgerSeq—number(required) — the (exclusive) future ledger sequence number until which this authorization entry should be valid (ifcurrentLedgerSeq==validUntil, this is expired) -
networkPassphrase—string(required) — the network passphrase is incorporated into the signature (seeNetworksfor options)If using the
SigningCallbackvariation, the signer is assumed to be the entry's credential address unless you use the variant that returns the object. -
forAddress—string(optional) — which credential node the signature should be written to. Only relevant forSOROBAN_CREDENTIALS_ADDRESS_WITH_DELEGATES, where a single entry can be signed by the top-level account and/or any of its (possibly nested) delegates. Per CAP-71-01 every one of these signers signs the same payload (bound to the top-level address), so the signature produced here is written to whichever node(s) carryforAddress. When omitted, the signature is written to the top-level credentials, which preserves the behavior forSOROBAN_CREDENTIALS_ADDRESS/SOROBAN_CREDENTIALS_ADDRESS_V2and for accounts whose signing key differs from the credential address (e.g. multisig).
Example
import {
SorobanRpc,
Transaction,
Networks,
authorizeEntry
} from '@stellar/stellar-sdk';
// Assume signPayloadCallback is a well-formed signing callback.
//
// It might, for example, pop up a modal from a browser extension, send the
// transaction to a third-party service for signing, or just do simple
// signing via Keypair like it does here:
function signPayloadCallback(payload) {
return signer.sign(hash(payload.toXdr()));
}
function multiPartyAuth(
server: SorobanRpc.Server,
// assume this involves multi-party auth
tx: Transaction,
) {
return server
.simulateTransaction(tx)
.then((simResult) => {
tx.operations[0].auth.map(entry =>
authorizeEntry(
entry,
signPayloadCallback,
currentLedger + 1000,
Networks.TESTNET)
);
return server.prepareTransaction(tx, simResult);
})
.then((preppedTx) => {
preppedTx.sign(source);
return server.sendTransaction(preppedTx);
});
}See also
- authorizeInvocation
Source: src/base/auth.ts:138
authorizeInvocation(params: AuthorizeInvocationParams): Promise<SorobanAuthorizationEntry>Parameters
params—AuthorizeInvocationParams(required)
Source: src/base/auth.ts:298
Builds the xdr.HashIdPreimage whose hash a signer must sign to
authorize entry. This is the low-level signature payload used by
authorizeEntry, exposed for callers that drive signing themselves —
most notably for SOROBAN_CREDENTIALS_ADDRESS_WITH_DELEGATES, where the
client (not simulation) decides which delegates sign and how.
For SOROBAN_CREDENTIALS_ADDRESS this is the legacy, non-address-bound
ENVELOPE_TYPE_SOROBAN_AUTHORIZATION preimage. For SOROBAN_CREDENTIALS_ADDRESS_V2
and SOROBAN_CREDENTIALS_ADDRESS_WITH_DELEGATES it is the address-bound
ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_ADDRESS preimage (CAP-71). For the
delegates variant this single payload — bound to the top-level address — is
what the top-level account and every (nested) delegate each sign.
To get the raw bytes to sign, hash the XDR: hash(preimage.toXdr()).
buildAuthorizationEntryPreimage(entry: SorobanAuthorizationEntry, validUntilLedgerSeq: number, networkPassphrase: string): HashIdPreimageParameters
entry—SorobanAuthorizationEntry(required) — the authorization entry to build the payload forvalidUntilLedgerSeq—number(required) — the expiration ledger committed into the payload (must match thesignatureExpirationLedgeron the credentials you submit)networkPassphrase—string(required) — the network passphrase mixed into the payload
Throws
Errorifentrycarries source-account or otherwise non-address credentials
Source: src/base/auth.ts:364
Turns a raw invocation tree into a human-readable format.
This is designed to make the invocation tree easier to understand in order to inform users about the side-effects of their contract calls. This will help make informed decisions about whether or not a particular invocation will result in what you expect it to.
buildInvocationTree(root: SorobanAuthorizedInvocation): InvocationTreeParameters
root—SorobanAuthorizedInvocation(required) — the raw XDR of the invocation, likely acquired from transaction simulation. this is either from theOperation.invokeHostFunctionitself (thefuncfield), or from the authorization entries (xdr.SorobanAuthorizationEntry, therootInvocationfield)
Example
Here, we show a browser modal after simulating an arbitrary transaction,
tx, which we assume has an Operation.invokeHostFunction inside of it:
import { Server, buildInvocationTree } from '@stellar/stellar-sdk';
const s = new Server("fill in accordingly");
s.simulateTransaction(tx).then(
(resp: SorobanRpc.SimulateTransactionResponse) => {
if (SorobanRpc.isSuccessfulSim(resp) && resp.result) {
// bold assumption: there's a valid result with an auth entry
const auth = resp.result.auth;
if (auth && auth.length > 0) {
alert(
"You are authorizing the following invocation:\n" +
JSON.stringify(
buildInvocationTree(auth[0].rootInvocation()),
null,
2
)
);
}
}
}
);Source: src/base/invocation.ts:151
Builds a SOROBAN_CREDENTIALS_ADDRESS_WITH_DELEGATES authorization entry by
wrapping the address credentials of an existing ADDRESS/ADDRESS_V2 entry
(e.g. one returned by simulation) together with a caller-provided set of
delegate signers.
Simulation never emits the delegates variant on its own — which accounts use
delegated authentication is account-specific policy known only to the client
(much like a multisig policy). This helper just assembles the wrapper XDR;
you supply the delegate tree (addresses and, optionally, signatures). To
produce the signatures, build the shared payload with
buildAuthorizationEntryPreimage on the returned entry and sign it,
or fill each node afterwards with authorizeEntry (passing the
signer's address as forAddress).
Each delegates array (the top-level set and every nestedDelegates) is
sorted by address in ascending order, and duplicate addresses within an array
are rejected, as the protocol requires (CAP-71-01) — otherwise the host
rejects the entry.
buildWithDelegatesEntry(params: BuildWithDelegatesParams): SorobanAuthorizationEntryParameters
params—BuildWithDelegatesParams(required) — seeBuildWithDelegatesParams
Throws
Errorifentryis not anADDRESS/ADDRESS_V2entry, or if any delegates array contains a duplicate address.
Source: src/base/auth.ts:471
Converts raw diagnostic or contract events into something with a flatter, human-readable, and understandable structure.
Each element in the returned list has the following properties:
type: one of'system','contract','diagnostic'contractId: optionally, aC...encoded strkeytopics: a list ofscValToNativeinvocations on the topicsdata: ascValToNativeinvocation on the raw event data
humanizeEvents(events: ContractEvent[] | DiagnosticEvent[]): SorobanEvent[]Parameters
events—ContractEvent[] | DiagnosticEvent[](required) — either contract events or diagnostic events to parse into a friendly format
Source: src/base/events.ts:44
Attempts to convert native types into smart contract values
(xdr.ScVal).
Provides conversions from smart contract XDR values (xdr.ScVal) to
native JavaScript types.
The conversions are as follows:
-
xdr.ScVal -> passthrough
-
null/undefined -> scvVoid
-
string -> scvString (a copy is made)
-
UintArray8 -> scvBytes (a copy is made)
-
boolean -> scvBool
-
number/bigint -> the smallest possible XDR integer type that will fit the input value (if you want a specific type, use
ScInt) -
AddressorContract-> scvAddress (for contracts and public keys) -
Array -> scvVec after attempting to convert each item of type
Tto an xdr.ScVal (recursively). note that all values must be the same type! -
object -> scvMap after attempting to convert each key and value to an xdr.ScVal (recursively). note that there is no restriction on types matching anywhere (unlike arrays)
When passing an integer-like native value, you can also optionally specify a type which will force a particular interpretation of that value.
Note that not all type specifications are compatible with all ScVals, e.g.
toScVal("a string", {type: "i256"}) will throw.
nativeToScVal(val: unknown, opts: NativeToScValOpts = {}): ScValParameters
val—unknown(required) — a native (or convertible) input value to wrapopts—NativeToScValOpts(optional) (default:{}) — an optional set of hints around the type of conversion you'd like to see
Throws
- if...
- there are arrays with more than one type in them
- there are values that do not have a sensible conversion (e.g. random XDR types, custom classes)
- the type of the input object (or some inner value of said object) cannot
be determined (via
typeof) - the type you specified (via
opts.type) is incompatible with the value you passed in (val), e.g.nativeToScVal("a string", { type: 'i128' }), though this does not apply for types that ignoreopts(e.g. addresses).
Example
nativeToScVal(1000); // gives ScValType === scvU64
nativeToScVal(1000n); // gives ScValType === scvU64
nativeToScVal(1n << 100n); // gives ScValType === scvU128
nativeToScVal(1000, { type: 'u32' }); // gives ScValType === scvU32
nativeToScVal(1000, { type: 'i125' }); // gives ScValType === scvI256
nativeToScVal("a string"); // gives ScValType === scvString
nativeToScVal("a string", { type: 'symbol' }); // gives scvSymbol
nativeToScVal(new Uint8Array(5)); // scvBytes
nativeToScVal(new Uint8Array(5), { type: 'symbol' }); // scvSymbol
nativeToScVal(null); // scvVoid
nativeToScVal(true); // scvBool
nativeToScVal([1, 2, 3]); // gives scvVec with each element as scvU64
nativeToScVal([1, 2, 3], { type: 'i128' }); // scvVec<scvI128>
nativeToScVal([1, '2'], { type: ['i128', 'symbol'] }); // scvVec with diff types
nativeToScVal([1, '2', 3], { type: ['i128', 'symbol'] });
// scvVec with diff types, using the default when omitted
nativeToScVal({ 'hello': 1, 'world': [ true, false ] }, {
type: {
'hello': [ 'symbol', 'i128' ],
}
})
// gives scvMap with entries: [
// [ scvSymbol, scvI128 ],
// [ scvString, scvArray<scvBool> ]
// ]Example
import {
nativeToScVal,
scValToNative,
ScInt,
xdr
} from '@stellar/stellar-base';
let gigaMap = {
bool: true,
void: null,
u32: xdr.ScVal.scvU32(1),
i32: xdr.ScVal.scvI32(1),
u64: 1n,
i64: -1n,
u128: new ScInt(1).toU128(),
i128: new ScInt(1).toI128(),
u256: new ScInt(1).toU256(),
i256: new ScInt(1).toI256(),
map: {
arbitrary: 1n,
nested: 'values',
etc: false
},
vec: ['same', 'type', 'list'],
vec: ['diff', 1, 'type', 2, 'list'],
};
// then, simply:
let scv = nativeToScVal(gigaMap); // scv.type === "scvMap"
// then...
someContract.call("method", scv);
// Similarly, the inverse should work:
scValToNative(scv) == gigaMap; // trueSee also
- scValToNative
Source: src/base/scval.ts:164
Given a smart contract value, attempt to convert it to a native type. Possible conversions include:
- void ->
null - u32, i32 ->
number - u64, i64, u128, i128, u256, i256, timepoint, duration ->
bigint - vec ->
Arrayof any of the above (via recursion) - map -> key-value object of any of the above (via recursion)
- bool ->
boolean - bytes ->
Uint8Array - symbol ->
string - string ->
stringIF the underlying buffer can be decoded as ascii/utf8,Uint8Arrayof the raw contents in any error case
If no viable conversion can be determined, this just "unwraps" the smart value to return its underlying XDR value.
scValToNative(scv: ScVal): anyParameters
scv—ScVal(required) — the input smart contract value
See also
- nativeToScVal
Source: src/base/scval.ts:378
Build a sorted ScVal map from unsorted entries, sorted by key.
scvSortedMap(items: ScMapEntry[]): ScValParameters
items—ScMapEntry[](required) — the unsorted map entries
Source: src/base/scval.ts:477
Executes a callback function on each node in the tree until stopped.
Nodes are walked in a depth-first order. Returning false from the callback
stops further depth exploration at that node, but it does not stop the walk
in a "global" view.
walkInvocationTree(root: SorobanAuthorizedInvocation, callback: InvocationWalker): voidParameters
root—SorobanAuthorizedInvocation(required) — the tree to explorecallback—InvocationWalker(required) — the callback to execute for each node
Source: src/base/invocation.ts:258
This builds an entry from scratch, allowing you to express authorization as a function of:
- a particular identity (i.e. signing
Keypairor other signer) - approving the execution of an invocation tree (i.e. a simulation-acquired
xdr.SorobanAuthorizedInvocationor otherwise built) - on a particular network (uniquely identified by its passphrase, see
Networks) - until a particular ledger sequence is reached.
This is in contrast to authorizeEntry, which signs an existing entry.
interface AuthorizeInvocationParams {
authV2?: boolean;
invocation: SorobanAuthorizedInvocation;
networkPassphrase: string;
publicKey?: string;
signer: Keypair | SigningCallback;
validUntilLedgerSeq: number;
}See also
- authorizeEntry
Source: src/base/auth.ts:281
Build SOROBAN_CREDENTIALS_ADDRESS_V2 (CAP-71) credentials instead of the
legacy SOROBAN_CREDENTIALS_ADDRESS. V2 credentials bind the address into
the signed payload but are only valid on networks that have activated
CAP-71, so leave this off until the activation vote passes for your target
network. The default flips to true once V2 becomes mandatory.
authV2?: boolean;Source: src/base/auth.ts:295
invocation: SorobanAuthorizedInvocation;Source: src/base/auth.ts:284
networkPassphrase: string;Source: src/base/auth.ts:285
publicKey?: string;Source: src/base/auth.ts:286
signer: Keypair | SigningCallback;Source: src/base/auth.ts:282
validUntilLedgerSeq: number;Source: src/base/auth.ts:283
Parameters for buildWithDelegatesEntry.
interface BuildWithDelegatesParams {
delegates: DelegateSignature[];
entry: SorobanAuthorizationEntry;
signature?: ScVal;
validUntilLedgerSeq: number;
}Source: src/base/auth.ts:429
the delegate signers to attach.
delegates: DelegateSignature[];Source: src/base/auth.ts:439
an existing SOROBAN_CREDENTIALS_ADDRESS or
SOROBAN_CREDENTIALS_ADDRESS_V2 entry — typically one returned by
simulation — whose address credentials should be wrapped.
entry: SorobanAuthorizationEntry;Source: src/base/auth.ts:435
the top-level account's signature. Defaults to scvVoid, which is valid
for accounts that authorize purely via delegated signers (CAP-71-01).
signature?: ScVal;Source: src/base/auth.ts:444
the expiration ledger sequence stored on the top-level credentials.
validUntilLedgerSeq: number;Source: src/base/auth.ts:437
Details about a contract creation invocation.
typeindicates if this creation was a custom contract ('wasm'), a wrapping of an existing Stellar asset ('sac'), or a reference to an external executable ('external', see CAP-85)assetis set whentype=='sac', containing the canonicalAssetbeing wrapped by this Stellar Asset Contractwasmis set whentype=='wasm', containing additional creation parametersexternalis set whentype=='external', containing the referenced executable and the creation parameters
interface CreateInvocation {
asset?: string;
external?: ExternalRefCreateDetails;
type: "wasm" | "sac" | "external";
wasm?: WasmCreateDetails;
}Source: src/base/invocation.ts:53
asset?: string;Source: src/base/invocation.ts:55
external?: ExternalRefCreateDetails;Source: src/base/invocation.ts:57
type: "wasm" | "sac" | "external";Source: src/base/invocation.ts:54
wasm?: WasmCreateDetails;Source: src/base/invocation.ts:56
A delegate signer to attach to a
SOROBAN_CREDENTIALS_ADDRESS_WITH_DELEGATES entry via
buildWithDelegatesEntry.
interface DelegateSignature {
address: string;
nestedDelegates?: DelegateSignature[];
signature?: ScVal;
}Source: src/base/auth.ts:415
the delegate's address (G… account or C… contract).
address: string;Source: src/base/auth.ts:417
signers this delegate in turn delegates to (recursive).
nestedDelegates?: DelegateSignature[];Source: src/base/auth.ts:425
the delegate's signature value. Defaults to a scvVoid placeholder, which
you can fill afterwards with authorizeEntry (passing this address
as forAddress) or by editing the entry directly.
signature?: ScVal;Source: src/base/auth.ts:423
Details about a contract function execution invocation.
sourceis the strkey of the contract (C...) being invokedfunctionis the name of the function being invokedargsare the natively-represented parameters to the function invocation (seescValToNativefor rules on how they're represented as JS types)
interface ExecuteInvocation {
args: any[];
function: string;
source: string;
}Source: src/base/invocation.ts:68
args: any[];Source: src/base/invocation.ts:72
function: string;Source: src/base/invocation.ts:70
source: string;Source: src/base/invocation.ts:69
Details about a contract creation from an external executable (CAP-85).
owneris the strkey of the account or contract that owns the external executable being referencedtagis the owner-scoped name of that executable. It is an unboundedSCString, so it is not always text: a lenient UTF-8 decode would render two distinct tags identically, and the tag is half of what identifies the code being deployed. Binary tags come back as raw bytes, matchingscValToNativeaddressis the strkey of the deployer andsaltits hex-encoded salt, which together derive the new contract's ID
interface ExternalRefCreateDetails {
address: string;
constructorArgs?: any[];
owner: string;
salt: string;
tag: string | Uint8Array<ArrayBufferLike>;
}Source: src/base/invocation.ts:32
address: string;Source: src/base/invocation.ts:35
constructorArgs?: any[];Source: src/base/invocation.ts:38
owner: string;Source: src/base/invocation.ts:33
salt: string;Source: src/base/invocation.ts:36
tag: string | Uint8Array<ArrayBufferLike>;Source: src/base/invocation.ts:34
type IntLike = bigint | number | stringSource: src/base/sorobandata_builder.ts:10
A node in the invocation tree.
typeis the type of invocation occurring, either contract creation or host function executionargsare the parameters to the invocation, depending on the typeinvocationsare any sub-invocations that may occur as a result of this invocation (i.e. a tree of call stacks)
interface InvocationTree {
args: CreateInvocation | ExecuteInvocation;
invocations: InvocationTree[];
type: "create" | "execute";
}Source: src/base/invocation.ts:84
args: CreateInvocation | ExecuteInvocation;Source: src/base/invocation.ts:86
invocations: InvocationTree[];Source: src/base/invocation.ts:87
type: "create" | "execute";Source: src/base/invocation.ts:85
A callback used when walking an invocation tree.
Returning exactly false is a hint to stop exploring deeper from this node;
other return values are ignored.
type InvocationWalker = (node: SorobanAuthorizedInvocation, depth: number, parent?: SorobanAuthorizedInvocation) => boolean | null | voidSource: src/base/invocation.ts:102
interface NativeToScValOpts {
type?: ScValType | ScValMapTypeSpec | ScValType | null[];
}Source: src/base/scval.ts:25
type?: ScValType | ScValMapTypeSpec | ScValType | null[];Source: src/base/scval.ts:26
A callback for signing an XDR structure representing all of the details necessary to authorize an invocation tree.
type SigningCallback = (preimage: HashIdPreimage) => Promise<Uint8Array | { publicKey: string; signature: Uint8Array }>Source: src/base/auth.ts:39
interface WasmCreateDetails {
address: string;
constructorArgs?: any[];
hash: string;
salt: string;
}Source: src/base/invocation.ts:11
address: string;Source: src/base/invocation.ts:13
constructorArgs?: any[];Source: src/base/invocation.ts:16
hash: string;Source: src/base/invocation.ts:12
salt: string;Source: src/base/invocation.ts:14