Pay3 Documentation

⌘
K
Overview
Pay3-EasySign
Pay3-Pay
Getting Started
Onboarding
Quick Start
Terminologies
Pay3 Javascript SDK
Initialize
Functions
Transactions
Event Listeners
End User Flow
Easy Sign
Buy Game Tokens
Sell Game Tokens
NFT Checkout
User Portfolio
User Transactions
SDK Errors
Webhooks
Docs powered by Archbee
Pay3 Javascript SDK

Functions

8min

pay3.connect()

Opens login modal of Pay3 web wallet. User will be able to connect to the wallet using Social, Email & Phone OTP or Wallet connect.

On completion of connecting pay3-sdk-login-status event is published to the DApp.

index.js
// Open Pay3 Login Modal
pay3.connect();


pay3.isConnected()

Return true if the user has successfully connected with Pay3 Wallet, else returns false.

index.js
const isLoggedIn = pay3.isConnected();


pay3.getAccount()

Returns wallet address of the connected wallet.

index.js
const address = pay3.getAccount();


pay3.getBalance({rpcURL [, tokenAddress]})

Returns logged in user's balance in the connected chain. It accepts an optional ERC20 Address in which case it returns user token address balance on the chain. The amount is returned is in WEI.

Parameters

  1. rpcUrl: You can pass your favourite rpcUrl that matches your dApp's chain. This URL is used for reading data from block chain from the JS sdk with in the dApp's / client application context.
  2. tokenAddress (Type string, Optional): Address of any ERC20 token available on the connected chain. If tokenAddress is undefined the function returns coin balance of the connected user.
    

Get chain native coin balance

index.js
// Returns the native currency of the network held by the connected user. The returned value is in Wei 
const coinBalanceInWei = await pay3.getBalance({
          rpcURL: "https://your-rpc-url.com" });
// { BigNumber: "172334002436162568" }


Get ERC20 token balance

index.js
const USDC_ADDR = "0xB8c77482e45F1F44dE1745F52C74426C631bDD52";
const usdcBalanceInWei = await pay3.getBalance({
     tokenAddress: USDC_ADDR,
     rpcURL });
// { BigNumber: "172334002436162568" }


// To convert wei in ether use
import {ethers} from 'ethers';
const usdcBalanceInEth = ethers.utils.formatEther(usdcBalanceInWei)
// '0.172334002436162568


pay3.readContract({contractAddress, abi, functionName [, args]}, rpcURL)

Pay3 readContract is a helpful utility which accepts parameters for read functionality for any contract interaction deployed on blockchain. This uses the rpcUrl passed in the constructor to interact with blockchain.

Parameters

  1. Contract Details
    1. contractAddress (string): Contract address deployed on the connected chain.
    2. abi (Array of Objects): ABI of the function that is being called.
    3. functionName (string): Name of the function that need to be invoked.
    4. args (Array of Objects: Optional): List of arguments to be passed while invoking the function.
  2. rpcUrl (string): You can pass your favourite rpcUrl that matches your dApp's chain.
index.js
import { erc20ABI } from 'wagmi';
const WMATIC_ADDRESS_MUMBAI = '0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889';
const UNISWAP_ADDRESS_MUMBAI = '0x000000000022D473030F116dDEE9F6B43aC78BA3';
const rpcUrl = "https://rpc.ankr.com/polygon_mumbai";


// 1. Example of an ERC20 contract function call without arguments 
// Get Total Wrapped Matic Supply 
const data = await pay3.readContract({ 
  contractAddress: WMATIC_ADDRESS_MUMBAI, 
  abi: erc20ABI, 
  functionName: "totalSupply" 
}, rpcUrl);
console.log("Total Supply of WMatic: ", data.toString());


// 2. Example of an ERC20 contract function call with arguments
// Get Wrapped Matic allowance given by connected user to a Uniswap Contract on Polygon Mumbai testnet 
const ownerAddress = pay3.getAccount();
const spenderAddress = UNISWAP_ADDRESS_MUMBAI;

const data = await pay3.readContract({
  contractAddress: WMATIC_ADDRESS_MUMBAI,
  abi: ERC20ABI,
  functionName: "allowance",
  args: [ownerAddress, spenderAddress] 
}, rpcUrl);
console.log("Allowance given on WMatic to Uniswap: ", data.toString());


pay3.disconnect()

Opens Pay3 Web Wallet and triggers logout for the user. Emits pay3-sdk-login-status event.

On completion of disconnect pay3-sdk-login-status ,event is published to the DApp.

index.js
// Open Pay3 Modal and trigger logout
pay3.disconnect();




Updated 10 Nov 2023
Did this page help you?
PREVIOUS
Initialize
NEXT
Transactions
Docs powered by Archbee
TABLE OF CONTENTS
pay3.connect()
pay3.isConnected()
pay3.getAccount()
pay3.getBalance({rpcURL [, tokenAddress]})
pay3.readContract({contractAddress, abi, functionName [, args]}, rpcURL)
pay3.disconnect()
Docs powered by Archbee