Provider API
NaboxWallet.nuls provider is gradually deprecated, please use or upgrade to the latest NaboxWallet.nai provider.
createSession (connect to Nabox wallet)
const res = NaboxWallet.nai.createSession();
// [NULSd6Hge.........8apXDR]
sendTransaction (send normal transaction)
const txParameters = {
from: 'NULSd6Hge.........8apXDR', //The transaction initiation address is required and must be an authorized address
to: '', // Required, receiving address
value: '', // Required, transfer amount (Note: use nai provider value as the smallest unit, nuls provider is the actual transfer amount)
assetChainId: '',// Required, chain id, you can get the corresponding asset ID information through the browser
assetId: '', // Required, asset ID, you can get the corresponding asset ID information through the browser.
contractAddress: '', // Required if it is a contract asset
remarks: 'reamrk' // Remark
};
const hash = await Nabox.nai.sendTransaction(txParameters); // Return hash
// 753dcb3...
signTransaction (signing ordinary transactions)
const txParameters = {
from: 'NULSd6Hge.........8apXDR', //The transaction initiation address is required and must be an authorized address
to: 'NULSd6Hge.........8apXDR', // Required, receiving address
value: '', // Required, transfer amount (Note: use nai provider value as the smallest unit, nuls provider is the actual transfer amount)
assetChainId: '',// Required, chain id, you can get the corresponding asset ID information through the browser.
assetId: '', // Required, asset ID, you can get the corresponding asset ID information through the browser
contractAddress: '', // Required if it is a contract asset
remarks: 'reamrk' // Remark
};
const txHex = await Nabox.nai.signTransaction(txParameters); // Return the signed txHex, and broadcast to get the hash
// 020000000000.............
signTxHex(signature txHex)
const txParameters = {
address: 'NULS...', // The address of the current connection
txHex: '020000000000.........' // NULS AI/NERVE txHex
};
const signedHex = await NaboxWallet.nai.signTxHex(txParameters);
// Return the signed txHex
signNULSTransaction (sign NULS AI Ledger transaction)
const txParameters = {
txHex: '020000000000.........' // NULS AI/NERVE txHex
};
const signedHex = await NaboxWallet.nai.signTxHex(txParameters);
// Return the signed txHex
contractCreate (create NULS AI contract)
const data = {
from: 'NULSd6Hge.........8apXDR', // The transaction initiation address must be an authorized address
alias: 'nec20', // Optional, contract alias
contractCode: 'b2d2acecc....', // Required, smart contract code (Hex encoded string of bytecode)
args: ["name", "symbol", ..] // Optional, contract parameters
};
const res = await NaboxWallet.nai.contractCreate(data);
// res示例
{
hash: '753dcb3.....', // The transaction hash that created the contract
contractAddress: 'NULS.....' // The contract address created
}
contractCall (call contract)
const data = {
from: "NULSeBaMqpRQkHCs5ur3ck4LXEZB4qmmkPNo3", // Call address, must be an authorized address
value: 0, // Required, NAI quantity (Note: use nai provider value as the smallest unit, nuls provider as the actual amount)
contractAddress: "NULSeBaMzvqHiyBnr7c1TKYBLMHMvi1CcisAg", // Required, the contract address to be called
methodName: "transfer", // Required, the contract method to be called
methodDesc: "(Address to, BigInteger value) return boolean", // Optional, method description
args: ["tNULSeBaMt9Tf6VvfYfvUFGVqdiyPqFLfQg9La", "2"] // Required, calling parameters
multyAssetValues: [[value,assetChainId,assetId], ...] // Optional, cross-chain asset information transferred to the contract address (note: use nai provider value as the minimum unit, nuls provider as the actual amount)
};
const hash = await NaboxWallet.nai.contractCall(data);
// '753dcb3.....'
invokeView (view contract)
const data = {
contractAddress: "NULSeBaMzvqHiyBnr7c1TKYBLMHMvi1CcisAg", // Required, contract address
methodName: "name", // Required, contract method
methodDesc: "() return String", // Optional,method description
args: [] // Optional
}
const res = await nabox.invokeView(data);
transactionSerialize(transaction Serialize)
Send the assembled transaction.
const txParameters = {
address, // Shipping Address
inputs, // inputs
outputs, // outputs
type, // Transaction Type
txData, // txData of contract transaction
remarks, // Transaction notes
};
const hash = await NaboxWallet.nai.transactionSerialize(txParameters);
// '753dcb3.....'
signMessage(Message Signature)
const hex = await NaboxWallet.nai.signMessage([message, address]);
// Return the signed message
getPub (get the public key of the currently connected account)
const pub = await NaboxWallet.nai.getPub();
// 00149393d565.................2c2f2bf04d2700
sendDepositeTransaction (send NAI pledge transaction)
const depositeData = {
from: "NULSeBaMrbMRiFAUeeAt6swb4xVBNyi8121" // Required, the account address of the current connection
assetChainId: "1", // Required, chain id
assetId: "1", // Required, asset id
depositValue: 200000000000, // Required, pledge quantity,(Note: Use nai provider value as the smallest unit and nuls provider as the actual amount)
agentHash: "62d93af0d6fd90f68bd1813f2......af2694c39ce6cad488c5cee9361" // Delegated node hash
}
const hash = await NaboxWallet.nai.sendDepositTransaction(depositeData); // Return transaction hash
// '753dcb3.....'
sendWithDrawTransaction
const withdrawData = {
from: "NULSeBaMrbMRiFAUeeAt6swb4xVBNyi8121" // Required, the account address of the current connection
assetChainId: "1", // Required, chain id
assetId: "1", // Required, asset id
withdrawAmount: 200000000000,// Required, pledge quantity,(Note: Use nai provider value as the smallest unit and nuls provider as the actual amount)
depositHash: "62d93af0d6fd90f68bd181........694c39ce6cad488c5cee9361" // Required, add consensus transaction hash
};
const hash = await NaboxWallet.nai.sendWithDrawTransaction(depositeData); // Return transaction hash
// '753dcb3.....'
on(event monitoring)
// Account Switching
NaboxWallet.nai.on("accountsChanged", (accounts) => {
if (accounts.length) {
console.log(accounts[0]);
// NULS.......
}
});
Last updated