Pay3 Javascript SDK

Transactions

11min

pay3.openBuy(transactionObj, provider)

This function opens Pay3 buy crypto modal. The Buy modal will guide the user through the digital asset purchase flow. This function accepts optional second parameter provider for the client that is configured in Payment only mode.

Once the purchase is completed sdk will publish pay3-sdk-transaction-status event.

Parameters

  1. transactionObj
    1. requestId (Type string): Dapp needs to provide a unique string for every new buy request triggered by the user. This will be passed back to the dApp along with completed event data.
    2. nftData (Type Object, Optional): This is an optional parameter. Can be used to improve presentation of NFT buy flow. Keys expected in this object are:
      1. The address is the NFT collection address. Used for fetching Image of NFT.
      2. The nftId is the unique ID of the NFT within the collection. Used for fetching Image of NFT.
      3. The nftName is the name of the NFT. This will be used in the buy flow to keep user context.
      4. The nftType param helps in classifying NFT based on the ERC type. It can take number values 721 or 1155
    3. destination (Type Object, Optional): Destination object can be optionally passed to Pay3 payment module if the dApp needs the deposit of the purchased currency in address other than user address. Keys expected in this object are:
      1. The address is the destination wallet address used in the purchase. For transaction safety, we need to whitelist possible destination addresses during onboarding.
      2. The currency is Pay3's unique string ID denoting the token that needs to be purchased. Example value are matic_mumbai, weth_polygon.
      3. The amount in Etherium user needs to purchase. If the value is passed user edit this within Pay3 buy flow.
  2. provider(Type Web3 Provider, Optional): In Payments Only mode, dApp can provide a Web3 provider from the user's connected wallet. Refer sample code to get provider for example code. In this mode Pay3 Web SDK will provide transaction related features. The digital assets will be managed within the wallet connected to the dApp. The provider object needs at least following functions
    1. getSigner()
    2. getNetwork()
    3. listAccounts()

Game token Buy flow with integrated Pay3 Wallet

index.js


Token buy flow where destination address is Game's wallet address

index.js


Payments Only mode - NFT buy flow where Game transfer's NFT to its user on receiving the amount passed in destination object.

index.js


pay3.openOnRamp(transactionObj)

The Dapp can use openOnRamp to use Pay3's On Ramp only solution. The Pay3 modal will guide user through On Ramp flow with its destination address defined by the Dapp.

index.js


pay3.openSell({requestId})

Opens sell game token screen. It requires a unique requestId as parameter.

index.js


pay3.openTransactions()

Show current and previous transactions of the connected user.

index.js


pay3.openPortfolio()

Opens portfolio screen for the connected user. This displays all the assets owned by the user's wallet and their balances. This will show both fungible and non-fungible assets. There will be options to customise the portfolio page as per the game.

index.js


pay3.sendTransaction(transaction: TransactionSpecs)

This triggers opening of Pay3 transaction model once user is connected to Pay3 Wallet. dApp can call trigger any transaction with connected Pay3 Wallet. This provides a single interface to interact with Web2 and Web3 wallets.

On completion of the transaction, pay3-sdk-sendtxn-status event is published to the dApp.

Parameters:

  1. requestId (Type string): dApp needs to provide a unique string for every new transaction request triggered by the user. This will be passed back to the Dapp along with completed event data
  2. to (Type string): Contract address of which the function needs to be executed
  3. value(Type string): Coin amount to be spent in gwei while invoking the function
  4. functionName (Type string): Contract function name that needs to be called
  5. args (Type Array of Objects): Arguments to be passed while calling the function
  6. userMessage (Type string): Information text message for user shown while confirming the transaction in the Pay3 wallet.
index.js


Sample Code to get Provider

Sample code to get Web3 provider from browser injected wallet like Metamask

JS


Sample code to get Web3 provider from Wagmi

JS




Updated 25 Mar 2024
Doc contributor
Did this page help you?