Quick Start
Get started with Pay3 Javascript SDK with a few lines of code. Pay3 SDK is designed to work in any javascript-based client-side application and work with most of the popular frontend frameworks including React, Flutter, React Native, Unity, etc
The Pay3 SDK is available at the public npm registry @pay3/sdk . It depends on the npm package ethers library for some of its read functions. You can install and add to your dApp using the following command.
Follow these instructions for an end to end signup and payment solution provided by Pay3. In case the dApp demands Payment only solution or Onboarding only solution follow the SDK reference section.
Import the package installed in the previous step using import directive. Create a instance of Pay3 by passing the parameters you received during onboarding. Reference
Connect opens Pay3 Web modal and present users with various login options including Email, Phone, Social and hundreds of Web3 wallets. Once login is successful, the JS SDK emits pay3-sdk-login-status event and the Web modal closes. Reference
Pay3 SDK emits real-time events to the dApp. Following sample shows how to listen to login status changed event. Pay3 uses npm module events to emit these events. Refer Event Listeners for all event types.
Once wallet is connected, the SDK can fetch coin and ERC20 token balance using getBalance(). Here the SDK uses the rpcUrl passed to fetch the balance from network (try using rpc urls from Chainlist). Reference
Pay3 Web Modal provides a comprehensive digital asset purchase buy flow. User is able to choose to buy the digital asset using their existing on-chain digital assets or Fiat.
The request object requires a string requestId . This will be passed back along with the event emitted on completion of the buy flow. Detailed documentation of openBuy is present at Reference.
On completion of the transaction flow an event is emitted with type pay3-sdk-transaction-status. The event data consists of fields status which is set to 'SUCCESS' when transaction is completed successfully. The orderId is Pay3's transaction ID and requestId is the unique string passed by dApp in openBuy call. The receipt is a transaction receipt returned from the blockchain. Reference
Show the transaction list of the user within Pay3 Web Modal. User also ha an option to see details of a specific transaction and get help regarding a transaction from the modal. Reference
The dApp can provide a logout feature for its users using the disconnect() function. As in the case of connect() function, this action will emit loginStatusChanged event. Reference