Skip to content

Commit 4e5b09d

Browse files
committed
fix evm examples
1 parent 56b34bc commit 4e5b09d

File tree

11 files changed

+316
-321
lines changed

11 files changed

+316
-321
lines changed

evm/.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
broadcast/
2-
cache/
3-
out/
1+
out/
2+
.env

evm/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ That's it! You're now fetching and verifying real-time oracle prices on EVM.
5858
| Network | Chain ID | Switchboard Contract |
5959
|---------|----------|---------------------|
6060
| **Monad Mainnet** | 143 | `0xB7F03eee7B9F56347e32cC71DaD65B303D5a0E67` |
61-
| **Monad Testnet** | 10143 | `0xD3860E2C66cBd5c969Fa7343e6912Eff0416bA33` |
62-
| **Hyperliquid Mainnet** | 999 | `0xcDb299Cb902D1E39F83F54c7725f54eDDa7F3347` |
61+
| **Monad Testnet** | 10143 | `0x33A5066f65f66161bEb3f827A3e40fce7d7A2e6C` |
62+
| **HyperEVM Mainnet** | 999 | `0x316fbe540c719970e6427ccd8590d7e0a2814c5d` |
6363
| **Hyperliquid Testnet** | 998 | TBD |
6464

6565
> **Note**: For other EVM chains (Arbitrum, Core, etc.), see the [legacy examples](./legacy/) which use the previous Switchboard implementation.
@@ -73,7 +73,7 @@ Monad is a high-performance EVM-compatible blockchain optimized for speed and ef
7373
| Network | Chain ID | RPC URL | Switchboard Contract |
7474
|---------|----------|---------|---------------------|
7575
| **Monad Mainnet** | 143 | `https://rpc-mainnet.monadinfra.com/rpc/YOUR_API_KEY` | `0xB7F03eee7B9F56347e32cC71DaD65B303D5a0E67` |
76-
| **Monad Testnet** | 10143 | `https://testnet-rpc.monad.xyz` | `0xD3860E2C66cBd5c969Fa7343e6912Eff0416bA33` |
76+
| **Monad Testnet** | 10143 | `https://testnet-rpc.monad.xyz` | `0x33A5066f65f66161bEb3f827A3e40fce7d7A2e6C` |
7777

7878
### Quick Start on Monad
7979

@@ -183,7 +183,7 @@ Hyperliquid is a high-performance Layer 1 blockchain with native perpetual futur
183183

184184
| Network | Chain ID | RPC URL | Switchboard Contract |
185185
|---------|----------|---------|---------------------|
186-
| **Hyperliquid Mainnet** | 999 | `https://rpc.hyperliquid.xyz/evm` | `0xcDb299Cb902D1E39F83F54c7725f54eDDa7F3347` |
186+
| **HyperEVM Mainnet** | 999 | `https://rpc.hyperliquid.xyz/evm` | `0x316fbe540c719970e6427ccd8590d7e0a2814c5d` |
187187
| **Hyperliquid Testnet** | 998 | `https://rpc.hyperliquid-testnet.xyz/evm` | TBD |
188188

189189
### Quick Start on Hyperliquid
@@ -248,8 +248,8 @@ import { CrossbarClient } from '@switchboard-xyz/common';
248248
const provider = new ethers.JsonRpcProvider('https://rpc.hyperliquid.xyz/evm');
249249
const signer = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);
250250

251-
// Switchboard contract on Hyperliquid Mainnet
252-
const switchboardAddress = '0xcDb299Cb902D1E39F83F54c7725f54eDDa7F3347';
251+
// Switchboard contract on HyperEVM Mainnet
252+
const switchboardAddress = '0x316fbe540c719970e6427ccd8590d7e0a2814c5d';
253253
const switchboard = new ethers.Contract(switchboardAddress, SWITCHBOARD_ABI, signer);
254254

255255
// Your deployed price consumer contract

evm/bun.lock

Lines changed: 139 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

