Skip to content

Instantly share code, notes, and snippets.

@kyriediculous
Last active September 17, 2023 09:42
Show Gist options
  • Save kyriediculous/2cb817b433ac9683c14d8061a0c79484 to your computer and use it in GitHub Desktop.
Save kyriediculous/2cb817b433ac9683c14d8061a0c79484 to your computer and use it in GitHub Desktop.
const chains = {
'1': 'https://eth-mainnet.g.alchemyapi.io/v2/',
'42161': 'https://arb-mainnet.g.alchemyapi.io/v2/'
}
if (
secrets.alchemy == ""
) {
throw Error(
"Provide Alchemy API key"
)
}
const txHash = args[0];
if (txHash.length != 66 && !txHash.startsWith('0x')) throw Error("invalid transaction hash")
const chainId = args[1];
if (!chainId) throw Error("chainId is required");
const endpoint = `${chains[chainId]}${secrets.alchemy}`
const body = {
jsonrpc: '2.0',
id: 1,
method: 'eth_getTransactionByHash',
params: [txHash]
};
console.log(`Getting transaction\n \
Tx hash: ${txHash} \n \
Chain: ${chainId}`)
const res = await Functions.makeHttpRequest({
url: endpoint,
method: 'POST',
data: body
})
if (res.error) {
console.error(res.error);
throw res.error;
}
const data = res.data.result;
if (!data.blockNumber) throw Error("Transaction not mined");
const response = {
from: data.from,
to: data.to,
data: data.input
}
console.log(`Retrieved data for transaction ${txHash} on chain ${chainId} \n \
From: ${response.from} \n \
To: ${response.to} \n \
Data: ${response.data}
`)
return Functions.encodeString(JSON.stringify(response));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment