Skip to main content

Class: SorosanSDK

Hierarchy

  • Soroban

    SorosanSDK

Constructors

constructor

new SorosanSDK(selectedNetwork, activePublicKey?)

Parameters

NameType
selectedNetworkNetworkDetails
activePublicKey?string

Overrides

Soroban.constructor

Defined in

src/sdk/sorosan-sdk.ts:25

Properties

contract

contract: ContractSDK

Defined in

src/sdk/sorosan-sdk.ts:21


token

token: TokenSDK

Defined in

src/sdk/sorosan-sdk.ts:22


util

util: UtilSDK

Defined in

src/sdk/sorosan-sdk.ts:23

Accessors

setPublicKey

Protected set setPublicKey(publicKey): void

Parameters

NameType
publicKeystring

Returns

void

Inherited from

Soroban.setPublicKey

Defined in

src/sdk/soroban.ts:100

Methods

calculateEstimateGas

Protected calculateEstimateGas(contractAddress, method, args): Promise<string>

Helper function to estimate the gas cost of a contract call. This estimation is done by creating a transaction builder and simulating the transaction using the Soroban network. The gas cost is calculated as the sum of the base fee and the fee obtained from the simulated transaction.

Parameters

NameTypeDescription
contractAddressstringThe contract address to estimate gas for.
methodstringThe name of the method to be called on the contract.
argsScVal[]An array of ScVal arguments to pass to the method.

Returns

Promise<string>

A promise that resolves to a string representation of the estimated gas cost for the contract call.

Example

const gasEstimation = await sdk.estimateGas(
"CCV3ODCHRVCUQTWJZ7F7SLKHGT3JLYWUVHAWMKIYQVSCKMGSOCOJ3AUO",
"init",
[xdr.scVal.scvString("Hello World"), new Address("GB...").toScAddress(), ...]
);

const gasCostInStroops: number = parseInt(gasEstimation); // Convert to a number if needed.

Inherited from

Soroban.calculateEstimateGas

Defined in

src/sdk/soroban.ts:81


call

call(contractAddress, method, args?): Promise<any>

Calls a method on a Soroban contract. This method estimates gas, creates a transaction builder, prepares the transaction, and simulates it on the network.

Parameters

NameTypeDefault valueDescription
contractAddressstringundefined-
methodstringundefinedThe name of the method to call on the contract.
argsScVal[][]An array of ScVal arguments to pass to the method.

Returns

Promise<any>

A promise that resolves to the result of the contract call.

Example

const result = await sdk.call(
"GB...",
"init",
[xdr.scVal.scvString("Hello World"), new Address("GB...").toScAddress(), ...]
);

Defined in

src/sdk/sorosan-sdk.ts:49


connectWallet

connectWallet(): Promise<boolean>

Connects to the Soroban via Freighter.

Returns

Promise<boolean>

A promise that resolves to true if the connection to Soroban via Freighter is successful, otherwise false.

Defined in

src/sdk/sorosan-sdk.ts:160


estimateGas

estimateGas(contractAddress, method, args): Promise<string>

Helper function to estimate the gas cost of a contract call. This estimation is done by creating a transaction builder and simulating the transaction using the Soroban network. The gas cost is calculated as the sum of the base fee and the fee obtained from the simulated transaction.

Parameters

NameTypeDescription
contractAddressstringThe contract address to estimate gas for.
methodstringThe name of the method to be called on the contract.
argsScVal[]An array of ScVal arguments to pass to the method.

Returns

Promise<string>

A promise that resolves to a string representation of the estimated gas cost for the contract call.

Example

const gasEstimation = await sdk.estimateGas(
"CCV3ODCHRVCUQTWJZ7F7SLKHGT3JLYWUVHAWMKIYQVSCKMGSOCOJ3AUO",
"init",
[xdr.scVal.scvString("Hello World"), new Address("GB...").toScAddress(), ...]
);

const gasCostInStroops: number = parseInt(gasEstimation); // Convert to a number if needed.

