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.

  1. Install the viem library

npm install viem --save
  1. Create 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.

  1. Install the WalletConnect library

  1. Create a WalletConnect instance

For more operations, please visit web3modal directly.

Community communication

Telegram https://t.me/CocosStudioCommunity

Last updated