Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

@enc-protocol/ethereum

Ethereum Enc Testnet on Cloudflare Workers. Full EVM, Etherscan-style explorer, pre-deployed USDT. Use as a test dependency — spawn a testnet from vitest, node

, or any test runner.

Live: https://enc-testnet.ocrybit.workers.dev

Source: https://github.com/enc-protocol/utils/tree/master/ethereum

Install

echo "@enc-protocol:registry=https://npm-registry.ocrybit.workers.dev/" >> .npmrc
npm install @enc-protocol/ethereum

Usage in Tests

import { startDevnet } from '@enc-protocol/ethereum'
import { describe, it, beforeAll, afterAll } from 'vitest'
import { JsonRpcProvider, Wallet } from 'ethers'
 
let devnet
 
beforeAll(async () => {
  devnet = await startDevnet({ port: 8545 })
})
 
afterAll(() => devnet.stop())
 
it('has funded accounts', async () => {
  const provider = new JsonRpcProvider(devnet.url)
  const balance = await provider.getBalance(devnet.accounts[0].address)
  // 100 ETH per account
})
 
it('can send transactions', async () => {
  const provider = new JsonRpcProvider(devnet.url)
  const wallet = new Wallet(devnet.accounts[0].privateKey, provider)
  const tx = await wallet.sendTransaction({
    to: devnet.accounts[1].address,
    value: 1000000000000000000n, // 1 ETH
  })
  const receipt = await tx.wait()
  // receipt.status === 1
})

API

startDevnet(options?): Promise<Devnet>

Spawns a local Ethereum Enc Testnet and returns when ready.

Options:
OptionDefaultDescription
port8545Port to listen on
silenttrueSuppress wrangler output
Returns:
interface Devnet {
  url: string                    // "http://127.0.0.1:8545"
  port: number                   // 8545
  chainId: number                // 31338
  accounts: DevnetAccount[]      // 10 pre-funded accounts (100 ETH each)
  rpc(method, params?): Promise  // Send JSON-RPC request
  stop(): Promise<void>          // Kill the testnet
}
 
interface DevnetAccount {
  address: string                // 0x-prefixed
  privateKey: string             // 0x-prefixed
}

devnet.rpc(method, params?)

await devnet.rpc('eth_blockNumber')
await devnet.rpc('eth_getBalance', ['0x...', 'latest'])
await devnet.rpc('anvil_setBalance', ['0x...', '0x1000'])
await devnet.rpc('evm_mine')

Standalone Usage

git clone https://github.com/enc-protocol/utils.git
cd utils/ethereum
npm install
npm run dev             # start on :8545
npm run keygen          # generate 10 accounts
npm run deploy:usdt     # deploy USDT + fund accounts

Deploy to Cloudflare

npm run deploy
npm run deploy:usdt -- https://enc-testnet.ocrybit.workers.dev

Network

FieldValue
Chain ID31338
RPC (local)http://localhost:8545
RPC (production)https://enc-testnet.ocrybit.workers.dev
ExplorerSame URL (GET = explorer, POST = RPC)
USDTDeployed via npm run deploy:usdt

MetaMask

  • Network Name: Enc Testnet
  • RPC URL: https://enc-testnet.ocrybit.workers.dev
  • Chain ID: 31338
  • Symbol: ETH

JSON-RPC Methods

Standard: eth_chainId, eth_blockNumber, eth_gasPrice, eth_getBalance, eth_getTransactionCount, eth_getCode, eth_getStorageAt, eth_call, eth_estimateGas, eth_sendTransaction, eth_sendRawTransaction, eth_getTransactionByHash, eth_getTransactionReceipt, eth_getBlockByNumber, eth_getBlockByHash, eth_getLogs, eth_accounts, eth_feeHistory, net_version, web3_clientVersion

Testnet control: evm_mine, evm_snapshot, evm_revert, evm_setAutomine, anvil_setBalance, anvil_setNonce, anvil_setCode, anvil_setStorageAt

Explorer

Built-in Etherscan-style block explorer at the same URL:

  • / — Homepage with latest blocks and transactions
  • /block/:number — Block detail
  • /tx/:hash — Transaction detail with token transfers
  • /address/:addr — Address/contract with balance, txs, token holders
  • /tokens — ERC-20 token tracker
  • /search?q= — Search by address, tx hash, or block number