Nabox Chrome Extension
Install the App
Acquire Nabox Extension in Google store
Download
Acquire source code
Acquire the latest source code from GitHub: https://github.com/naboxwallet
Installation dependency
Runing locally
Packaging locally
Nabox Extension add the local package
Nabox Extension method
Check if Nabox is installed
Copy if (typeof window.nabox !== "undefined") {
console.log("nabox is installed!");
}
connect Nabox
nabox.createSession()
Return the current network address of the plug-in
Copy const naboxInfo = await nabox.createSession();
console.log(naboxInfo); //[tNULSeBaMvH8....D7oN643aBL]
Send ordinary transaction
nabox .sendTransaction(tx)
Copy 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)
Copy 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)
Copy const data = {
from: "tNULSeBaMqpRQkHCs5ur3ck4LXEZB4qmmkPNo3",
alias: 'nrc_20',
contractCode: "b2d2acecc....",
args: ["name", "symbol", ..]
}
const res = await nabox.contractCreate(data)
Call contract
nabox.contractCall(data)
Copy 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)
Copy const data = {
contractAddress: "tNULSeBaMzvqHiyBnr7c1TKYBLMHMvi1CcisAg",
methodName: "name",
methodDesc: "() return String",
args: []
}
const res = await nabox.invokeView(data)
Send contract transaction
nabox.transactionSerialize(dataInfo)
Copy 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])
Copy const res = await nabox.signMessage(["hello", "tNULSeBaMt9Tf6VvfYfvUFGVqdiyPqFLfQg9La"])
Get public key nabox.getPub({address:''})
Copy const data = {
address: "tNULSeBaMvH8TmMZUPQKvc19qeLrD7oN643aBL"
}
const naboxInfo = await nabox.getPub(data);
console.log(naboxInfo); //45641a...
Events
accountsChanged
Copy nabox.on("accountsChanged", (accounts) => {
if (accounts.length) {
console.log(accounts[0])
}
});
chainChanged
Copy nabox.on("chainChanged", (chainId) => {
console.log(chainId)
});