How to explore Data inside of Blockchain Network in Javascript
Blockchain
39
network
15
Javascript
321
Male avatar

loveprogramming viết ngày 19/05/2021

https://grokonez.com/node-js/how-to-explore-data-blockchain-network-javascript-tutorial

How to explore Data inside of Blockchain Network in Javascript

In this tutorial, we're gonna build API that allows us to explore the data inside of our Blockchain Network. We will have ability to search the entire Blockchain for a specific Block by Hash, for a specific Transaction by Id. We can also fetch data from our Blockchain Network for a specific User/Address.

Previous Post: How to build Consensus Algorithm for Blockchain Network in Javascript

Explore Data Endpoints

We will make 3 endpoints:

  • GET /block/:hash: shows a specific Block by :hash.
  • GET /transaction/:id: shows a specific Transaction by Transaction's :id.
  • GET /address/:address: shows all Transactions that an :address is related to (address/user is a sender or a recipient).

These endpoints use 3 Blockchain class finder methods:


class Blockchain {

    findBlockByHash(hash) { ... }
    findTransactionById(id) { ... }
    findTransactionsByAddress(address) { ... }
}

Practice

Implement Blockchain class Finder Methods

Inside blockchain.js file, add 3 methods to Blockchain class:

Find specific Block by Hash


class Blockchain {
    ...
    findBlockByHash(hash) {
        let result = null;

        this.chain.forEach(block => {
            if (block.hash === hash) {
                result = block;
            }
        });

        return result;
    }
}

Find specific Transaction by Transaction's Id

More at:

https://grokonez.com/node-js/how-to-explore-data-blockchain-network-javascript-tutorial

How to explore Data inside of Blockchain Network in Javascript

Bình luận


White
{{ comment.user.name }}
Bỏ hay Hay
{{comment.like_count}}
Male avatar
{{ comment_error }}
Hủy
   

Hiển thị thử

Chỉnh sửa

Male avatar

loveprogramming

545 bài viết.
97 người follow
Kipalog
{{userFollowed ? 'Following' : 'Follow'}}
Cùng một tác giả
Male avatar
1 0
Tutorial Link: (Link) (Ảnh) Django is a Pythonbased free and opensource web framework that follows the modeltemplateview architectural pattern. A...
loveprogramming viết 10 tháng trước
1 0
Male avatar
1 0
https://loizenai.com/angular11nodejspostgresqlcrudexample/ Angular 11 Node.js PostgreSQL Crud Example (Ảnh) Tutorial: “Angular 11 Node.js Postg...
loveprogramming viết 9 tháng trước
1 0
Male avatar
1 0
Angular Spring Boot jwt Authentication Example Github https://loizenai.com/angularspringbootjwt/ (Ảnh) Tutorial: ” Angular Spring Boot jwt Authe...
loveprogramming viết 9 tháng trước
1 0
Bài viết liên quan
White
11 5
Tạm xóa
Giaosucan viết hơn 3 năm trước
11 5
Male avatar
0 0
https://grokonez.com/nodejs/howtobuildadecentralizedblockchainnetworkjavascriptexample How to build a Decentralized Blockchain Network in Javascri...
loveprogramming viết 4 tháng trước
0 0
{{like_count}}

kipalog

{{ comment_count }}

bình luận

{{liked ? "Đã kipalog" : "Kipalog"}}


Male avatar
{{userFollowed ? 'Following' : 'Follow'}}
545 bài viết.
97 người follow

 Đầu mục bài viết

Vẫn còn nữa! x

Kipalog vẫn còn rất nhiều bài viết hay và chủ đề thú vị chờ bạn khám phá!