Skip to content

Commit b72faa2

Browse files
authored
feat(docs): add guide for detecting if address is a smart account (#1259)
1 parent a9c1a26 commit b72faa2

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

docs/smart-accounts/guides/typescript-viem/01-state-lookup.mdx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import YouTubeEmbed from "@site/src/components/YouTubeEmbed";
2323
In this guide, you will learn how to get the following using the Viem TypeScript library:
2424

2525
- the Flare address that corresponds to an XRPL account
26+
- whether a Flare address is a smart account
2627
- the total value of FXRP that belongs to a personal account tied to an XRPL address
2728
- a list of all the registered vaults
2829
- the total value of FXRP of a personal account, in each of the registered vaults
@@ -131,6 +132,33 @@ export async function getContractAddressByName(name: string) {
131132
}
132133
```
133134
135+
## Checking if a Flare address is a smart account
136+
137+
A Flare address is a smart account (PersonalAccount) if calling the `xrplOwner()` function on it returns an XRPL account using the [`IPersonalAccount`](/smart-accounts/reference/IPersonalAccount) interface.
138+
The `PersonalAccount` contract exposes the `xrplOwner()` function the XRPL address that controls it.
139+
If the call succeeds and returns a non-empty and valid XRPL address, the address is a smart account.
140+
141+
```typescript
142+
export async function getXrplAccountForAddress(
143+
evmAddress: Address,
144+
): Promise<`0x${string}`> {
145+
const xrplOwner = await publicClient.readContract({
146+
address: evmAddress,
147+
abi: coston2.iPersonalAccountAbi,
148+
functionName: "xrplOwner",
149+
args: [],
150+
});
151+
return xrplOwner && xrplOwner.length > 0
152+
? evmAddress
153+
: "0x0000000000000000000000000000000000000000";
154+
}
155+
156+
export async function isSmartAccount(evmAddress: Address): Promise<boolean> {
157+
const smartAccountAddress = await getXrplAccountForAddress(evmAddress);
158+
return smartAccountAddress !== "0x0000000000000000000000000000000000000000";
159+
}
160+
```
161+
134162
## Personal account of an XRPL address
135163
136164
There are many situations when it is important or even necessary to know the address of the `PersonalAccount` of an XRPL address;

docs/smart-accounts/reference/IPersonalAccount.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ Returns the XRPL owner address associated with this personal account.
2121
function xrplOwner() external view returns (string memory);
2222
```
2323

24+
:::tip Smart account detection
25+
If a contract at a given Flare address returns an XRPL account when the `xrplOwner()` function is called, then it is a smart account.
26+
Use this to [detect whether an arbitrary Flare address is a smart account](/smart-accounts/guides/typescript-viem/state-lookup-ts#checking-if-a-flare-address-is-a-smart-account).
27+
:::
28+
2429
### `controllerAddress`
2530

2631
Returns the `MasterAccountController` address that manages this personal account.

0 commit comments

Comments
 (0)