Using Ethers.js or Web3.js with the Wepin Provider allows you to interact with EVM-compatible blockchain networks.
Supported Networks
Installation
First, import @wepin/widget-sdk and @wepin/provider into your peoject.
// You must import the widget-sdk first.import'@wepin/widget-sdk'import'@wepin/provider'
Initialize Web3.js
First, initialize Wepin, then obtain the provider to initialize web3.js.
// Import the web3.js first.import Web3 from'web3';constappId='app_id_eg12sf3491azgs520'// Test App IDconstappKey='ak_test_ghq1D5s1sfG234sbnhdsw24mnovk313'// Test App Keyconstattributes= { type:'show'}// Initialize WepinawaitWepin.init(appId, appKey, attributes)// Obtain the provider from the initialized Wepin.constprovider=Wepin.getProvider({ network:'ethereum' });// Initialize web3 using the Wepin provider.constweb3=newWeb3(provider)
Methods
Get Accounts
Through the initialized web3, you can retrieve account information.
constaccounts=awaitweb3.eth.getAccounts()
Get Balance
Using the account information, you can query the balance.