DApp connects to Nabox Wallet (BCH/FCH)
Last updated
Was this helpful?
Last updated
Was this helpful?
Nabox Chrome Extension
Acquire the latest source code from GitHub:
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 address
amount
: Transfer amount
msg
: 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
Select the BCH or FCH network in Nabox Wallet.
Open the DApp page in the browser.
Nabox Wallet will inject a naboxBch
or naboxFch
object into the DApp page's window
object.
The DApp can communicate with Nabox Wallet through this object.
Example:
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 address
amount
: Transfer amount
msg
: 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:
Download
To run the demo, you need to install the Node.js environment. After extracting, run:
npm install
npm run start
Steps:
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.
Access: