Locus Wallet API
Integrating the website with the wallet
- Javascript
if (!window.locus) {
alert('Locus wallet is not installed.');
return;
}
const addr = await window.locus.request('connect').catch(err => {
console.error(err);
});
console.error(addr);
Function call
const params = {
assetType: 'asset1',
amount: '1000',
operator: '',
metaData: await window.locus.utils.ConvertStringToData(
'{"imageUrl":"https://foo/test.png"}'
)
};
const result = await window.locus.request('createAssetObject', params).catch(err => {
console.error(err);
});
console.log('createAssetObject result', result);
Register event listener
window.locus.on("accountChanged", (data) => {
console.log(`accountChanged! ${data.addr}`);
});
List of Functions
connect
Connect the wallet to the designated site.
Input
[None]
Output
| Key | Type | Description |
|---|---|---|
| addr | string | Connected wallet address |
getAccount
Retrieve the account connected to the target site.
Input
[None]
Output
| Key | Type | Description |
|---|---|---|
| - | string | Account Address |
getAccountDetail
Retrieve the status of the account.
Input
[None]
Output
| Key | Type | Description |
|---|---|---|
| status | string | Account status (pending: open account not completed, activated: open account completed) |
| info | object | locus_getAccountDetail rpc response Locus JSON-RPC |
getBalance
Retrieve the amount of coins held by the account.
Input
| Key | Type | Description |
|---|---|---|
| addr | string | Account Address |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Amount of coins held |
getNodeUrl
Retrieve the RPC URL of the selected network.
Input
[None]
Output
| Key | Type | Description |
|---|---|---|
| - | string | RPC url |
sign
Sign a string with the normal private key.
Input
| Key | Type | Description |
|---|---|---|
| input | string | target to Sign |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Signature result |
addNetwork
Register a new network in the wallet.
Input
| Key | Type | Description |
|---|---|---|
| name | string | Name |
| rpcUrl | string | RPC call url |
| currencySymbol | string | Default currency |
| explorerUrl | string | (Optional) Explorer URL |
Output
| Key | Type | Description |
|---|---|---|
| - | boolean | Success Status |
transferCoin
Send coins to another account.
Input
| Key | Type | Description |
|---|---|---|
| to | string | Recipient account address |
| amount | string | Quantity of coins to send |
Output
| Key | Type | Description |
|---|---|---|
| Hash | base64 | Tx Hash |
| Tx | string | Created Tx |
| Success | bool | Success Status |
| signedHeight | number | Signed tx height |
| feeType | number | Fee Type (AUTO:0, GRANT_ONLY:1) |
transferToken
Send tokens to another account.
Input
| Key | Type | Description |
|---|---|---|
| contractAddr | string | Contract address |
| to | string | Recipient account address |
| amount | string | Quantity of tokens to send |
| decimal | int32 | Token decimal place |
Output
| Key | Type | Description |
|---|---|---|
| Hash | base64 | Tx Hash |
| Tx | string | Generated Tx |
| Success | bool | Success Status |
| signedHeight | number | Signed tx height |
| feeType | number | Fee Type (AUTO:0, GRANT_ONLY:1) |
createContract
Create contract.
Input
| Key | Type | Description |
|---|---|---|
| contractAccount | string | (Optional) Address for the contract to be created. If not provided, a new address will be generated. |
| code | string | binary code of source |
| amount | string | Coins to be deposited into the newly created contract account, which will be deducted from the creator's coins. |
| fuelLimit | uint32 | Fuel limit for creating the contract. |
| tokenAmounts | []{TokenID base32, AmountToken string} | Token information to be sent to the contract. |
| sysId | base32 | |
| until | base32 | Maximum rounds for retrying contract creation. |
Output
| Key | Type | Description |
|---|---|---|
| ContractAccount | base32 | The address of the created contract. You can use the return value of the first call as an argument for the second call. |
| Hash | base64 | Tx Hash |
| Tx | string | Generated Tx |
| Success | bool | Success Status |
| signedHeight | number | tx height to be included in the 2nd call |
| feeType | number | Fee Type (AUTO:0, GRANT_ONLY:1) |
callContract
Execute the contract function.
Input
| Key | Type | Description |
|---|---|---|
| contractAccount | string | Smart Contract address |
| func | string | Function name |
| argData | string | Parameters |
| abi | string | ABI JSON string of the function to be executed |
| funcStr | string | (Optional) Function name for display in the wallet |
| funcArgs | []string | (Optional) Parameters for display in the wallet |
Output
| Key | Type | Description |
|---|---|---|
| Hash | base64 | Tx Hash |
| Tx | string | Generated Tx |
| Success | bool | Success Status |
| signedHeight | number | Signed tx height |
| feeType | number | Fee Type (AUTO:0, GRANT_ONLY:1) |
viewContract
Calls a function to read data from the smart contract.
Input
| Key | Type | Description |
|---|---|---|
| contractAccount | string | Smart contract address |
| func | string | Function name |
| argData | string | Parameters |
Output
| Key | Type | Description |
|---|---|---|
| result | base64 | Result of function call |
createAssetObject
Create AssetObject.
Input
| Key | Type | Description |
|---|---|---|
| assetType | string | Type of object to create |
| amount | string | Quantity to create, if 0, create as a single Object with no quantity. |
| operator | string | Management account (Contract address) |
| metaData | base64 | User-defined information data |
Output
| Key | Type | Description |
|---|---|---|
| hash | string | Transaction Hash |
| tx | object | Created Tx |
| success | boolean | Success Status |
| signedHeight | number | tx height to be included in the 2nd call |
| feeType | number | Fee Type (AUTO:0, GRANT_ONLY:1) |
transferAssetObject
Transfer AssetObject.
Input
| Key | Type | Description |
|---|---|---|
| to | base32 | Account to receive Asset Unit |
| assetId | base64 | Unique ID of Asset |
| amount | string | Quantity |
Output
| Key | Type | Description |
|---|---|---|
| hash | string | Transaction Hash |
| tx | object | Created Tx |
| success | boolean | Success Status |
| signedHeight | number | tx height to be included in the 2nd call |
| feeType | number | Fee Type (AUTO:0, GRANT_ONLY:1) |
getAccountAssetList
Retrieve the Asset list of the account and retrieve Object ID and quantity by AssetId.
Input
| Key | Type | Description |
|---|---|---|
| count | number | Limit count to retrieve, 0 to allow all |
Output
| Key | Type | Description |
|---|---|---|
| AssetList | string | Owned object information array (Total Amount, ObjectId Array) []{Amount, []Digest} |
getAccountAssetObject
Output AssetObjects corresponding to the AssetId specified in the account.
Input
| Key | Type | Description |
|---|---|---|
| assetId | []base64 | Unique ID array of Asset |
Output
| Key | Type | Description |
|---|---|---|
| objects | []AssetObject | Owned object info |
| unactObjects | []AssetObject | Unactivated object info |
AssetObject
| Key | Type | Description |
|---|---|---|
| version | number | Version of this object structure |
| type | string | Object type name |
| assetId | string | Unique ID for object type |
| objectId | string | Unique ID of object |
| amount | string | Quantity |
| operator | string | Address to link when creating or managing object (Contract link address) |
| metaData | base64 | Other information about this object (User defined) |
| hash | string | Hash to verify object validity |
getNodeStatus
Returns the status information of the node.
Input
None
Output
| Key | Type | Description |
|---|---|---|
| nodeId | string | Node ID |
| baseTime | number | Base Time |
| host | string | Host Address |
| reliable | boolean | Is Reliable Node |
| roundTime | number | Round Time |
| roundCycle | number | Round Cycle |
| prunedRound | number | Pruned Round |
| round | number | Current Round |
| epoch | number | Epoch |
| shardId | number | Shard ID |
| homeShardId | number | Home Shard ID |
| totalShard | number | Total Shard Count |
| networkId | number | Network ID |
| totalHeight | string | Total Height |
| intraPeerCount | number | Intra Peer Count |
| interPeerCount | number | Inter Peer Count |
| syncState | string | Sync State |
| detailState | string | Detail State |
| presyncState | string | Presync State |
| buildTime | string | Build Time |
| avgTxTime | string | Average Tx Time |
| rsNextRound | number | Next RS Round |
| rsf | number | RSF |
| vmInfo | string | VM Info |
| wrsNextRound | number | Next WRS Round |
| wrsHeight | number | WRS Height |
getNodeInfo
Returns summary information of the node connected to the wallet.
Input
None
Output
| Key | Type | Description |
|---|---|---|
| shardId | number | Shard ID |
| round | number | Round |
| host | string | Host |
| baseTime | number | Base Time |
| reliable | boolean | Is Reliable |
| status | number | Node Status (NodeStatus enum) |
| netStatus | number | Network Status (NodeNetStatus enum) |
| buildTime | string | Build Time |
| networkId | number | Network ID |
| rpcFailCount | number | RPC Fail Count |
| genesis | string | Genesis Hash |
getAccountInfo
Returns detailed information of the selected account.
Input
None
Output
| Key | Type | Description |
|---|---|---|
| addr | string | Account Address |
| existAddr | string | Existing Address (Optional) |
| status | number | Account Status (AccountStatus enum) |
| totalBalance | string | Total Balance |
| balance | string | Balance |
| grant | number | Grant |
| identity | string | Identity |
| representative | string | Representative |
| height | number | Height |
| unactBalance | string | Inactive Balance |
| canBecomeHost | boolean | Can Become Host |
| canBecomeGuest | boolean | Can Become Guest |
getFirstVmeInfo
Returns the first VME (Validator Management Engine) information.
Input
None
Output
| Key | Type | Description |
|---|---|---|
| code | number | Response Code |
| message | string | Response Message |
| data | object | VME Info Data |
getVmeList
Returns the VME list.
Input
None
Output
| Key | Type | Description |
|---|---|---|
| code | number | Response Code |
| message | string | Response Message |
| data | array | VME Info List |
Event List
init
This event occurs once when the wallet is properly installed and ready for use.
Output
| Key | Type | Description |
|---|---|---|
| connectedAccount | account | Connected Account Info |
| address | string | Current selected account address |
| network | network | Selected Network Info |
| extensionId | string | Wallet's extension ID |
| connected | boolean | Whether the account is connected to the site |
network
| Key | Type | Description |
|---|---|---|
| id | string | Network ID |
| name | string | Network name |
| rpcUrl | string | RPC URL |
| currencySymbol | string | Currency symbol |
| explorerUrl | string | Explorer URL |
account
| Key | Type | Description |
|---|---|---|
| addr | string | Account Address |
| name | string | Account Name |
connected
Occurs when the wallet is connected to the target site. (Deprecated)
Output
| Key | Type | Description |
|---|---|---|
| addr | string | Connected account address |
connect
Occurs when connected to the target site.
Output
| Key | Type | Description |
|---|---|---|
| addr | string | Connected account address |
disconnect
Occurs when the wallet is disconnected from the target site.
Output
| Key | Type | Description |
|---|---|---|
| addr | string | Disconnected account address |
connectionChanged
Occurs when the connected account is changed.
Output
| Key | Type | Description |
|---|---|---|
| addr | string | Changed account address |
accountChanged
Occurs when the account is selected.
Output
| Key | Type | Description |
|---|---|---|
| addr | string | Account Address |
networkChanged
Occurs when the network is changed.
Output
| Key | Type | Description |
|---|---|---|
| id | string | Network ID of the registered network |
| name | string | Name of the registered network |
| rpcUrl | string | RPC URL for the registered network |
| currencySymbol | string | Default currency symbol for the registered network |
| explorerUrl | string | Explorer URL for the registered network |
lockWallet
Occurs when logging out from the wallet.
Output
[None]
unlockWallet
Occurs when logging into the wallet. (Deprecated)
Output
| Key | Type | Description |
|---|---|---|
| addr | string | Address of the logged-in account |
login
Occurs when logging into the wallet.
Output
| Key | Type | Description |
|---|---|---|
| addr | string | Address of the logged-in account |
logout
Occurs when logging out from the wallet.
Output
[None]
contractResult
Occurs when receiving the smart contract execution result.
Output
| Key | Type | Description |
|---|---|---|
| contract | string | Contract Address |
| result | string | Execution Result |
| error | string | Error Message |
| transfers | array | Token Transfer History |
| callerAddr | string | Caller Address |
| callerIndex | number | Caller Index |
| state | number | Contract State (1: Call, 2: Execute, 3: Confirm, 4: Result Failure) |
acceptConfirmation
Occurs when accepting from the wallet confirmation prompt.
Output
| Key | Type | Description |
|---|---|---|
| uuid | string | Request unique key |
| data | string | Execution result |
rejectConfirmation
Occurs when rejecting from the wallet confirmation prompt.
Output
| Key | Type | Description |
|---|---|---|
| uuid | string | Request unique key |
| code | string | 0: General 1: Rejected by user |
| message | string | Error Message |
rejectAllConfirmations
Occurs when rejecting all from the wallet confirmation prompt.
Output
| Key | Type | Description |
|---|---|---|
| - | []result | List of rejected requests |
result
| Key | Type | Description |
|---|---|---|
| uuid | string | Request unique key |
| code | string | 0: General 1: Rejected by user |
| message | string | Error Message |