Skip to content
This repository was archived by the owner on Aug 27, 2024. It is now read-only.

Commit 072d613

Browse files
CurlyBracketEffectdanforbesimadaraiJimmy ChuDan Forbes
authored
Add validate address options (#804)
* Add validate address options I have added the 2 main tools that Parity has created to validate ss58 addresses. I also added a list of places for developers to look for some more code examples to use to create their own custom validation tools in various languages. @joepetrowski @danforbes * Fix line length * Add validate address options I have added the 2 main tools that Parity has created to validate ss58 addresses. I also added a list of places for developers to look for some more code examples to use to create their own custom validation tools in various languages. @joepetrowski @danforbes * Nitpicks * Updated Terms of Use per Legal (#803) * Updated Terms of Use per Legal * Prettier `npx prettier --write --print-width 100 ./website/pages/en/terms.js` Co-authored-by: Dan Forbes <[email protected]> * refining off-chain indexing (#800) * refining off-chain indexing * Update docs/knowledgebase/learn-substrate/off-chain-workers.md Co-authored-by: Dan Forbes <[email protected]> * Update docs/knowledgebase/learn-substrate/off-chain-workers.md Co-authored-by: Dan Forbes <[email protected]> * Expanded the section from off-chain-worker to off-chain-features * Update docs/knowledgebase/learn-substrate/off-chain-features.md Co-authored-by: Tomasz Drwięga <[email protected]> * update on content to make it more coherent * Fix link * Links and nitpicks * Prettier Co-authored-by: Dan Forbes <[email protected]> Co-authored-by: Tomasz Drwięga <[email protected]> Co-authored-by: Dan Forbes <[email protected]> * Bump ini from 1.3.5 to 1.3.7 in /website (#801) Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.7. - [Release notes](https://github.com/isaacs/ini/releases) - [Commits](npm/ini@v1.3.5...v1.3.7) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jimmy Chu <[email protected]> * Making most static strings in substrate.dev supporting multi-lingual (#802) * adding <translate> tag for multi-lingual support * Most strings are translatable now * Minor fix of bash syntax in console output * fixing spacing * using relative link so multi-lingual option is kept between navigation * cmd style in console output * Indent all JS to use spacing for indentation * Updated to latest libs * Fix site internal links to respect multi-lingual. * Add validate address options I have added the 2 main tools that Parity has created to validate ss58 addresses. I also added a list of places for developers to look for some more code examples to use to create their own custom validation tools in various languages. @joepetrowski @danforbes * Fix line length * Add validate address options I have added the 2 main tools that Parity has created to validate ss58 addresses. I also added a list of places for developers to look for some more code examples to use to create their own custom validation tools in various languages. @joepetrowski @danforbes * Fix: Comment Edits * Update docs/knowledgebase/advanced/ss58-address-format.md Co-authored-by: joe petrowski <[email protected]> * Update docs/knowledgebase/advanced/ss58-address-format.md Co-authored-by: joe petrowski <[email protected]> * Update docs/knowledgebase/advanced/ss58-address-format.md Co-authored-by: joe petrowski <[email protected]> * Update docs/knowledgebase/advanced/ss58-address-format.md Co-authored-by: joe petrowski <[email protected]> * Update docs/knowledgebase/advanced/ss58-address-format.md Co-authored-by: joe petrowski <[email protected]> * Review and edits for SS58 General pruning to make text more succinct. Slight tweak on structure and linking to be more consistent with other KB articles. Added code comments too. * Revert "Review and edits for SS58 " This reverts commit 532d283. * Apply uncontroversial suggestions from code review Co-authored-by: sacha-l <[email protected]> * fix github suggestions error * Update docs/knowledgebase/advanced/ss58-address-format.md Co-authored-by: sacha-l <[email protected]> * fix: wording and formatting * Update docs/knowledgebase/advanced/ss58-address-format.md Co-authored-by: Dan Forbes <[email protected]> Co-authored-by: Imad Arain <[email protected]> Co-authored-by: Jimmy Chu <[email protected]> Co-authored-by: Dan Forbes <[email protected]> Co-authored-by: Tomasz Drwięga <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jimmy Chu <[email protected]> Co-authored-by: joe petrowski <[email protected]> Co-authored-by: Sacha <[email protected]> Co-authored-by: sacha-l <[email protected]>
1 parent 37327e4 commit 072d613

File tree

1 file changed

+85
-2
lines changed

1 file changed

+85
-2
lines changed

docs/knowledgebase/advanced/ss58-address-format.md

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,89 @@ The basic idea is a base-58 encoded value that can identify a specific account o
1010
chain. Different chains have different means of identifying accounts. SS58 is designed to be
1111
extensible for this reason.
1212

13-
The living specification for the SS-58 address format can be found on the Substrate GitHub wiki:
13+
The living specification for the SS58 address format can be found on the
14+
[Substrate GitHub wiki](<https://github.com/paritytech/substrate/wiki/External-Address-Format-(SS58)>).
1415

15-
https://github.com/paritytech/substrate/wiki/External-Address-Format-(SS58)
16+
## Validating Addresses
17+
18+
There are several ways to verify that a value is a valid SS58 address.
19+
20+
### Subkey
21+
22+
You can use the [Subkey](https://substrate.dev/docs/en/knowledgebase/integrate/subkey) `inspect`
23+
subcommand, which accepts the seed phrase, a hex-encoded private key, or an SS58 address as the input
24+
URI. If the input is a valid address, it will return a list containing the corresponding public
25+
key (hex), account ID, and SS58 values.
26+
27+
Subkey assumes that an address is based on a public/private keypair. In the case of inspecting an
28+
address, it will return the 32 byte account ID. Not all addresses in Substrate-based networks are
29+
based on keys.
30+
31+
> **Note:** If you input a valid SS58 value, Subkey will also return a network ID/version value
32+
> that indicates for which network the address has been encoded.
33+
34+
```bash
35+
# A valid address.
36+
$ subkey inspect "12bzRJfh7arnnfPPUZHeJUaE62QLEwhK48QnH9LXeK2m1iZU"
37+
Public Key URI `12bzRJfh7arnnfPPUZHeJUaE62QLEwhK48QnH9LXeK2m1iZU` is account:
38+
Network ID/version: polkadot
39+
Public key (hex): 0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a
40+
Account ID: 0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a
41+
SS58 Address: 12bzRJfh7arnnfPPUZHeJUaE62QLEwhK48QnH9LXeK2m1iZU
42+
43+
# An invalid address.
44+
$ subkey inspect "12bzRJfh7arnnfPPUZHeJUaE62QLEwhK48QnH9LXeK2m1iZUInvalidAddress"
45+
Invalid phrase/URI given
46+
```
47+
48+
### Polkadot.js
49+
50+
For verifying an address in your JavaScript projects, you can utilize the functions built
51+
into the [Polkadot.js API](https://polkadot.js.org/docs/api/).
52+
53+
```javascript
54+
// Import Polkadot.js API dependencies.
55+
const { decodeAddress, encodeAddress } = require("@polkadot/keyring");
56+
const { hexToU8a, isHex } = require("@polkadot/util");
57+
58+
// Specify an address to test.
59+
const address = "<addressToTest>";
60+
61+
// Check address.
62+
const isValidSubstrateAddress = () => {
63+
try {
64+
encodeAddress(isHex(address) ? hexToU8a(address) : decodeAddress(address));
65+
66+
return true;
67+
} catch (error) {
68+
return false;
69+
}
70+
};
71+
72+
// Query result.
73+
const isValid = isValidSubstrateAddress();
74+
console.log(isValid);
75+
```
76+
77+
### Community Built
78+
79+
Below you will find a list of other Substrate API tools built in various languages by our community.
80+
They each validate addresses in their own way, and can act as a starting point.
81+
82+
- [Python Substrate Interface](https://polkascan.github.io/py-substrate-interface/#substrateinterface.Keypair) - developed by Polkascan.
83+
84+
- [Go Substrate RPC client](https://github.com/centrifuge/go-substrate-rpc-client) - developed by Centrifuge.
85+
86+
- [C++ Polkadot Substrate API](https://github.com/usetech-llc/polkadot_api_cpp) - developed by Usetech.
87+
88+
- [.Net API](https://github.com/usetech-llc/polkadot_api_dotnet) - developed by Usetech.
89+
90+
- [Go implemented utilities](https://github.com/itering/subscan-essentials) - developed by Subscan.
91+
92+
- [SS58 Transform](https://polkadot.subscan.io/tools/ss58_transform) - to manually verify an address (sanity check).
93+
94+
### Learn More
95+
96+
- [Polkadot-js API on GitHub](https://github.com/polkadot-js/api)
97+
98+
- [Subkey guide](docs/en/knowledgebase/integrate/subkey)

0 commit comments

Comments
 (0)