Using EVM in Cocos Creator
Using the viem library
Cocos Creator 3.8.3 and above versions are compatible with the viem library, you can use it directly.
Install the viem library
npm install viem --saveCreate an EVM instance
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(), // http() is a public client, you can also use a wallet client by replacing it with custom(window.ethereum!)
})
// Get the current block height
const blockNumber = await client.getBlockNumber() For more operations, please visit the viem official website directly.
Using WalletConnect's web3modal
The official web3modal is not compatible with Cocos Creator, so we have repackaged the web3modal library and it can now be used directly. Currently, version 5.1.6 is supported.
Install the WalletConnect library
Create a WalletConnect instance
For more operations, please visit web3modal directly.
Community communication
Telegram https://t.me/CocosStudioCommunity
PreviousUsing Ton in Cocos CreatorNextQuick Integration Guide for Alchemy Pay Ramp Fiat-to-Crypto Payment Solution
Last updated