0% found this document useful (0 votes)
20 views2 pages

How To Query Data From Hyperledger Blockchain

I Will Judge You By Your Bookshelf by Grant Snider
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

How To Query Data From Hyperledger Blockchain

I Will Judge You By Your Bookshelf by Grant Snider
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

how to query data from hyperledger

blockchain

class BlockchainService {
async getBlock(blockNumber: number):
Promise<Block> {
const peer =
fabricClient.getPeer('peer0.org1.example.
com');
return await
peer.queryBlock(blockNumber);
}
}

Key Components to Replace Explorer


Functionality
1 Chaincode Query FunctionsImplement these in your
smart contracts:golang// Get transaction by ID
2 func (s *SmartContract) GetTx(ctx Context, txId string) (TxRecord,
error) {
3 return ctx.GetStub().GetTransactionByID(txId)
4 }
5
6 // Get block by number
7 func (s *SmartContract) GetBlock(ctx Context, blockNum uint64)
(Block, error) {
8 return ctx.GetStub().GetBlockByNumber(blockNum)
9 }
10 Optimized Backend Servicestypescriptclass
BlockchainService {
11 async getBlock(blockNumber: number): Promise<Block> {
12 const peer = fabricClient.getPeer('peer0.org1.example.com');
13 return await peer.queryBlock(blockNumber);
14 }
15 }
16 Client-Side FilteringProcess raw data in frontend:
javascript// Frontend filtering example
17 const filterTransactions = (txns, status) =>
18 txns.filter(tx =>
19 tx.status === status &&
20 tx.timestamp > Date.now() - 30*24*3600*1000
21 );

You might also like