@@ -21,6 +21,7 @@ Change `TOKEN` to any ERC-20 address on testnet. The default is **WCFX** (Wrappe
2121// WCFX (Wrapped CFX) — always-live ERC-20 on Conflux eSpace testnet
2222const TOKEN = '0x2ed3dddae5b2f321af0806181fbfa6d049be47d8'
2323const HOLDER = '0x85d80245Dc02f5a89589e1f19C5c718E405B56Aa'
24+ const SPENDER = '0x33e5E5B262e5d8eBC443E1c6c9F14215b020554d' // AutomationManager testnet
2425
2526const client = new EspaceClient({
2627 chainId: EVM_TESTNET.id,
@@ -29,30 +30,31 @@ const client = new EspaceClient({
2930
3031console.log('-- Token: ' + TOKEN + ' --')
3132
32- // Batch-read all standard ERC-20 metadata in one round-trip
33- const [name, symbol, decimals, totalSupply] = await Promise.all([
34- client.publicClient.readContract({ address: TOKEN, abi: ERC20_ABI, functionName: 'name' }),
35- client.publicClient.readContract({ address: TOKEN, abi: ERC20_ABI, functionName: 'symbol' }),
36- client.publicClient.readContract({ address: TOKEN, abi: ERC20_ABI, functionName: 'decimals' }),
37- client.publicClient.readContract({ address: TOKEN, abi: ERC20_ABI, functionName: 'totalSupply' }),
38- ])
39-
40- console.log('-- Metadata --')
41- console.log('Name : ' + name)
42- console.log('Symbol : ' + symbol)
43- console.log('Decimals : ' + decimals)
44- console.log('Total Supply : ' + formatUnits(totalSupply, decimals) + ' ' + symbol)
45-
46- // Read holder balance and allowance
47- const SPENDER = '0x33e5E5B262e5d8eBC443E1c6c9F14215b020554d' // AutomationManager testnet
48- const [balance, allowance] = await Promise.all([
49- client.publicClient.readContract({ address: TOKEN, abi: ERC20_ABI, functionName: 'balanceOf', args: [HOLDER] }),
50- client.publicClient.readContract({ address: TOKEN, abi: ERC20_ABI, functionName: 'allowance', args: [HOLDER, SPENDER] }),
51- ])
52-
53- console.log('-- Holder ' + HOLDER.slice(0,10) + '... --')
54- console.log('Balance : ' + formatUnits(balance, decimals) + ' ' + symbol)
55- console.log('Allowance : ' + formatUnits(allowance, decimals) + ' ' + symbol + ' (for AutomationManager)')
33+ ;(async () => {
34+ // Batch-read all standard ERC-20 metadata in one round-trip
35+ const [name, symbol, decimals, totalSupply] = await Promise.all([
36+ client.publicClient.readContract({ address: TOKEN, abi: ERC20_ABI, functionName: 'name' }),
37+ client.publicClient.readContract({ address: TOKEN, abi: ERC20_ABI, functionName: 'symbol' }),
38+ client.publicClient.readContract({ address: TOKEN, abi: ERC20_ABI, functionName: 'decimals' }),
39+ client.publicClient.readContract({ address: TOKEN, abi: ERC20_ABI, functionName: 'totalSupply' }),
40+ ])
41+
42+ console.log('-- Metadata --')
43+ console.log('Name : ' + name)
44+ console.log('Symbol : ' + symbol)
45+ console.log('Decimals : ' + decimals)
46+ console.log('Total Supply : ' + formatUnits(totalSupply, decimals) + ' ' + symbol)
47+
48+ // Read holder balance and allowance
49+ const [balance, allowance] = await Promise.all([
50+ client.publicClient.readContract({ address: TOKEN, abi: ERC20_ABI, functionName: 'balanceOf', args: [HOLDER] }),
51+ client.publicClient.readContract({ address: TOKEN, abi: ERC20_ABI, functionName: 'allowance', args: [HOLDER, SPENDER] }),
52+ ])
53+
54+ console.log('-- Holder ' + HOLDER.slice(0,10) + '... --')
55+ console.log('Balance : ' + formatUnits(balance, decimals) + ' ' + symbol)
56+ console.log('Allowance : ' + formatUnits(allowance, decimals) + ' ' + symbol + ' (for AutomationManager)')
57+ })().catch(console.error)
5658`
5759 }}
5860 showConsole
0 commit comments