Skip to content

Commit

Permalink
Add tx query API
Browse files Browse the repository at this point in the history
Signed-off-by: KayleCoder <[email protected]>
  • Loading branch information
KayleCoder committed Jan 16, 2024
1 parent 295c445 commit f5920ca
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 145 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"dependencies": {
"@ethda/blobs": "^0.2.0",
"axios": "^1.6.5",
"body-parser": "^1.20.2",
"c-kzg": "^2.1.2",
"cors": "^2.8.5",
Expand Down
24 changes: 24 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {blobToKzgCommitment, computeBlobKzgProof, loadTrustedSetup} from "c-kzg"
const app = express();
const port = process.env.PORT ?? 3000;
const SETUP_FILE_PATH = resolve(__dirname, 'trusted.txt');
import axios, {HttpStatusCode} from 'axios'
const rpcUrl = process.env.RPC_URL??'https://rpc-devnet.ethda.io'
loadTrustedSetup(SETUP_FILE_PATH);
app.use(cors({
origin:true,
Expand Down Expand Up @@ -35,6 +37,28 @@ app.post('/convert/blob', (req: any, res: any) => {
}
});

app.get('/transaction/:hash', async (req: any, res: any) => {
const hash = req.params.hash;
if (hash) {
const result = await axios.post(rpcUrl, {
method: "eth_getTransactionByHash",
params: [hash],
id: 1,
jsonrpc: "2.0"
});
if (result.status === HttpStatusCode.Ok) {
res.json({
data: result.data.result.input
})
} else {
res.status(500).send('query tx failed');
}

} else {
res.status(400).send('invalid tx hash');
}
})

app.listen(port, () => {
console.log(`server start at: ${port}`);
});
Loading

0 comments on commit f5920ca

Please sign in to comment.