DApp connects to Nabox Wallet (BCH/FCH)
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
Runing locally
Packaging locally
Nabox Extension add the local package BCH/FCH Provider Integration Protocol
Key Variables Description
The Provider Object is used by the DApp business side and offers two ways to interact:
window.naboxBch
|window.naboxFch
window.NaboxWallet.bch
|window.NaboxWallet.fch
Methods Required via postMessage
getPub
Parameters: None
Returns: The public key of the current user's address
getBalance
Parameters: None
Returns: The balance of the current user's address
signMessage
Parameters: A string that needs to be signed
Returns: The signed string
sendTransaction
Parameters: A JSON object
to
: Transfer addressamount
: Transfer amountmsg
: Attached remark
Returns: Transaction hash (
txHash
)
Wallet Address Injection into the DApp Page
After the DApp page loads, the current wallet address is passed to the page object using the following method:
Download fch-provider-min.js
Getting Started
Select the BCH or FCH network in Nabox Wallet.
Open the DApp page in the browser.
Nabox Wallet will inject a
naboxBch
ornaboxFch
object into the DApp page'swindow
object.The DApp can communicate with Nabox Wallet through this object.
Example:
API Introduction
Connect Wallet
Method:
createSession
Parameters: None
Returns:
{”selectedAddress”: address}
Note: In the app, this method doesn't need to be called. The wallet is connected by default. If there is no address, call this method:
Get Current User's Account Address
Method:
getAddress
Parameters: None
Returns:
string
Example:
Get Current Address Public Key
Method:
getPub
Parameters: None
Returns:
string
Example:
Get Current User's Account Balance
Method:
getBalance
Parameters: None
Returns:
number
Example:
Send Transaction
Method:
sendTransaction
Parameters: JSON object
to
: Recipient addressamount
: Transfer amountmsg
: Additional transaction info (remark)
Returns: Transaction hash (string)
Example:
Sign a String
Method:
signMessage
Parameters: A string to be signed
Returns: Signed string (hex format)
Example:
Demo
Download
To run the demo, you need to install the Node.js environment. After extracting, run:
npm install
npm run start
Steps:
Access: http://localhost:8080
In the top input box, import a test private key to begin testing the following use cases.
Note: The demo simulates a Nabox Wallet environment. In actual business environments, you don't need to reference fch-min.js
, fch-provider-min.js
, or app-mock.js
in the HTML file.
Last updated