Registering Usernames
This section covers how to programmatically register Subsocial Usernames on the Subsocial blockchain.
Subsocial usernames allow you to map a human-readable name to your Substrate account. Read more here.
To register a Subsocial username from a web UI, go to https://polkaverse.com/dd.
Registering usernames
To register new usernames, you need to pass a set of details to create the transaction:
api.substrateApi.tx.domains.registerDomain(
fullDomain: Bytes | string | Uint8Array,
content: SubsocialSupportContent
| { None: any; }
| { Other: any; }
| { IPFS: any; }
| string | Uint8Array,
expiresIn: u32 | AnyNumber | Uint8Array)
Params | Description |
---|---|
fullDomain | Full username like myname.sub |
content | The content field can have a value like a string, IPFS content, a URL, or Subsocial defined object. |
expiresIn | The number of blocks after which a username expires. |
Example:
const username = 'ramesh.sub'
const content = {
IPFS: 'my custom content'
}
const expiresIn = 1000
const substrateApi = await api.substrateApi
const usernameTransaction = await substrateApi.tx.domains.registerDomain(username, content, expiresIn)
Updating content
To set content for an existing username, you can use the following method:
api.substrateApi.tx.domains.setDomainContent(domain: Bytes | string | Uint8Array, content: SubsocialSupportContent | {
None: any;
} | {
Other: any;
} | {
IPFS: any;
} | string | Uint8Array)
Params | Description |
---|---|
domain | Existing username like myname.sub |
content | The content field can have a value like a string, IPFS content, a URL, or Subsocial defined object. |
Example:
const username = 'ramesh.sub'
const content = {
IPFS: 'my new custom content'
}
const substrateApi = await api.substrateApi
const usernameTransaction = await substrateApi.tx.domains.setDomainContent(username, content)
Updating values
Each username entity has properties called innerValue and outerValue that can be set by the user. Generally, we use innerValue for referencing a particular space on the Subsocial blockchain and outerValue for websites or URLs.
To set values for an existing username, you can use the following method:
- Inner Value
- Outer Value
api.substrateApi.tx.domains.setInnerValue(domain: Bytes | string | Uint8Array, valueOpt: Option<PalletDomainsInnerValue> | null | Uint8Array | PalletDomainsInnerValue | {
Account: any;
} | {
Space: any;
} | {
Post: any;
} | string)
Params | Description |
---|---|
domain | Existing username like myname.sub |
valueOpt | The value opt can point to entities on the Subsocial blockchain like Space, Account, Post, etc. |
Example:
const username = 'ramesh.sub'
const valueOpt = {
Space: '1'
}
const substrateApi = await api.substrateApi
const usernameTransaction = await substrateApi.tx.domains.setInnerValue(username, valueOpt)
api.substrateApi.tx.domains.setOuterValue(domain: Bytes | string | Uint8Array, valueOpt: Option<Bytes> | null | Uint8Array | Bytes | string)
Params | Description |
---|---|
domain | Existing username like myname.sub |
valueOpt | The valueOpt field can have a value like a string, urls or it can be null too. |
Example:
const username = 'ramesh.sub'
const valueOpt = 'https://polkaverse.com'
const substrateApi = await api.substrateApi
const usernameTransaction = await substrateApi.tx.domains.setOuterValue(username, valueOpt)