Skip to content

Commit fa2ffc8

Browse files
committed
fix: use archive RPC node and add error handling for staked XTZ balance
- Switch RPC nodes to rpc.tzkt.io (archive nodes with full history) - Add try/catch with fallback to TzKT API if RPC fails - Ensures staked XTZ is included in voting power via full_balance endpoint - Fixes voting power queries for proposals older than 3 days
1 parent 929c792 commit fa2ffc8

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ bun.lockb
3737

3838
# Local Netlify folder
3939
.netlify
40+
41+
# Claude
42+
.claude/
43+
44+
# Misc
45+
deno.lock

services/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const networkNameMap = {
99
};
1010

1111
const rpcNodes = {
12-
mainnet: "https://mainnet.api.tez.ie",
13-
ghostnet: "https://ghostnet.smartpy.io",
12+
mainnet: "https://rpc.tzkt.io/mainnet",
13+
ghostnet: "https://rpc.tzkt.io/ghostnet",
1414
};
1515

1616
const getTokenMetadata = async (contractAddress, network, tokenId) => {

utils.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,18 @@ const getUserBalanceAtLevel = async (
8080
const getUserXTZBalanceAtLevelViaRpc = async (network, level, userAddress) => {
8181
const rpcUrl = rpcNodes[network];
8282
const url = `${rpcUrl}/chains/main/blocks/${level}/context/contracts/${userAddress}/full_balance`;
83-
console.log("url: ", url);
84-
const response = await axios({ url, method: "GET" });
85-
86-
if (response.status === 200) {
87-
return new BigNumber(response.data);
83+
84+
try {
85+
const response = await axios({ url, method: "GET" });
86+
if (response.status === 200) {
87+
return new BigNumber(response.data);
88+
}
89+
} catch (error) {
90+
// RPC failed (likely historical block not available), fall back to TzKT
91+
console.warn(`RPC failed for block ${level}, falling back to TzKT API`);
92+
return await getUserXTZBalanceAtLevel(network, level, userAddress);
8893
}
89-
94+
9095
return new BigNumber(0);
9196
};
9297

0 commit comments

Comments
 (0)