DApp connects to Nabox Wallet (NULS)
Nabox Chrome Extension
Install the App
Acquire Nabox Extension in Google store
Acquire source code
Acquire the latest source code from GitHub: https://github.com/naboxwallet
Installation dependency
npm install
Runing locally
npm run serve
Packaging locally
npm run build
Nabox Extension add the local package
Nabox Extension method
Check if Nabox is installed
if (typeof window.nabox !== "undefined") {
console.log("nabox is installed!");
}
connect Nabox
nabox.createSession()
Return the current network address of the plug-in
const naboxInfo = await nabox.createSession();
console.log(naboxInfo); //[tNULSeBaMvH8....D7oN643aBL]
Send ordinary transaction
nabox .sendTransaction(tx)
Params
Description
from
Required, the currently connecting account
to
Required, receiving address
assetChainId
Required, chain id
assetId
Required, asset id
contractAddress
Optional, if it is a contract asset
remarks
optional
const tx = {
from: "tNULSeBaMrxuvawQWSf7NEtadNUQGcEztwFhpu",
to: "tNULSeBaMf2kxj6EmGvu9csJLT9NjukVnXdMdg",
value: "1",
assetChainId: 2,
assetId: 1,
contractAddress: "",
remarks: ""
}
const res = await nabox.sendTransaction(tx); //
console.log(res); // 753dcb3... // hash
Ordinary transaction signature
nabox .signTransaction(tx)
Params
Description
from
Required, the currently connecting account
to
Required, receiving address
assetChainId
Required, chain id
assetId
Required, asset id
contractAddress
Optional, if it is a contract asset
const tx = {
from: "tNULSeBaMrxuvawQWSf7NEtadNUQGcEztwFhpu",
to: "tNULSeBaMf2kxj6EmGvu9csJLT9NjukVnXdMdg",
value: "1",
assetChainId: 2,
assetId: 1,
contractAddress: ""
}
const res = await nabox.signTransaction(tx);
console.log(res); // 753dcb3... // hex
Contract Create
nabox.contractCreate(data)
Params
Description
from
Required, the currently connecting account
alias
Required, contract alias
contractCode
Required, ContractCode
args
Optional
const data = {
from: "tNULSeBaMqpRQkHCs5ur3ck4LXEZB4qmmkPNo3",
alias: 'nrc_20',
contractCode: "b2d2acecc....",
args: ["name", "symbol", ..]
}
const res = await nabox.contractCreate(data)
Call contract
nabox.contractCall(data)
Params
Description
from
Required, the currently connecting account
value
Required, The number of NULS transferred into the contract
contractAddress
Required, Contract address
methodName
Required
methodDesc
Optional
args
Optional
multyAssetValues
Optional, Cross-chain asset information transferred to the contract address
const data = {
from: "tNULSeBaMqpRQkHCs5ur3ck4LXEZB4qmmkPNo3",
value: 0,
contractAddress: "tNULSeBaMzvqHiyBnr7c1TKYBLMHMvi1CcisAg",
methodName: "transfer",
methodDesc: "(Address to, BigInteger value) return boolean",
args: ["tNULSeBaMt9Tf6VvfYfvUFGVqdiyPqFLfQg9La", "2"],
multyAssetValues: [[value,assetChainId,assetId], ...]
}
const res = await nabox.contractCall(data)
View contract
nabox.invokeView(data)
Params
Description
contractAddress
Required, Contract address
methodName
Required
methodDesc
Optional
args
Optional
const data = {
contractAddress: "tNULSeBaMzvqHiyBnr7c1TKYBLMHMvi1CcisAg",
methodName: "name",
methodDesc: "() return String",
args: []
}
const res = await nabox.invokeView(data)
Send contract transaction
nabox.transactionSerialize(dataInfo)
let = dataInfo{
inputs,//inputs
outputs,//outputs
remarks,//Remarks of the transaction info
type,//type of the transaction
txData,//The txData of Contract transaction
address,//sending address
}
let resData = await nabox.transactionSerialize(dataInfo);
console.log(resData); //hash 882127eb36462....d762eed115f9c
Sign message
nabox.signMessage([message, address])
Params
Descriptions
message
Required
address
Required(Authorized address)
const res = await nabox.signMessage(["hello", "tNULSeBaMt9Tf6VvfYfvUFGVqdiyPqFLfQg9La"])
Get public key nabox.getPub({address:''})
Params
Description
address
Required(Authorized address)
const data = {
address: "tNULSeBaMvH8TmMZUPQKvc19qeLrD7oN643aBL"
}
const naboxInfo = await nabox.getPub(data);
console.log(naboxInfo); //45641a...
Events
accountsChanged
nabox.on("accountsChanged", (accounts) => {
if (accounts.length) {
console.log(accounts[0])
}
});
chainChanged
nabox.on("chainChanged", (chainId) => {
console.log(chainId)
});
Last updated
Was this helpful?