This module allows you to access both personal information of the node runner. The module is accessed from the global variable user
.
user.getKeys()
Gets the address of all keys stored on the keystore of the node.
Array<String>
: A list of addresses.
user.getKeys()
["os1qfrysysaawvjlgfz5ecqv569adkkw7sxudy36u","os1wfx7vp8qfyv98cctvamqwec5xjrj48tpklxklh"]
user.getKey(addrOrIndex, [passphrase])
Gets the private key of a key by its address or keystore index. If the key exists, it will be unlocked using the provided passphrase
. If passphrase
is not provided, an interactive prompt will be launched to ask for it.
addrOrIndex
- String|Number
: The address or keystore index of the key
passphrase
- String
: (Optional) The passphrase to use to unlock the key. If not provided, you will be prompted to provide it.
String
: The base58 encoded private key.
user.getKey("os1qfrysysaawvjlgfz5ecqv569adkkw7sxudy36u")
"wXVFmgEmKumxVnQGSnL67krnWkBj4Q...W711b7UnmARiUWtSNSJ6pVhmk1ppiPQPGrD8F3"
user.getPublicKey(addrOrIndex, [passphrase])
Gets the public key of a key by its address or keystore index. If the key exists, it will be unlocked using the provided passphrase
. If passphrase
is not provided, an interactive prompt will be launched to ask for it.
addrOrIndex
- String|Number
: The address or keystore index of the key
passphrase
- String
: (Optional) The passphrase to use to unlock the key. If not provided, you will be prompted to provide it.
String
: The base58 encoded public key.
chain.getPublicKey("os1qfrysysaawvjlgfz5ecqv569adkkw7sxudy36u")
"48hpSpVR39MX947pHPSxRzKHoe65rLWzLWuC14sBU1n6tu7Jg5x"
user.getNonce(address, [height])
Gets the current nonce of a user account.
address
- String
: The address of the target user account.
height
- String|Number
: (Optional) The block height to query (Default: latest).
String
: The current nonce.
user.getNonce("os1qfrysysaawvjlgfz5ecqv569adkkw7sxudy36u")
"12"
user.get(address, [height])
Gets a user account by its address.
address
- String
: The address of the target user account.
height
- String|Number
: (Optional) The block height to query (Default: latest).
Object
: The account object balance
- String
: The native coin balance. nonce
- String
: The account nonce. stakes
- Object
: Staked coin information delegatorCommission
- String
: Commission to receive from delegators.
user.get("os1qfrysysaawvjlgfz5ecqv569adkkw7sxudy36u")
{"balance": "1984872.35","nonce": "91"}
user.getBalance(address, [height])
Gets the coin balance of a user account.
address
- String
: The address of the target user account.
height
- String|Number
: (Optional) The block height to query (Default: latest).
String
: The coin balance.
user.getBalance("os1qfrysysaawvjlgfz5ecqv569adkkw7sxudy36u")
"12.3"
user.getStakedBalance(address, [height])
Gets the total amount of the native coin a user account has staked.
address
- String
: The address of the target user account.
height
- String|Number
: (Optional) The block height to query (Default: latest).
String
: The coin balance.
user.getStakedBalance("os1qfrysysaawvjlgfz5ecqv569adkkw7sxudy36u")
"12.3"
user.getValidator(includePrivKey)
Gets the node’s validator key.
includePrivKey
- Boolean
: When true, the private key is included in the result.
Object
: The validator key information.
user.getValidator(true)
{"address": "os174vnayvd6teyzcfze5z7xsdmzg4kxk8l6jry7n","privateKey": "wnrZynYB6837qB5mRN7V4To1MDB...nYZxaU9qQZPWhsFUPHefAdQEyRUu","publicKey": "48J1NrCGHu4D8qkbsGYKRRaVhJgPt3gfFmgwmSeNjMcrsX1fuas","tmAddress": "5CFFB08E0403EF88770EBAEA3499324779D0FB06"}
user.setCommission(txObject, [signingKey | payloadOnly | [signingKey, payloadOnly]])
Create a transaction that updates the delegator commission percentage of a validator account.
txObject
- Object
: The transaction object
commission
- String
: The percentage of reward to receive from delegators.
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
.
signingKey
- String
: (optional) The private key to use to sign the transaction.
payloadOnly
- Boolean
: (optional) When true, the transaction payload is returned instead of being sent to the network.
Object
- The result object
hash
- String
: A 32 bytes transaction hash.
user.setCommission({commission: "100",fee: "1"}, user.getKey(accounts[0]))
user.send(txObject, [signingKey | payloadOnly | [signingKey, payloadOnly]])
Create a transaction that sends coins from the signers account to another account or repository.
txObject
- Object
: The transaction object
value
- Number|String
: The amount of native coin to be sent.
to
- String
: The address of the recipient; A user address 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
.
signingKey
- String
: (optional) The private key to use to sign the transaction.
payloadOnly
- Boolean
: (optional) When true, the transaction payload is returned instead of being sent to the network.
Object
- The result object
hash
- String
: A 32 bytes transaction hash.
user.send({to: "os1qfrysysaawvjlgfz5ecqv569adkkw7sxudy36u",value:"5000",fee: "1"}, user.getKey(accounts[0]))