-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathevm_basics.py
More file actions
68 lines (52 loc) · 1.71 KB
/
evm_basics.py
File metadata and controls
68 lines (52 loc) · 1.71 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
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
"""
HyperEVM Example
Shows how to use standard Ethereum JSON-RPC calls on Hyperliquid's EVM chain.
Requirements:
pip install hyperliquid-sdk
Usage:
export ENDPOINT="https://your-endpoint.hype-mainnet.quiknode.pro/TOKEN"
python evm_basics.py
"""
import os
import sys
from hyperliquid_sdk import HyperliquidSDK
ENDPOINT = os.environ.get("ENDPOINT") or os.environ.get("QUICKNODE_ENDPOINT")
if not ENDPOINT:
print("Error: Set ENDPOINT environment variable")
print(" export ENDPOINT='https://your-endpoint.hype-mainnet.quiknode.pro/TOKEN'")
sys.exit(1)
def main():
print("=" * 50)
print("HyperEVM (Ethereum JSON-RPC)")
print("=" * 50)
# Single SDK instance - access everything through sdk.info, sdk.core, sdk.evm
sdk = HyperliquidSDK(ENDPOINT)
evm = sdk.evm
# Chain info
print("\n1. Chain Info:")
chain_id = evm.chain_id()
block_num = evm.block_number()
gas_price = evm.gas_price()
print(f" Chain ID: {chain_id}")
print(f" Block: {block_num}")
print(f" Gas Price: {gas_price / 1e9:.2f} gwei")
# Latest block
print("\n2. Latest Block:")
block = evm.get_block_by_number(block_num)
if block:
block_hash = block.get("hash", "?")
txs = block.get("transactions", [])
print(f" Hash: {block_hash[:20]}...")
print(f" Txs: {len(txs)}")
# Check balance
print("\n3. Balance Check:")
addr = "0x0000000000000000000000000000000000000000"
balance = evm.get_balance(addr)
print(f" {addr[:12]}...: {balance / 1e18:.6f} ETH")
print()
print("=" * 50)
print("Done!")
print("\nFor debug/trace APIs, use: sdk.evm(debug=True)")
if __name__ == "__main__":
main()