DApp连接Nabox钱包(NULS)
适用于NULS系列平行链网络,例如NULS / NerveNetwork等。
安装应用
Chrome商城获取
点击下载
源码获取
从GitHub获取最新的源代码https://github.com/naboxwallet
安装依赖: npm install
本地运行: npm run serve
打包: npm run build
将打包好的文件夹添加到Chrome拓展程序
插件API
连接Nabox
nabox.createSession();
默认连接网络为当前插件所选链网络
const naboxInfo = await nabox.createSession();
console.log(naboxInfo); //[tNULSeBaMvH8....D7oN643aBL] 返回当前插件网络对应的地址
发送普通交易
nabox.sendTransaction(tx)
参数说明:
from: 发起交易地址,必须为已授权地址
to: 必填
assetChainId: 必填,链id
assetId: 必填,资产id
contractAddress: 如果是合约资产则必填
remarks: 备注
返回值:交易hash
const tx = {
from: "tNULSeBaMrxuvawQWSf7NEtadNUQGcEztwFhpu",
to: "tNULSeBaMf2kxj6EmGvu9csJLT9NjukVnXdMdg",
value: "1",
assetChainId: 2,
assetId: 1,
contractAddress: "",
remarks: ""
}
const res = await nabox.sendTransaction(tx); // 返回交易hash
console.log(res); // 753dcb3...
普通交易签名
nabox.signTransaction(tx)
参数说明:
from: 发起交易地址,必须为已授权地址
to: 必填
assetChainId: 必填,链id
assetId: 必填,资产id
contractAddress: 如果是合约资产则必填
返回值:签名hex
const tx = {
from: "tNULSeBaMrxuvawQWSf7NEtadNUQGcEztwFhpu",
to: "tNULSeBaMf2kxj6EmGvu9csJLT9NjukVnXdMdg",
value: "1",
assetChainId: 2,
assetId: 1,
contractAddress: ""
}
const res = await nabox.signTransaction(tx); // 返回签名hex
console.log(res); // 753dcb3...
创建合约(NULS)
nabox.contractCreate(data)
参数说明:
from: 发起交易地址,必须为已授权地址
alias: 选填,,合约别名
contractCode: 必填,,智能合约代码(字节码的Hex编码字符串)
args: 选填, 合约参数
返回值:{ hash: "发布合约的交易hash", contractAddress: "生成的合约地址" }
const data = {
from: "tNULSeBaMqpRQkHCs5ur3ck4LXEZB4qmmkPNo3",
alias: 'nrc_20',
contractCode: "b2d2acecc....",
args: ["name", "symbol", ..]
}
const res = await nabox.contractCreate(data)
调用合约(NULS)
nabox.contractCall(data)
参数说明:
from: 发起交易地址,必须为已授权地址
value: 选填,,转入合约的NULS数量
contractAddress: 必填,,合约地址
methodName: 必填,合约方法
methodDesc: 选填, 方法描述
args: 选填, 合约参数
multyAssetValues: 选填, 向合约地址转入的跨链资产信息, [[value, assetChainId, assetId], ...]
返回值:交易hash
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) // 返回交易hash
查看合约(NULS)
nabox.invokeView(data)
参数说明:
contractAddress: 必填,,合约地址
methodName: 必填,合约方法
methodDesc: 选填, 方法描述
args: 选填, 合约参数
const data = {
contractAddress: "tNULSeBaMzvqHiyBnr7c1TKYBLMHMvi1CcisAg",
methodName: "name",
methodDesc: "() return String",
args: []
}
const res = await nabox.invokeView(data)
发送合约交易(NULS)
nabox.transactionSerialize(dataInfo)
const dataInfo = {
address,//发送地址
inputs,//inputs
outputs,//outputs
type,//交易类型
txData,//合约交易的txData
remarks,//交易的备注信息
}
const resData = await nabox.transactionSerialize(dataInfo);
console.log(resData); //hash 8821272....d762f9c
message签名
nabox.signMessage([message, address])
参数说明:
message: 必填,需要签名内容
address: 必填,发起签名地址,必须为已授权地址
返回值:签名hex
const res = await nabox.signMessage(["hello", "tNULSeBaMt9Tf6VvfYfvUFGVqdiyPqFLfQg9La"])
获取地址公钥
nabox.getPub(data)
参数说明:
address: 必填, 必须为已授权地址
const data = {
address: "tNULSeBaMvH8TmMZUPQKvc19qeLrD7oN643aBL"
}
const naboxInfo = await nabox.getPub(data);
console.log(naboxInfo); //45641a...
发送加入共识交易
nabox.sendDepositTransaction(data)
参数说明:
from: 必填,,委托人地址
assetChainId: 必填,委托共识资产链ID
assetId:必填,委托共识资产ID
depositValue:必填,委托金额
agentHash::必填,委托共识节点hash
返回值:交易hash
const data = {
from: "tNULSeBaMrbMRiFAUeeAt6swb4xVBNyi8121"
assetChainId: "2",
assetId: "1",
depositValue: 2000,
agentHash: "62d93af0d6fd90f68bd1813f28d315324019eaf2694c39ce6cad488c5cee9361"
}
const res = await nabox.sendDepositTransaction(data); // 返回交易hash
发送退出共识交易
nabox.sendWithDrawTransaction(data)
参数说明:
from: 必填,委托人地址
assetChainId: 必填,委托共识资产链ID
assetId:必填,委托共识资产ID
withdrawAmount:必填,委托退出金额
depositHash::必填,加入共识交易hash
返回值:交易hash
const data = {
from: "tNULSeBaMrbMRiFAUeeAt6swb4xVBNyi8121"
assetChainId: "2",
assetId: "1",
withdrawAmount: 2000,
depositHash: "62d93af0d6fd90f68bd1813f28d315324019eaf2694c39ce6cad488c5cee9361"
}
const res = await nabox.sendWithDrawTransaction(data); // 返回交易hash
事件监听
账户切换
nabox.on("accountsChanged", (accounts) => {
if (accounts.length) {
console.log(accounts[0])
}
});
网络切换
nabox.on("chainChanged", (chainId) => {
console.log(chainId)
});
Last updated