Skip to main content

Locus Wallet API

Integrating the website with the wallet

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

KeyTypeDescription
addrstringConnected wallet address

getAccount

Retrieve the account connected to the target site.

Input

[None]

Output

KeyTypeDescription
-stringAccount Address

getAccountDetail

Retrieve the status of the account.

Input

[None]

Output

KeyTypeDescription
statusstringAccount status (pending: open account not completed, activated: open account completed)
infoobjectlocus_getAccountDetail rpc response Locus JSON-RPC

getBalance

Retrieve the amount of coins held by the account.

Input

KeyTypeDescription
addrstringAccount Address

Output

KeyTypeDescription
-stringAmount of coins held

getNodeUrl

Retrieve the RPC URL of the selected network.

Input

[None]

Output

KeyTypeDescription
-stringRPC url

sign

Sign a string with the normal private key.

Input

KeyTypeDescription
inputstringtarget to Sign

Output

KeyTypeDescription
-stringSignature result

addNetwork

Register a new network in the wallet.

Input

KeyTypeDescription
namestringName
rpcUrlstringRPC call url
currencySymbolstringDefault currency
explorerUrlstring(Optional) Explorer URL

Output

KeyTypeDescription
-booleanSuccess Status

transferCoin

Send coins to another account.

Input

KeyTypeDescription
tostringRecipient account address
amountstringQuantity of coins to send

Output

KeyTypeDescription
Hashbase64Tx Hash
TxstringCreated Tx
SuccessboolSuccess Status
signedHeightnumberSigned tx height
feeTypenumberFee Type (AUTO:0, GRANT_ONLY:1)

transferToken

Send tokens to another account.

Input

KeyTypeDescription
contractAddrstringContract address
tostringRecipient account address
amountstringQuantity of tokens to send
decimalint32Token decimal place

Output

KeyTypeDescription
Hashbase64Tx Hash
TxstringGenerated Tx
SuccessboolSuccess Status
signedHeightnumberSigned tx height
feeTypenumberFee Type (AUTO:0, GRANT_ONLY:1)

createContract

Create contract.

Input

KeyTypeDescription
contractAccountstring(Optional) Address for the contract to be created. If not provided, a new address will be generated.
codestringbinary code of source
amountstringCoins to be deposited into the newly created contract account, which will be deducted from the creator's coins.
fuelLimituint32Fuel limit for creating the contract.
tokenAmounts[]{TokenID base32, AmountToken string}Token information to be sent to the contract.
sysIdbase32
untilbase32Maximum rounds for retrying contract creation.

Output

KeyTypeDescription
ContractAccountbase32The address of the created contract. You can use the return value of the first call as an argument for the second call.
Hashbase64Tx Hash
TxstringGenerated Tx
SuccessboolSuccess Status
signedHeightnumbertx height to be included in the 2nd call
feeTypenumberFee Type (AUTO:0, GRANT_ONLY:1)

callContract

Execute the contract function.

Input

KeyTypeDescription
contractAccountstringSmart Contract address
funcstringFunction name
argDatastringParameters
abistringABI JSON string of the function to be executed
funcStrstring(Optional) Function name for display in the wallet
funcArgs[]string(Optional) Parameters for display in the wallet

Output

KeyTypeDescription
Hashbase64Tx Hash
TxstringGenerated Tx
SuccessboolSuccess Status
signedHeightnumberSigned tx height
feeTypenumberFee Type (AUTO:0, GRANT_ONLY:1)

viewContract

Calls a function to read data from the smart contract.

Input

KeyTypeDescription
contractAccountstringSmart contract address
funcstringFunction name
argDatastringParameters

Output

KeyTypeDescription
resultbase64Result of function call

createAssetObject

Create AssetObject.

Input

KeyTypeDescription
assetTypestringType of object to create
amountstringQuantity to create, if 0, create as a single Object with no quantity.
operatorstringManagement account (Contract address)
metaDatabase64User-defined information data

Output

KeyTypeDescription
hashstringTransaction Hash
txobjectCreated Tx
successbooleanSuccess Status
signedHeightnumbertx height to be included in the 2nd call
feeTypenumberFee Type (AUTO:0, GRANT_ONLY:1)

transferAssetObject

Transfer AssetObject.

Input

KeyTypeDescription
tobase32Account to receive Asset Unit
assetIdbase64Unique ID of Asset
amountstringQuantity

Output

KeyTypeDescription
hashstringTransaction Hash
txobjectCreated Tx
successbooleanSuccess Status
signedHeightnumbertx height to be included in the 2nd call
feeTypenumberFee Type (AUTO:0, GRANT_ONLY:1)

getAccountAssetList

Retrieve the Asset list of the account and retrieve Object ID and quantity by AssetId.

Input

KeyTypeDescription
countnumberLimit count to retrieve, 0 to allow all

Output

KeyTypeDescription
AssetListstringOwned object information array
(Total Amount, ObjectId Array)
[]{Amount, []Digest}

getAccountAssetObject

Output AssetObjects corresponding to the AssetId specified in the account.

Input

KeyTypeDescription
assetId[]base64Unique ID array of Asset

Output

KeyTypeDescription
objects[]AssetObjectOwned object info
unactObjects[]AssetObjectUnactivated object info

AssetObject

