@platonnetwork/platon-wallet-sdk
v1.4.0
Published
Integrate our SDK to your dApp/Wallet/swap UI.
Downloads
489
Readme
Wallet SDK
Integrate our SDK to your dApp/Wallet/swap UI.
Installation
# Using npm
$ npm install '@platonnetwork/platon-wallet-sdk'
# Using yarn
$ yarn add '@platonnetwork/platon-wallet-sdk'
# Using pnpm
$ pnpm add '@platonnetwork/platon-wallet-sdk'
Example usage
CSR
import PlatONWallet from '@platonnetwork/platon-wallet-sdk'
// Definition PlatONWallet SDK
const walletSDK = new PlatONWallet({
env: 'PROD', // optional, 'PROD' or 'TEST', default to 'PROD'
theme: 'auto', // optional, 'auto', 'light' or 'dark', default to 'auto'
})
// Initialization PlatONWallet SDK
walletSDK.init({
walletType: 'METAMASK', // 'METAMASK', 'PARTICLE', 'WALLETCONNECT', 'UNIPASS'
walletProvider: window.ethereum, // eip1193 ethereum provider
})
// other methods
walletSDK.hide()
walletSDK.show()
walletSDK.destroy()
// When you switch from the MetaMask wallet to connect to another wallet
// particle example, @particle-network/connect-react-ui, @wagmi/core and @particle-network/connect packages expose the provider in a different way, refer their docs for details
const pn = new ParticleNetwork({
projectId: 'your project id',
clientKey: 'your client key',
appId: 'your app id',
wallet: {
displayWalletEntry: false,
},
}) // import { ParticleNetwork } from '@particle-network/auth'
const particleProvider = new ParticleProvider(pn.auth) // import { ParticleProvider } from '@particle-network/provider'
walletSDK.setWalletOption({
walletType: 'PARTICLE',
walletProvider: particleProvider,
})
// walletconnect example, @wagmi/core and @web3modal/ethereum packages expose the provider in a different way, refer their docs for details
const supportedRpcMap = await wallet.getSupportedChainsMap() // walletconnect required
const wcProvider = await EthereumProvider.init({
// import { EthereumProvider } from '@walletconnect/ethereum-provider'
projectId: 'your project id',
chains: [
...Object.keys(supportedRpcMap).map((item) => +item),
// your own chains
],
rpcMap: {
...supportedRpcMap,
// your own rpc map
},
showQrModal: true,
qrModalOptions: {
themeVariables: {
'--wcm-z-index': '9999',
},
},
})
walletSDK.setWalletOption({
walletType: 'WALLETCONNECT',
walletProvider: wcProvider,
})
// When you are not connected to any wallet
walletSDK.setWalletOption({
walletType: '',
walletProvider: null,
})
next.js
let walletSDK = null
import('@platonnetwork/platon-wallet-sdk').then((module) => {
walletSDK = new module.default({ env: 'PROD' })
})