Defined in

src/sdk/sorosan-sdk.ts:197


login

login(): Promise<boolean>

Used to connect to the Soroban via Freighter. This method checks if the user has Freighter installed and is logged in.

Returns

Promise<boolean>

A promise that resolves to true if the user has Freighter installed and is logged in, otherwise false.

Example

const hasFreighter = await sdk.login();
if (!hasFreighter) {
throw new Error("Freighter not installed or not logged in");
}

Defined in

src/sdk/sorosan-sdk.ts:134


nativeToScVal

nativeToScVal(arg, type?): ScVal

Convert native value to ScValue. Currently supported types are: string, number, boolean, object, address, bytes, symbol, i64, i128, i256, u64, u128, u256

Parameters

NameType
argany
type?string

Returns

ScVal

Example

const addr: xdr.scVal = sdk.nativeToScVal("GBT57WS2EQU3ECJGH6LGU6I5ZOTBDCTEV2YD7L2ZJAD6U7MNMQPHIBGW", "address"),
const hundred: xdr.scVal = sdk.nativeToScVal(100, "i128"),

Defined in

src/sdk/sorosan-sdk.ts:241


nativesToScVal

nativesToScVal(args): ScVal[]

Batch convert of list of native typescript types to Soroban data types. Note this doesn't support custom types. You have to manually convert them.

Parameters

NameType
argsCustomScVal[]

Returns

ScVal[]

Example


Defined in

src/sdk/sorosan-sdk.ts:222


send

send(contractAddress, method, args?): Promise<GetTransactionResponse>

Generic call method for a Soroban contract. This method estimates gas, creates a transaction builder, prepares the transaction, and submits the transaction to the network via Freighter signing.

Parameters

NameTypeDescription
contractAddressstring-
methodstringThe name of the method to call on the contract.
args?ScVal[]An array of ScVal arguments to pass to the method.

Returns

Promise<GetTransactionResponse>

A promise that resolves to true if the transaction of the contract call was successful, otherwise false.

this is currently a boolean to determine if the transaction of the contract call was successful.

Example

const result = await sdk.send(
"GB...",
"init",
[xdr.scVal.scvString("Hello World"), new Address("GB...").toScAddress(), ...]
);

Defined in

src/sdk/sorosan-sdk.ts:88


structToScVal

structToScVal(struct): ScVal

Converts a Rust type struct into an xdr.ScVal on Soroban type.

This function takes a xdr.ScSpecUdtStructV0 object representing a Rust type struct and converts it into an xdr.ScVal object on the Soroban type system. It handles both unnamed and named structs and returns the corresponding xdr.ScVal representation based on the struct's field names.

Parameters

NameTypeDescription
structScSpecUdtStructV0The xdr.ScSpecUdtStructV0 object to convert into an xdr.ScVal.

Returns

ScVal

The converted xdr.ScVal representing the Rust struct on Soroban type.

Example

// Get Rust information...
const specs = await sdk.contract.decompileContract("CDUL5OW2XI7JJQL7VGWD6Y34SXAV3ZDCSW55SUYRFGHWXVK25E7S7FXJ")
const types = specs.filter(x => x.switch() === xdr.ScSpecEntryKind.scSpecEntryUdtStructV0());

// Convert the Rust struct to an xdr.ScVal
types.forEach((type) => {
const struct = structToScVal(myStruct as as xdr.scSpecEntryUdtStructV0)
console.log(struct);
});

Defined in

src/sdk/sorosan-sdk.ts:266


transactionBuilder

transactionBuilder(publicKey?, fee?): Promise<SorosanTransactionBuilder>

This value is an extension of TransactionBuilder and is used to create and prepare transactions It contains more methods than the TransactionBuilder and is used to interact with the Soroban network.

Parameters

NameType
publicKey?string
fee?string

Returns

Promise<SorosanTransactionBuilder>

Defined in

src/sdk/sorosan-sdk.ts:210