EVM-Compatible Networks
Using Ethers.js or Web3.js with the Wepin Provider allows you to interact with EVM-compatible blockchain networks.
Supported Networks
1
Ethereum Mainnet
ethereum
5
Ethereum Goerli Testnet
evmeth-goerli
11155111
Ethereum Sepolia Testnet
evmeth-sepolia
19
Songbird Canary Network
evmsongbird
137
Polygon Mainnet
evmpolygon
80002
Polygon Amoy
evmpolygon-amoy
1001
Klaytn Testnet
klaytn-testnet
8217
Klaytn Mainnet
klaytn
2731
TimeNetwork Testnet
evmtimenetwork-testnet
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';
const appId = 'app_id_eg12sf3491azgs520' // Test App ID
const appKey = 'ak_test_ghq1D5s1sfG234sbnhdsw24mnovk313' // Test App Key
const attributes = {
type: 'show'
}
// Initialize Wepin
await Wepin.init(appId, appKey, attributes)
// Obtain the provider from the initialized Wepin.
const provider = Wepin.getProvider({ network: 'ethereum' });
// Initialize web3 using the Wepin provider.
const web3 = new Web3(provider)
Methods
Get Accounts
Through the initialized web3
, you can retrieve account information.
const accounts = await web3.eth.getAccounts()
Get Balance
Using the account information, you can query the balance.
const balance = await web3.eth.getBalance(accounts[0])
You can refer to the link below to query not only the balance but also fee information, block number, etc.
Send Transaction
You can send transactions.
const accounts = await web3.eth.getAccounts()
const tx = {
from: accounts[0],
gasPrice: "2000000000",
gas: "21000",
to: '0x11f4d0A3c1......13F7E19D048276DAe',
value: "10000000000000000",
}
const response = await web3.eth.sendTransaction(tx)
Contract Call
You can perform contract calls.
const callObject = {
to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', //contract address
data: '0xc6888fa10000000000000000000000000000000000000000000000000000000000000003'
}
const response = await web3.eth.call(callObject)
For more details on the Ethereum-compatible network provider, please refer to the link below.
Last updated
Was this helpful?