namespace
This module allows you to create and manage namespaces. It can be accessed from the global variable ns.

register

1
ns.register(txObject, [signingKey | payloadOnly | [signingKey, payloadOnly]])
Copied!
Send a transaction to register a public key as a push key.

Parameters

  1. 1.
    txObject - Object: The transaction object
    • name - String: The unique name
    • value - String: The namespace registration fee.
    • to - String: (optional) The user address or repository that will own and control the namespace.
    • domains - Object: The namespace domain and target pairs. The domain must contain only alphanumeric (plus underscore and hyphen) characters. The target must be a user address prefixed with a/ or a repository name prefixed with r/.
    • nonce - Number|String : The signing account’s next nonce.
    • fee - String: The network fee to be paid by the signing account.
    • timestamp - String: (optional) The unix timestamp of the transaction.
    • sig - String : (optional) The transaction signature. If not provided, the transaction will be signed using the signingKey.
  2. 2.
    signingKey - String: (optional) The private key to use to sign the transaction.
  3. 3.
    payloadOnly - Boolean: (optional) When true, the transaction payload is returned instead of being sent to the network.

Returns

Object - The result object
  • hash - String: A 32 bytes transaction hash.

Example

  • Create a transaction to register a namespace.
1
ns.register({
2
value: "1",
3
fee: "1",
4
name: "myname",
5
domains: {
6
"target": "r/repo",
7
"target2": "a/os1qfrysysaawvjlgfz5ecqv569adkkw7sxudy36u"
8
},
9
}, user.getKey(accounts[0]))
Copied!

updateDomain

1
ns.updateDomain(txObject, [signingKey | payloadOnly | [signingKey, payloadOnly]])
Copied!
Send a transaction to register a public key as a push key.

Parameters

  1. 1.
    txObject - Object: The transaction object
    • name - String: The unique name
    • domains - Object: The namespace domain and target pairs. Domain must contain only alphanumeric (plus underscore and hyphen) characters. Target must be a user address prefixed with a/ or a repository name prefixed with r/.
    • nonce - Number|String : The signing account’s next nonce.
    • fee - String: The network fee to be paid by the signing account.
    • timestamp - String: (optional) The unix timestamp of the transaction.
    • sig - String : (optional) The transaction signature. If not provided, the transaction will be signed using the signingKey.
  2. 2.
    signingKey - String: (optional) The private key to use to sign the transaction.
  3. 3.
    payloadOnly - Boolean: (optional) When true, the transaction payload is returned instead of being sent to the network.

Returns

Object - The result object
  • hash - String: A 32 bytes transaction hash.

Example

  • Create a transaction to update the domains of a namespace.
1
ns.updateDomain({
2
value: "1",
3
fee: "1",
4
name: "ns-xyz",
5
domains: {
6
"target": "r/repo"
7
}
8
}, user.getKey(accounts[0]))
Copied!

lookup

1
ns.lookup(name, [height])
Copied!
Find a namespace by its name.

Parameters

  1. 1.
    name - String: The name of the namespace.
  2. 2.
    height - String|Number: (optional) The block height to query (Default: latest).

Returns

Object - The result object
  • name - String: The namespace name.
  • owner - String: The user address or repository that owns the namespace.
  • expiresAt - String: The block height when the namespace lease expires.
  • graceEndAt - String: The block height when grace period will end.
  • expired - Boolean: When true, it means the namespace has expired.
  • grace - Boolean: When true, it means that namespace has expired and in the grace period.

Example

  • Create a transaction to register a namespace.
1
ns.register({
2
value: "1",
3
fee: "1",
4
name: "google",
5
domains: {
6
"target": "r/repo",
7
"target2": "a/os1qfrysysaawvjlgfz5ecqv569adkkw7sxudy36u"
8
}
9
}, user.getKey(accounts[0]))
Copied!

getTarget

1
ns.getTarget(path, [height])
Copied!
Find a namespace by its name.

Parameters

  1. 1.
    path - String: The domain path namespace/domain
  2. 2.
    height - String|Number: (optional) The block height to query (Default: latest).

Returns

String - The target value

Example

JavaScript
Output
1
// sends a transaction to register a namespace
2
ns.getTarget("myname/target")
Copied!
1
"r/repo"
Copied!
Last modified 1yr ago