Skip to main content

Quick integration with everpay-js

everpay-js encapsulates most of the interfaces of everPay protocol for developers, developers can use everpay-js to quickly integrate everPay protocol into application pages. Using everpay-js, you can quickly complete everPay payment settlement in your application.

Requirements for use

info
  • This section explains how to quickly install, introduce, create, top up, transfer and withdraw funds using everpay-js.

    :::

Installation

Use yarn or npm to install and use, if not please check your network and try again.

yarn add everpay

Import

import Everpay from 'everpay'
const everpay = new Everpay()

Initialization

Smart Account Connect

Extremely easy & convenient.

1. Using the Package Manager

(1)Install everpay-js.

yarn add everpay

(2)Introduce everpay-js for creation.

import Everpay from 'everpay'

const authResult = await new Everpay().smartAccountAuth(
'https://app-dev.permaswap.network/permalogo.svg'
)
const everpay = new Everpay({
account: authResult.account,
isSmartAccount: true
})

Connecting with an ethereum wallet

  • Optional configuration items such as ethConnectedSigner, chainType, etc. can be injected during creation.
  • Developers need to install and use ethers.js to create it.
  • Please download MetaMask or other Ether wallets.

1. Using the Package Manager

(1) Install [everpay-js](. /everpay-js.md#install) and ethers.js.

yarn add everpay [email protected]

(2) Introduce everpay-js and ethers for creation.

import Everpay from 'everpay'
import { ethers } from 'ethers'

const provider = new ethers.providers.Web3Provider(window.ethereum)
const signer = provider.getSigner()
const everpay = new Everpay({
debug: true // Enable everpay development environment.
account: window.ethereum.selectedAddress,
chainType: 'ethereum',
ethConnectedSigner: signer
})

2. Connecting to an Ethernet wallet via CDN

(1) Create index.html file and introduce everpay-js and ethers to the CDN link.

<script
src="https://cdn.jsdelivr.net/npm/[email protected]/umd/index.umd.min.js"
defer
type="text/javascript"
></script>
<script
defer
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ethers.umd.min.js"
type="application/javascript"
></script>

(2) Create script tags in the index.html file and populate them according to the following code.

<script type="text/javascript" defer>
const ethRun = async () => {
// You can connect your wallet or website here if not connected yet.
const provider = new ethers.providers.Web3Provider(window.ethereum)
const signer = provider.getSigner()
const everpay = new window.Everpay.default({
debug: true // Enable everpay development environment.
account: window.ethereum.selectedAddress,
chainType: 'ethereum',
ethConnectedSigner: signer
})
}
ethRun()
</script>

Arweave Wallet Connection

  • You need to inject arJWK when creating a browser ArConnect wallet, just inject arJWK: 'use_wallet'.
  • Download the ArConnect wallet.

1. Using package management

(1) Install everpay-js.

yarn add everpay

(2) Introduce everpay-js for creation.

import Everpay from 'everpay'

const arAddress = await window.arweaveWallet.getActiveAddress()
const everpay = new Everpay({
debug: true,
account: arAddress,
chainType: 'arweave',
arJWK: 'use_wallet'
})

2. Connect to Arweave wallet using CDN

(1) Create the index.html file and introduce the everpay-js CDN link.

<script
src="https://cdn.jsdelivr.net/npm/[email protected]/umd/index.umd.min.js"
defer
type="text/javascript"
></script>

(2) Create script tags in the index.html file and populate them according to the following code.

<script>
const arRun = async () => {
// You can connect your wallet or website here if not connected yet.
const arAddress = await window.arweaveWallet.getActiveAddress()
const everpay = new window.Everpay.default({
debug: true // Enable everpay development environment.
account: arAddress,
chainType: 'arweave',
arJWK: 'use_wallet'
})
}
arRun()
</script>
info

  • Following the steps above, we have completed the creation of the Everpay application, so let's move on to top-up, transfer and withdraw funds.

:::

Deposit

Deposit your Arweave, Ethereum and other on-chain assets to everPay. Fill in the token tag and amount for the top-up and call the following interface to complete the top-up:

everpay
.deposit({
tag: 'ethereum-usdt-0x923fcb255da521037385457fb549a51f78ef0af4',
amount: '5.21'
})
.then(console.log)
info
  • Wait patiently for the block verification to be completed and you will have the corresponding property in everPay.

  • Ethereum requires 20 blocks for recharge, Arweave requires 20 blocks for recharge

  • everPay supports AR cross-chain, initialization injection ethConnectedSigner will call WAR (ERC20) for recharge, initialization injection arJWK will call AR (native) for recharge

    :::

Transfer

After the everPay instance is created successfully, you can use the transfer method to transfer the assets(token) that the current account already owns to everPay.

Fill in the token tag and amount, to required for the transfer and call the following interface to complete the transfer:

  • tag : the unique identifier of the token, which can be accessed via info interface to view.
  • amount : The amount.
  • to : The recipient address of everPay, see account-model.
everpay
.transfer({
tag: 'ethereum-usdt-0x923fcb255da521037385457fb549a51f78ef0af4',
amount: '5.21',
to: '0x26361130d5d6E798E9319114643AF8c868412859'
})
.then(console.log)
  • Please note: You are operating a transfer of assets on the everPay network, please do not transfer to an exchange address, or a contract address, or your assets will not be recovered!

    :::

Withdrawal

After the everPay instance is created successfully, you can withdraw the assets(token) you have in your current account through the withdraw method. Withdraw the token from everPay to the native chain address.

Fill in the token tag, amount, chainType, to that you want to withdraw, and call the following interface to complete the withdrawal:

  • token tag : a unique identifier that can be accessed via info interface.
  • amount : The amount.
  • chainType : chainType native chain.
  • to : everpay Recipient address, details can be found in account-model.
everpay
.withdraw({
tag: 'ethereum-usdt-0x923fcb255da521037385457fb549a51f78ef0af4',
amount: '5.26',
chainType: 'ethereum',
to: '0x26361130d5d6E798E9319114643AF8c868412859'
})
.then(console.log)
danger
  • Withdraw assets from everPay to target chains, such as Ethereum, etc.

  • Please do not withdraw to contract addresses, they cannot be recovered!

    :::

Example reference

More examples can be found in everpay-js unit test cases