KeyTypeDescription
versionnumberVersion of this object structure
typestringObject type name
assetIdstringUnique ID for object type
objectIdstringUnique ID of object
amountstringQuantity
operatorstringAddress to link when creating or managing object (Contract link address)
metaDatabase64Other information about this object (User defined)
hashstringHash to verify object validity

getNodeStatus

Returns the status information of the node.

Input

None

Output

KeyTypeDescription
nodeIdstringNode ID
baseTimenumberBase Time
hoststringHost Address
reliablebooleanIs Reliable Node
roundTimenumberRound Time
roundCyclenumberRound Cycle
prunedRoundnumberPruned Round
roundnumberCurrent Round
epochnumberEpoch
shardIdnumberShard ID
homeShardIdnumberHome Shard ID
totalShardnumberTotal Shard Count
networkIdnumberNetwork ID
totalHeightstringTotal Height
intraPeerCountnumberIntra Peer Count
interPeerCountnumberInter Peer Count
syncStatestringSync State
detailStatestringDetail State
presyncStatestringPresync State
buildTimestringBuild Time
avgTxTimestringAverage Tx Time
rsNextRoundnumberNext RS Round
rsfnumberRSF
vmInfostringVM Info
wrsNextRoundnumberNext WRS Round
wrsHeightnumberWRS Height

getNodeInfo

Returns summary information of the node connected to the wallet.

Input

None

Output

KeyTypeDescription
shardIdnumberShard ID
roundnumberRound
hoststringHost
baseTimenumberBase Time
reliablebooleanIs Reliable
statusnumberNode Status (NodeStatus enum)
netStatusnumberNetwork Status (NodeNetStatus enum)
buildTimestringBuild Time
networkIdnumberNetwork ID
rpcFailCountnumberRPC Fail Count
genesisstringGenesis Hash

getAccountInfo

Returns detailed information of the selected account.

Input

None

Output

KeyTypeDescription
addrstringAccount Address
existAddrstringExisting Address (Optional)
statusnumberAccount Status (AccountStatus enum)
totalBalancestringTotal Balance
balancestringBalance
grantnumberGrant
identitystringIdentity
representativestringRepresentative
heightnumberHeight
unactBalancestringInactive Balance
canBecomeHostbooleanCan Become Host
canBecomeGuestbooleanCan Become Guest

getFirstVmeInfo

Returns the first VME (Validator Management Engine) information.

Input

None

Output

KeyTypeDescription
codenumberResponse Code
messagestringResponse Message
dataobjectVME Info Data

getVmeList

Returns the VME list.

Input

None

Output

KeyTypeDescription
codenumberResponse Code
messagestringResponse Message
dataarrayVME Info List

Event List


init

This event occurs once when the wallet is properly installed and ready for use.

Output

KeyTypeDescription
connectedAccountaccountConnected Account Info
addressstringCurrent selected account address
networknetworkSelected Network Info
extensionIdstringWallet's extension ID
connectedbooleanWhether the account is connected to the site

network

KeyTypeDescription
idstringNetwork ID
namestringNetwork name
rpcUrlstringRPC URL
currencySymbolstringCurrency symbol
explorerUrlstringExplorer URL

account

KeyTypeDescription
addrstringAccount Address
namestringAccount Name

connected

Occurs when the wallet is connected to the target site. (Deprecated)

Output

KeyTypeDescription
addrstringConnected account address

connect

Occurs when connected to the target site.

Output

KeyTypeDescription
addrstringConnected account address

disconnect

Occurs when the wallet is disconnected from the target site.

Output

KeyTypeDescription
addrstringDisconnected account address

connectionChanged

Occurs when the connected account is changed.

Output

KeyTypeDescription
addrstringChanged account address

accountChanged

Occurs when the account is selected.

Output

KeyTypeDescription
addrstringAccount Address

networkChanged

Occurs when the network is changed.

Output

KeyTypeDescription
idstringNetwork ID of the registered network
namestringName of the registered network
rpcUrlstringRPC URL for the registered network
currencySymbolstringDefault currency symbol for the registered network
explorerUrlstringExplorer URL for the registered network

lockWallet

Occurs when logging out from the wallet.

Output

[None]


unlockWallet

Occurs when logging into the wallet. (Deprecated)

Output

KeyTypeDescription
addrstringAddress of the logged-in account

login

Occurs when logging into the wallet.

Output

KeyTypeDescription
addrstringAddress 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

KeyTypeDescription
contractstringContract Address
resultstringExecution Result
errorstringError Message
transfersarrayToken Transfer History
callerAddrstringCaller Address
callerIndexnumberCaller Index
statenumberContract State (1: Call, 2: Execute, 3: Confirm, 4: Result Failure)

acceptConfirmation

Occurs when accepting from the wallet confirmation prompt.

Output

KeyTypeDescription
uuidstringRequest unique key
datastringExecution result

rejectConfirmation

Occurs when rejecting from the wallet confirmation prompt.

Output

KeyTypeDescription
uuidstringRequest unique key
codestring0: General
1: Rejected by user
messagestringError Message

rejectAllConfirmations

Occurs when rejecting all from the wallet confirmation prompt.

Output

KeyTypeDescription
-[]resultList of rejected requests

result

KeyTypeDescription
uuidstringRequest unique key
codestring0: General
1: Rejected by user
messagestringError Message