1.4.0 • Published 2 months ago

@platonnetwork/platon-wallet-sdk v1.4.0

Weekly downloads
-
License
-
Repository
-
Last release
2 months ago

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' })
})
1.4.0

2 months ago

1.3.5

4 months ago

1.3.4

4 months ago

1.3.3

4 months ago

1.2.0

9 months ago

1.1.0

10 months ago

1.3.2

6 months ago

1.3.1

7 months ago

1.3.0

7 months ago

1.2.1

9 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

12 months ago

1.0.0

12 months ago