How to use NebPay in your Dapp

NebPay is an officially released payment tool for Nebulas BlockChain, which could be used to meet the payment requirement in Dapp.

Dapp users need to send transactions while using a Dapp. However, it’s extremely insecure to import your wallet file or entering your private key directly into the Dapp page. Therefore Nebulas provides NebPay as an oficial payment interface. Dapp developers can use NebPay as a payment channel in their Dapp. The Dapp user needs to install a browser plug-in (desktop) or a wallet APP (mobile) to complete the payment initiated by the Dapp page.

If your Dapp page needs to interact with the Nebulas network for other non-trading information, such as querying data and subscribing to events, then you can use neb.js to communicate directly with the Nebulas BlockChain.

NebPay provides 4 payment APIs and 1 transaction query API according to different payment scenarios. Please refer to documents of NebPay to get more datailed information.

  • pay Ordinary transactions between users
  • nrc20pay NRC20 token transactions
  • deploy Deploy a smart contract (currently not supported)
  • call Call a smart contract function
  • queryPayInfo query a transaction result

When the payment API is called, a transaction serial number is returned, and the DAPP can use queryPayInfo(serialNumber) to query the result of the transaction.

How to use NebPay in your Dapp

If you want to use NebPay in your Dapp, just clone the NebPay source code from GitHub, and then pack it with gulp, and then you can get nebpay.js file under ./distdirectory. And now you can use NebPay by including it into you Dapp page.

Here is a detailed example on how to use call API of NebPay.

The format of transaction result queried by queryPayInfo(serialNumber) is a JSON string. You can deserialize it with JSON.parse() to get a JS object.

The above example is for Nebulas mainnet, and if you need to use testnet, you need to add an argument options.callback like this:

Example of Dapp using NebPay

Here is a Dapp example Using NebPay: SuperDictionary . It’s source code is on GitHub.

This video blow explains the payment process of a Dapp using Nebpay both on PC and mobile phone.

Nebulas Dapp Using NebPay SDK on PC
Nebulas Dapp Using NebPay SDK on mobile