Skip to content

How do I check that a string is a valid account address? #28

Answered by banool
banool asked this question in Questions
Discussion options

You must be logged in to vote

You can do that with the TS SDK like this:

import { AccountAddress } from "../../src";

function myFunction {
    let addr = "0x1";
 
    // Get an actual AccountAddress object.
    let accountAddress = AccountAddress.from(addr);

    // Just check if the account address is valid.
    let result = AccountAddress.isValid(addr);
    let valid = result.valid;
}

You can learn more about AccountAddress here: https://aptos-labs.github.io/aptos-ts-sdk/@aptos-labs/ts-sdk-1.9.1/classes/AccountAddress.html.

Replies: 1 comment

Comment options

banool
Mar 7, 2024
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by banool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant