Skip to content

Commit

Permalink
fetch attestationHash from Transaction Receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
RamRamez committed Sep 1, 2024
1 parent 7a230cb commit 6aa930a
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 1 deletion.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"@neynar/nodejs-sdk": "^1.40.0",
"ethers": "^6.13.2",
"frog": "latest",
"hono": "latest"
}
Expand Down
54 changes: 54 additions & 0 deletions src/helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
export const NETWORK_IDS = {
MAIN_NET: 1,
ROPSTEN: 3,
SEPOLIA: 11155111,
XDAI: 100,
POLYGON: 137,
OPTIMISTIC: 10,
OPTIMISM_SEPOLIA: 11155420,
BSC: 56,
CELO: 42220,
CELO_ALFAJORES: 44787,
ETC: 61,
MORDOR_ETC_TESTNET: 63,

ARBITRUM_MAINNET: 42161,
ARBITRUM_SEPOLIA: 421614,

BASE_MAINNET: 8453,
BASE_SEPOLIA: 84532,

ZKEVM_MAINNET: 1101,
ZKEVM_CARDONA: 2442,

STELLAR_MAINNET: 1500,

// https://docs.particle.network/developers/other-services/node-service/solana-api
SOLANA_MAINNET: 101,
SOLANA_TESTNET: 102,
SOLANA_DEVNET: 103,
};

export const NETWORK_NAMES = {
BSC: 'bsc',
XDAI: 'xdaichain',
MAINNET: 'mainnet',
ROPSTEN: 'ropsten',
SEPOLIA: 'sepolia',
POLYGON: 'polygon-mainnet',
OPTIMISTIC: 'optimistic-mainnet',
OPTIMISM_SEPOLIA: 'optimism-sepolia-testnet',
CELO: 'Celo',
CELO_ALFAJORES: 'Celo Alfajores',
ETC: 'Ethereum Classic',
MORDOR_ETC_TESTNET: 'Ethereum Classic Testnet',
ARBITRUM_MAINNET: 'Arbitrum Mainnet',
ARBITRUM_SEPOLIA: 'Arbitrum Sepolia',
BASE_MAINNET: 'Base Mainnet',
BASE_SEPOLIA: 'Base Sepolia',

ZKEVM_CARDONA: 'ZKEVM Cardona',
ZKEVM_MAINNET: 'ZKEVM Mainnet',

STELLAR_MAINNET: 'Stellar Mainnet',
};
92 changes: 92 additions & 0 deletions src/helpers/ethers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import {NETWORK_IDS, NETWORK_NAMES} from "./constants.js";
import {ethers} from "ethers";

const INFURA_ID = process.env.INFURA_ID as string;

export function getProvider(networkId: number) {
let url;
let options;
switch (networkId) {
case NETWORK_IDS.MORDOR_ETC_TESTNET:
url =
(process.env.MORDOR_ETC_TESTNET as string) ||
`https://rpc.mordor.etccooperative.org`;
break;
case NETWORK_IDS.ETC:
url = process.env.ETC_NODE_HTTP_URL as string;
break;
case NETWORK_IDS.XDAI:
url = process.env.XDAI_NODE_HTTP_URL as string;
break;

case NETWORK_IDS.BSC:
// 'https://bsc-dataseed.binance.org/'
url = process.env.BSC_NODE_HTTP_URL as string;
options = { name: NETWORK_NAMES.BSC, chainId: NETWORK_IDS.BSC };
break;

case NETWORK_IDS.CELO:
url =
(process.env.CELO_NODE_HTTP_URL as string) ||
`https://celo-mainnet.infura.io/v3/${INFURA_ID}`;
break;

case NETWORK_IDS.CELO_ALFAJORES:
url =
(process.env.CELO_ALFAJORES_NODE_HTTP_URL as string) ||
`https://celo-alfajores.infura.io/v3/${INFURA_ID}`;
break;

case NETWORK_IDS.OPTIMISM_SEPOLIA:
url = `https://optimism-sepolia.infura.io/v3/${INFURA_ID}`;
break;

case NETWORK_IDS.ARBITRUM_MAINNET:
url =
(process.env.ARBITRUM_MAINNET_NODE_HTTP_URL as string) ||
`https://arbitrum-mainnet.infura.io/v3/${INFURA_ID}`;
break;

case NETWORK_IDS.ARBITRUM_SEPOLIA:
url =
(process.env.ARBITRUM_SEPOLIA_NODE_HTTP_URL as string) ||
`https://arbitrum-sepolia.infura.io/v3/${INFURA_ID}`;
break;

case NETWORK_IDS.BASE_MAINNET:
url =
(process.env.BASE_MAINNET_NODE_HTTP_URL as string) ||
`https://base-mainnet.infura.io/v3/${INFURA_ID}`;
break;

case NETWORK_IDS.BASE_SEPOLIA:
url =
(process.env.BASE_SEPOLIA_NODE_HTTP_URL as string) ||
`https://base-sepolia.infura.io/v3/${INFURA_ID}`;
break;

// Infura doesn support Polygon ZKEVM
case NETWORK_IDS.ZKEVM_MAINNET:
url = process.env.ZKEVM_MAINNET_NODE_HTTP_URL as string;
break;

case NETWORK_IDS.ZKEVM_CARDONA:
url = process.env.ZKEVM_CARDONA_NODE_HTTP_URL as string;
break;

case NETWORK_IDS.STELLAR_MAINNET:
url = process.env.STELLAR_HORIZON_API_URL as string;
break;

default: {
const network = ethers.Network.from(networkId);
url = `https://${network.name}.infura.io/v3/${INFURA_ID}`;
break;
}
}

return new ethers.JsonRpcProvider(
url,
options,
);
}
7 changes: 6 additions & 1 deletion src/routes/replyAttestation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import neynarClient from "../helpers/neynarClient.js";
import {getProvider} from "../helpers/ethers.js";
import {NETWORK_IDS} from "../helpers/constants.js";

const baseAttestationScan = 'https://base.easscan.org/attestation/view/';

Expand All @@ -8,7 +10,10 @@ const replyAttestation = async (req: Request) => {
}
const body = await req.text();
const data = JSON.parse(body);
const { attestationHash, praiseHash } = data;
const { txHash, praiseHash } = data;
const provider = getProvider(NETWORK_IDS.BASE_MAINNET);
const receipt = await provider.getTransactionReceipt(txHash);
const attestationHash = receipt?.logs[0]?.data
if (!attestationHash || !praiseHash) {
throw new Error("attestationHash and praiseHash are required");
}
Expand Down

0 comments on commit 6aa930a

Please sign in to comment.