How to use NebPay in your Dapp

yupnano
yupnano
May 8, 2018 · 2 min read

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

Nebulasio

Nebulas is an autonomous metanet.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store