evm/deploy.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Load .env if it exists
5+
if [ -f .env ]; then
6+
source .env
7+
fi
8+
9+
# Check required vars
10+
if [ -z "$PRIVATE_KEY" ] || [ -z "$RPC_URL" ]; then
11+
echo "Error: PRIVATE_KEY and RPC_URL must be set in .env"
12+
exit 1
13+
fi
14+
15+
echo "Deploying SwitchboardPriceConsumer..."
16+
17+
# Deploy and capture output
18+
OUTPUT=$(forge script script/DeploySwitchboardPriceConsumer.s.sol:DeploySwitchboardPriceConsumer \
19+
--rpc-url "$RPC_URL" \
20+
--private-key "$PRIVATE_KEY" \
21+
--broadcast \
22+
2>&1)
23+
24+
echo "$OUTPUT"
25+
26+
# Extract contract address from output
27+
CONTRACT_ADDRESS=$(echo "$OUTPUT" | grep -oE "SwitchboardPriceConsumer deployed at: 0x[a-fA-F0-9]{40}" | grep -oE "0x[a-fA-F0-9]{40}")
28+
29+
if [ -z "$CONTRACT_ADDRESS" ]; then
30+
echo "Error: Could not extract contract address from deployment output"
31+
exit 1
32+
fi
33+
34+
echo ""
35+
echo "Updating .env with CONTRACT_ADDRESS=$CONTRACT_ADDRESS"
36+
37+
# Update or add CONTRACT_ADDRESS in .env
38+
if grep -q "^CONTRACT_ADDRESS=" .env 2>/dev/null; then
39+
# Replace existing
40+
sed -i.bak "s/^CONTRACT_ADDRESS=.*/CONTRACT_ADDRESS=$CONTRACT_ADDRESS/" .env && rm -f .env.bak
41+
else
42+
# Add new
43+
echo "CONTRACT_ADDRESS=$CONTRACT_ADDRESS" >> .env
44+
fi
45+
46+
echo ""
47+
echo "Done! Now run: bun scripts/run.ts"

evm/foundry.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
[profile.default]
22
src = "src"
3-
out = "out"
3+
out = "out/artifacts"
4+
cache_path = "out/cache"
5+
broadcast = "out/broadcast"
46
libs = ["node_modules", "lib"]
57

68
remappings = [
79
"forge-std/=node_modules/forge-std/src/",
10+
"@switchboard-xyz/on-demand-solidity/=node_modules/@switchboard-xyz/on-demand-solidity/",
811
]
912

1013
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

evm/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
"typescript": "^5.0.0"
3535
},
3636
"dependencies": {
37-
"@switchboard-xyz/common": "^5",
38-
"@switchboard-xyz/on-demand-solidity": "^0.0.4",
37+
"@switchboard-xyz/common": "^5.5.0",
38+
"@switchboard-xyz/on-demand": "^3.7.3",
39+
"@switchboard-xyz/on-demand-solidity": "^1.0.0",
3940
"@types/yargs": "^17.0.33",
4041
"ethers": "^6.13.1",
4142
"forge-std": "github:foundry-rs/forge-std#v1.9.4",

evm/script/DeploySwitchboardPriceConsumer.s.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import "../src/SwitchboardPriceConsumer.sol";
3030
* -vvvv
3131
*/
3232
contract DeploySwitchboardPriceConsumer is Script {
33-
// Monad Switchboard addresses
34-
address constant MONAD_TESTNET_SWITCHBOARD = 0xD3860E2C66cBd5c969Fa7343e6912Eff0416bA33;
33+
// Monad Switchboard addresses (from docs.switchboard.xyz)
34+
address constant MONAD_TESTNET_SWITCHBOARD = 0x33A5066f65f66161bEb3f827A3e40fce7d7A2e6C;
3535
address constant MONAD_MAINNET_SWITCHBOARD = 0xB7F03eee7B9F56347e32cC71DaD65B303D5a0E67;
3636

3737
function run() external {

0 commit comments

Comments
 (0)