You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* light touches and a python example for address conversions
Fixes#1858
* remove one unnecessary set of codeblock tags
* update the bytes conversion guide
Fixes#1859
* update the string conversions guide
Fixes#1867
* remove unused imports
* update scval conversions guide
Fixes#1866
* simplify scval conversions from base64 strings
Copy file name to clipboardExpand all lines: docs/build/guides/conversions/address-conversions.mdx
+25-26Lines changed: 25 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,11 +8,11 @@ import { CodeExample } from "@site/src/components/CodeExample";
8
8
9
9
The `Address` is an opaque type that represents either a 'default' externally owned account on the Stellar network, or a contract (that may also provide logic for custom externally owned accounts, see [authorization docs](../../../learn/fundamentals/contract-development/authorization.mdx#account-abstraction) for details). For the smart contracts it normally doesn't matter which kind of `Address` is used. However, in some contexts it's useful to convert `Address` to/from different data types, such as string or XDR. The conversions have distinctly different purpose depending on whether they happen in the smart contract itself, or in the client code.
10
10
11
-
# String conversions
11
+
##String conversions
12
12
13
13
The default string format for `Address` is a so called 'string key' (or 'strkey'), defined fully in [SEP-23](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0023.md). For the default externally owned accounts strkey always starts with `G` and for all the contracts it starts with `C`.
14
14
15
-
## Conversions in Client SDKs
15
+
### String Conversions in Client SDKs
16
16
17
17
Outside of the smart contracts, it is convenient to represent `Address` as string most of the time. It can be stored in string serialization formats such as JSON and XML. Storing addresses as strings in databases can simplify database schema design and queries. Strings are easier to manipulate and are more compatible with user interfaces and APIs. Thus
18
18
@@ -30,46 +30,49 @@ const address = new StellarSdk.Address(stellarAddress);
It's generally preferred for contracts to operate directly on the `Address` type. String conversions may be useful for specialized use cases, such as passing the Stellar `Address`es to/from other chains.
XDR is schema-based binary serialization format used by the Stellar network. It is used for all the Stellar blockchain interactions, such as building the transactions, storing data in the ledger, communicating the transaction results etc. Stellar SDKs provide the typed wrappers for all the Stellar XDR data types. Address is represented as `ScAddress` type, which can then be wrapped into `ScVal` which is a type that represents any contract type supported by Stellar contracts.
71
74
72
-
## Conversions in Client SDKs
75
+
### XDR Conversions in Client SDKs
73
76
74
77
On the client side XDR conversions are useful to build the transactions and process the transaction results.
Smart contracts don't need to explicitly interact with the XDR types, as all the smart contract data types are automatically converted to XDR by the smart contract runtime. Every contract type, including `Address`, can be serialized to XDR bytes. This conversion is useful, for example, for performing hashing in smart contracts. It is also possible to convert the serialized XDR bytes back to contract types, which can be useful in some narrow use cases, such as custom authentication schemes.
108
111
109
-
Note, that XDR conversions are and advanced feature and are not necessary for most of the Stellar smart contracts.
110
-
111
-
<CodeExample>
112
+
Note, that XDR conversions are an advanced feature and are not necessary for most Stellar smart contracts.
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.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.
0 commit comments