Skip to main content

Class: UtilSDK

Constructors

constructor

new UtilSDK()

Methods

addressScVal

addressScVal(address): ScVal

Converts a string address to a Soroban ScVal type Address.

Parameters

NameTypeDescription
addressstringThe string address to convert to a ScVal.

Returns

ScVal

Soroban ScVal representing the address.

Example

const str = "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN";
const address: xdr.ScVal = sdk.util.addressScVal(str);
console.log(address);

Defined in

src/sdk/util-sdk.ts:27


isAddress

isAddress(val): boolean

Checks if a string is a valid Soroban address.

Parameters

NameType
valstring

Returns

boolean

true if the string is a valid 56-character alphanumeric Soroban address, otherwise false.

Example

const str = "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN";
const isAddress: boolean = sdk.util.isAddress(str);
console.log(isAddress); // true

Example

const str = "CCV3ODCHRVCUQTWJZ7F7SLKHGT3JLYWUVHAWMKIYQVSCKMGSOCOJ3AUO";
const isAddress: boolean = sdk.util.isAddress(str);
console.log(isAddress); // false

Defined in

src/sdk/util-sdk.ts:101


isContractAddress

isContractAddress(val): boolean

Checks if a string is a valid Soroban contract address.

Parameters

NameTypeDescription
valstringThe string to check for Soroban contract address validity.

Returns

boolean

true if the string is a valid Soroban contract address, otherwise false.

Example

const str = "CCV3ODCHRVCUQTWJZ7F7SLKHGT3JLYWUVHAWMKIYQVSCKMGSOCOJ3AUO";
const isContractAddress: boolean = sdk.util.isContractAddress(str);
console.log(isContractAddress); // true

Example

const str = "CCV3ODCHRVCUQTWJZ7F7SL";
const isContractAddress: boolean = sdk.util.isContractAddress(str);
console.log(isContractAddress); // false

Defined in

src/sdk/util-sdk.ts:122


isSorobanTransaction

isSorobanTransaction(tx): boolean

Checks if a transaction is a Soroban transaction.

This method determines whether the provided transaction is a Soroban transaction by checking its operations.

Parameters

NameTypeDescription
txTransaction<Memo<MemoType>, Operation[]>The transaction to check.

Returns

boolean

  • A boolean indicating whether the transaction is a Soroban transaction.

Example

// Example usage:
const transaction: Transaction;
const isSorobanTx = sdk.util.isSorobanTransaction(transaction);
console.log('Is Soroban transaction:', isSorobanTx);

Defined in

src/sdk/util-sdk.ts:140


mask

mask(str): string

Shortens an address or hash to a fixed length for display.

Parameters

NameTypeDescription
strstringThe address or hash to shorten.

Returns

string

The shortened string if its length is greater than 10 characters; otherwise, the original string.

Example

const str = "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN";
const short: string = sdk.util.mask(str);
console.log(short); // GA5Z...K4KZVN

Example

const str = "ABC";
const short: string = sdk.util.mask(str);
console.log(short); // ABC

Defined in

src/sdk/util-sdk.ts:80


toContractAddress

toContractAddress(id): string

Converts a contract hash to its contract address.

Parameters

NameTypeDescription
idstringThe contract hash to convert to its contract address.

Returns

string

The contract address as a string.

Example

const str = "c13dfd0485a7a572bad3e54676cf99d6257535d38e5f251086e5b5c8b01f4b23";
const hash: string = sdk.util.contractHash(str);
console.log(hash); // CDAT37IEQWT2K4V22PSUM5WPTHLCK5JV2OHF6JIQQ3S3LSFQD5FSGYN6

Defined in

src/sdk/util-sdk.ts:59


toContractHash

toContractHash(hash): string

Converts a contract address to its contract hash.

Parameters

NameTypeDescription
hashstringThe contract address to convert to its contract hash.

Returns

string

The contract hash as a string.

Example

const str = "CDAT37IEQWT2K4V22PSUM5WPTHLCK5JV2OHF6JIQQ3S3LSFQD5FSGYN6";
const id: string = sdk.util.contractAddress(str);
console.log(id); // c13dfd0485a7a572bad3e54676cf99d6257535d38e5f251086e5b5c8b01f4b23

Defined in

src/sdk/util-sdk.ts:43


toStroop

toStroop(amount): BigNumber

Converts XLM (Lumen) to stroops (1 XLM = 10^7 stroops).

Parameters

NameTypeDescription
amountnumberThe amount of XLM to convert.

Returns

BigNumber

The equivalent amount in stroops as a BigNumber.

Example

const xlmAmount = 5.0; // Replace with the actual amount of XLM to convert.
const stroops = sdk.toStroop(xlmAmount);
console.log(`Equivalent in Stroops: ${stroops.toString()}`);

Defined in

src/sdk/util-sdk.ts:154


toXLM

toXLM(amount): BigNumber

Converts stroops to XLM (Lumen) (1 XLM = 10^7 stroops).

Parameters

NameTypeDescription
amountnumberThe amount in stroops to convert.

Returns

BigNumber

The equivalent amount in XLM as a BigNumber.

Example

const stroopsAmount = 50000000; // Replace with the actual amount in stroops to convert.
const xlm = sdk.toXLM(stroopsAmount);
console.log(`Equivalent in XLM: ${xlm.toString()}`);

Defined in

src/sdk/util-sdk.ts:168