-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathevm_basics.ts
More file actions
59 lines (49 loc) · 1.78 KB
/
evm_basics.ts
File metadata and controls
59 lines (49 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env npx ts-node
// @ts-nocheck
/**
* HyperEVM Example
*
* Shows how to use standard Ethereum JSON-RPC calls on Hyperliquid's EVM chain.
*
* Usage:
* export QUICKNODE_ENDPOINT="https://your-endpoint.hype-mainnet.quiknode.pro/YOUR_TOKEN"
* npx ts-node evm_basics.ts
*/
import { HyperliquidSDK } from '@quicknode/hyperliquid-sdk';
const ENDPOINT = process.env.QUICKNODE_ENDPOINT;
if (!ENDPOINT) {
console.error("Set QUICKNODE_ENDPOINT environment variable");
process.exit(1);
}
async function main() {
// Single SDK instance — access everything through sdk.info, sdk.core, sdk.evm, etc.
const sdk = new HyperliquidSDK(ENDPOINT);
const evm = sdk.evm;
console.log("=".repeat(50));
console.log("HyperEVM (Ethereum JSON-RPC)");
console.log("=".repeat(50));
// Chain info
console.log("\n1. Chain Info:");
const chainId = await evm.chainId();
const blockNum = await evm.blockNumber();
const gasPrice = await evm.gasPrice();
console.log(` Chain ID: ${chainId}`);
console.log(` Block: ${blockNum}`);
console.log(` Gas Price: ${(Number(gasPrice) / 1e9).toFixed(2)} gwei`);
// Latest block
console.log("\n2. Latest Block:");
const block = await evm.getBlockByNumber("latest");
if (block) {
console.log(` Hash: ${block.hash?.slice(0, 20)}...`);
console.log(` Txs: ${(block.transactions || []).length}`);
}
// Check balance
console.log("\n3. Balance Check:");
const addr = "0x0000000000000000000000000000000000000000";
const balance = await evm.getBalance(addr);
console.log(` ${addr.slice(0, 12)}...: ${(Number(balance) / 1e18).toFixed(6)} ETH`);
console.log("\n" + "=".repeat(50));
console.log("Done!");
console.log("\nFor debug/trace APIs, use: new EVM(endpoint, { debug: true })");
}
main().catch(console.error);