Convert a ScVal to other type
Soroban Contract Value (ScVal
) is a custom type defined within the Soroban runtime environment that represents other data types such as strings, bytes, and more complex structures used within smart contracts in a format that that the soroban runtime can process, store and retrieve efficiently.
ScVal to bytesN
- JS
- Python
const StellarSdk = require("@stellar/stellar-sdk");
/* Convert ScVal to bytes */
const bytesFromScVal = StellarSdk.scVal.bytes();
.bytes()
converts an ScVal value to bytes.scVal
is the ScVal value to be converted to bytes.
import stellar_sdk
# Convert ScVal to bytes
sc_val_to_bytes = stellar_sdk.scval.from_bytes(sc_val)
stellar_sdk.scval.from_bytes()
converts an ScVal value to bytes.sc_val
is the ScVal value to be converted to bytes.
ScVal to address
- JS
- Python
const StellarSdk = require("@stellar/stellar-sdk");
const addressFromScVal = StellarSdk.Address.fromScVal(scVal);
addressFromScVal.toString();
StellarSdk.Address.fromScVal()
converts an ScVal value to an address.scVal
is the ScVal value to be converted to an address.
import stellar_sdk
sc_to_address = Address.from_xdr_sc_address(sc_val)
stellar_sdk.scval.from_xdr_sc_addres9()
converts an ScVal value to an address.sc_val
represents the ScVal value to be converted to an address.
ScVal to String
- JS
- Python
const StellarSdk = require("@stellar/stellar-sdk");
const stringFromScVal = scVal.toString("utf-8");
scVal.toString()
converts an ScVal value to a string. scVal
is the ScVal value to be converted to a string. utf-8
is the encoding format for the string.
import stellar_sdk
# scval to string
sc_val_to_string = stellar_sdk.scval.from_string(sc_val)
stellar_sdk.scval.from_string()
converts an ScVal value to a string.sc_val
represents the ScVal value to be converted to a string.