Through BlockChain RPC to call Pharos contract
Get the RPC Address
First, visit https://zan.top/service/apikeys to obtain the RPC address for the Pharos chain:
You need to log in to ZAN, which will automatically create a free Access Key for you. The process is similar for most other Blockchain RPC service providers—you’ll first need to obtain an address, which serves as the Endpoint for calling RPC services.
Access via Command Line
You can use the following code in a Shell command line to test the RPC connectivity:
curl --location 'https://api.zan.top/node/v1/pharos/testnet/${YOUR_ACCEEE_KEY}' \
--header 'Content-Type: application/json' \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
Note that ${YOUR_ACCEEE_KEY}
should be replaced with your own key. Alternatively, you can directly run the code provided on the ZAN website.
You should then see output similar to the following:
{"result":"0xdfedf7","id":1,"jsonrpc":"2.0"}
This indicates that the RPC call was successful.
Call Contracts via JS SDK
Pharos is an EVM-compatible Layer 1 blockchain, so it fully supports Ethereum’s ecosystem. You can use SDKs like Viem or Ethers to interact with contracts. For frontend development (e.g., React), you can also leverage SDKs and component libraries like wagmi and Ant Design Web3.
For example, with Viem, you can initialize the SDK and call the getBlockNumber
method as follows:
import { createPublicClient, http, defineChain } from 'viem'
// 1. Define Pharos chain configuration
const pharos = defineChain({
id: 688688, // Pharos Testnet chainId
name: 'Pharos Testnet',
nativeCurrency: {
name: 'Ether',
symbol: 'ETH',
decimals: 18,
},
rpcUrls: {
default: { http: ['https://api.zan.top/node/v1/pharos/testnet/${YOUR_ACCEEE_KEY}'] },
},
blockExplorers: {
default: { name: 'Pharos Explorer', url: 'https://pharos-testnet.socialscan.io/' },
},
})
// 2. Create PublicClient
const publicClient = createPublicClient({
chain: pharos,
transport: http(), // If no URL is provided, it defaults to pharos.rpcUrls.default.http[0]
})
// 3. Usage
const blockNumber = await publicClient.getBlockNumber()
console.log('Pharos block number:', blockNumber)
For Pharos chain details, refer to:
https://docs.pharosnetwork.xyz/network-overview/pharos-networks
To interact with contracts, you can use the SDK’s readContract
, simulateContract
, and writeContract
methods.
readContract
: Under the hood, this calls Ethereum’s JSON-RPCeth_call
method. It does not consume gas and does not submit transactions to the chain—used for read-only contract calls.writeContract
: Callseth_sendTransaction
for contract methods that modify state.simulateContract
: Viem simulates write operations by callingeth_call
+eth_estimateGas
.
For writeContract
, signing is required. Initialize the wallet client as follows:
import { wagmiAbi } from './abi'
import { createWalletClient, custom } from 'viem'
// ...
const { request } = await publicClient.simulateContract({
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
args: [69420],
account
})
await walletClient.writeContract(request)
Configure Wallet RPC
Wallets also need to interact with the chain. You can configure a custom network in your wallet to use a custom RPC service. Below is an example using MetaMask:
- Click the network dropdown in the top-left corner of the wallet.
- Edit an existing network or add a custom network.
- Add the Pharos Testnet to MetaMask:
This ensures that transactions and requests from the wallet use ZAN’s RPC service. This is particularly useful for users with specific speed and performance requirements. Additionally, this method allows adding chains that are not natively supported by the wallet.