{"id":26562907,"url":"https://github.com/aelfproject/aelf-block-api","last_synced_at":"2025-09-14T14:39:33.814Z","repository":{"id":42104439,"uuid":"144841884","full_name":"AElfProject/aelf-block-api","owner":"AElfProject","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-03T09:35:34.000Z","size":1075,"stargazers_count":2,"open_issues_count":27,"forks_count":9,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-08-07T07:31:34.335Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AElfProject.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-08-15T10:56:03.000Z","updated_at":"2024-06-18T09:44:19.000Z","dependencies_parsed_at":"2023-12-18T08:23:50.804Z","dependency_job_id":"72b2bf5e-7917-4c26-8680-6bdac05fa5c9","html_url":"https://github.com/AElfProject/aelf-block-api","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/AElfProject/aelf-block-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AElfProject%2Faelf-block-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AElfProject%2Faelf-block-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AElfProject%2Faelf-block-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AElfProject%2Faelf-block-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AElfProject","download_url":"https://codeload.github.com/AElfProject/aelf-block-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AElfProject%2Faelf-block-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271285545,"owners_count":24732935,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-20T02:00:09.606Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-22T15:29:13.967Z","updated_at":"2025-08-20T08:18:41.369Z","avatar_url":"https://github.com/AElfProject.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AElf Block API\n\n## Quick Start\n\nPlease ensure your dependencies are ready.\n\nDefault port: `7101`\n\nOpen `http://127.0.0.1:7101`, you will see 'hi, this is aelf-block-api.'.\n\n### 0.Dependencies\n\n- 1.[aelf-scan-mysql](https://github.com/AElfProject/aelf-scan-mysql):\nStart up [aelf-scan-mysql](https://github.com/AElfProject/aelf-scan-mysql) at first. There are mysql and redis services in this project\n- 2.NodeJS: You can see the JS dependencies in package.json, we use egg.js(Node.js \u0026 Koa).\n- 3. Redis, you need a redis\n\n### 1.Change the Config\n\nset your own configs in `.env`\n\ninclude: `sql`, `endpoint` and `side chain APIs`\n\n1. sql: mysql service in `aelf-scan-mysql`\n2. endpoint: chain endpoint\n3. side chain APIs: other chains' `aelf-block-api` services URLs\n\nAnd Redis config in `config/config.default.js`\n\nWarning About Mysql:\n\n- Please do not use root. Use the normal users without SUPER privilege.\n\nGrant Demo\n\n```bash\n    CREATE USER 'normal_aelf'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';\n    GRANT select, insert, update, delete on aelf_test.* TO 'normal_aelf'@'localhost';\n```\n\n### 2.Start the node server\n\ntry to use build.sh at first.\n\n```bash\nnpm install\n\n# for local development\nnpm run dev\n# for production\nnpm start\n# for shutdown in production environment\nnpm stop\n```\n\n## About csrf-token \u0026 POST API\n\nIf you want test Post API.\n\nYou must set header x-csrf-token=(csrfToken in cookie).\n\n```javascript\n// for a javascript example\nconst csrf = document.cookie.match(/csrfToken=[^;]*/)[0].replace('csrfToken=', '');\nfetch(`/block/api/address/transactions`, {\n    credentials: 'include',\n    method: 'POST',\n    headers: {\n        // About csrf token\n        // csrf: https://github.com/pillarjs/understanding-csrf/blob/master/README_zh.md\n        // csrf: https://www.ibm.com/developerworks/cn/web/1102_niugang_csrf/index.html\n        'x-csrf-token': csrf,\n        'Content-Type': 'application/json',\n        'Accept': 'application/json'\n    }\n}).then().catch();\n```\n\n## API DOCS\n\nYou can get the docs in the folder ./postman\n\n## Dev Suggestion\n\nWe advise you implement your own API like the example.\n\n```javascript\n// 1.\n// The framework recommends that the Controller layer is responsible for processing request parameters(verification and transformation)\n// from user's requests, then calls related business methods in Service, encapsulates and sends back business result:\n// 1.retrieves parameters passed by HTTP.\n// 2.verifies and assembles parameters.\n// 3.calls the Service to handle business, if necessary,\n//          transforms Service process results to satisfy user's requirement.\n// 4.sends results back to user by HTTP.\n// 框架推荐 Controller 层主要对用户的请求参数进行处理（校验、转换），然后调用对应的 service 方法处理业务，得到业务结果后封装并返回：\n// 获取用户通过 HTTP 传递过来的请求参数。\n// 校验、组装参数。\n// 调用 Service 进行业务处理，必要时处理转换 Service 的返回结果，让它适应用户的需求。\n// 通过 HTTP 将结果响应给用户。\n\n// 2.\n// give the params keysRule.\n\n// Example, code snippets.\n// controller/address.js\n    async function getTokens() {\n        let ctx = this.ctx;\n\n        // Not only param validate but also a detail param doc.\n        // About 'paramater': https://github.com/node-modules/parameter\n        const keysRule = {\n            address: 'string',\n            limit: {\n                type: 'int',\n                required: false,\n                allowEmpty: true,\n                max: 500,\n                min: 0\n            },\n            page: {\n                type: 'int',\n                required: false,\n                allowEmpty: true\n            },\n            order: {\n                type: 'string',\n                required: false,\n                allowEmpty: true\n            },\n            nodes_info: {\n                type: 'boolean',\n                required: false,\n                allowEmpty: true\n            }\n        };\n\n        try {\n            let {\n                address,\n                limit,\n                page,\n                order,\n                nodes_info\n            } = ctx.request.query;\n            let options = {\n                address,\n                limit: limit ? parseInt(limit, 10) : 0,\n                page: page ? parseInt(page, 10) : 0,\n                order: order || 'DESC',\n                nodes_info: nodes_info || false\n            };\n            ctx.validate(keysRule, options);\n            let result = await ctx.service.address.getTokens(options);\n            formatOutput(ctx, 'get', result);\n        }\n        catch (error) {\n            formatOutput(ctx, 'error', error, 422);\n        }\n    }\n\n// service/address.js\nasync function getTokens(options) {\n    // get the tokens information.\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faelfproject%2Faelf-block-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faelfproject%2Faelf-block-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faelfproject%2Faelf-block-api/lists"}