{"id":18367250,"url":"https://github.com/k-nuth/c-api","last_synced_at":"2025-04-06T16:32:37.148Z","repository":{"id":53831939,"uuid":"237131281","full_name":"k-nuth/c-api","owner":"k-nuth","description":"Bitcoin full node as a C Programming Language library","archived":false,"fork":false,"pushed_at":"2025-02-02T22:28:45.000Z","size":3499,"stargazers_count":11,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T03:41:41.949Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":false,"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/k-nuth.png","metadata":{"files":{"readme":"README.md","changelog":"history.txt","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}},"created_at":"2020-01-30T03:25:40.000Z","updated_at":"2025-02-19T23:36:33.000Z","dependencies_parsed_at":"2023-11-06T13:30:24.464Z","dependency_job_id":"a0b40154-bd97-4fcd-b794-4481f987ba7f","html_url":"https://github.com/k-nuth/c-api","commit_stats":null,"previous_names":[],"tags_count":82,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k-nuth%2Fc-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k-nuth%2Fc-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k-nuth%2Fc-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k-nuth%2Fc-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/k-nuth","download_url":"https://codeload.github.com/k-nuth/c-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247512972,"owners_count":20950964,"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","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":"2024-11-05T23:20:49.161Z","updated_at":"2025-04-06T16:32:37.125Z","avatar_url":"https://github.com/k-nuth.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- \u003ca target=\"_blank\" href=\"http://semver.org\"\u003e![Version][badge.version]\u003c/a\u003e --\u003e\n\u003c!-- \u003ca target=\"_blank\" href=\"https://cirrus-ci.com/github/k-nuth/c-api\"\u003e![Build Status][badge.Cirrus]\u003c/a\u003e --\u003e\n\n\u003cimg width=\"200px\" src=\"https://raw.githubusercontent.com/k-nuth/misc/master/images/KTH-and-C.svg\" /\u003e\n\n# C API \u003ca target=\"_blank\" href=\"https://github.com/k-nuth/c-api/releases\"\u003e![Github Releases][badge.release]\u003c/a\u003e \u003ca target=\"_blank\" href=\"https://github.com/k-nuth/c-api/actions\"\u003e![Build status][badge.GithubActions]\u003c/a\u003e \u003ca href=\"#\"\u003e![C][badge.c]\u003c/a\u003e \u003ca target=\"_blank\" href=\"https://t.me/knuth_cash\"\u003e![Telegram][badge.telegram]\u003c/a\u003e \u003ca target=\"_blank\" href=\"https://k-nuth.slack.com/\"\u003e![Slack][badge.slack]\u003c/a\u003e\n\n\u003e Bitcoin full node as a C Programming Language library\n\nKnuth is a high performance implementation of the Bitcoin protocol focused on users requiring extra performance and flexibility, what makes it the best platform for wallets, exchanges, block explorers and miners.\n\n## Getting started\n\nInstall and run Knuth is very easy:\n\n1. Install and configure the Knuth build helper:\n```\n$ pip install kthbuild --user --upgrade\n\n$ conan config install https://github.com/k-nuth/ci-utils/raw/master/conan/config2023.zip\n```\n\n2. Install the appropriate library:\n\n```\n$ conan install --requires=c-api/0.61.0 --update\n```\n\n### \"Hello, Knuth!\":\n```c\n// hello_knuth.c\n\n#include \u003cinttypes.h\u003e\n#include \u003cstdint.h\u003e\n#include \u003cstdio.h\u003e\n\n#include \u003ckth/capi.h\u003e\n\nint main() {\n    kth_node_t node = kth_node_construct(\"my_config_file\", stdout, stderr);\n\n    kth_node_initchain(node);\n    kth_node_run_wait(node);\n    kth_chain_t chain = kth_node_get_chain(node);\n\n    uint64_t height;\n    chain_get_last_height(chain, \u0026height);\n\n    printf(\"%\" PRIu64 \"\\n\", height);\n\n    kth_node_destruct(node);\n}\n```\n\n### Explanation:\n\n```c\n#include \u003cinttypes.h\u003e\n#include \u003cstdint.h\u003e\n#include \u003cstdio.h\u003e\n```\n\nIncludes C standard library stuff, like format conversion specifiers, fixed width integer types (`uint64_t`) and input/output features. (`stdout`, `stderr` and `printf())`.\n\n```c\n#include \u003ckth/capi.h\u003e\n```\nGives access to Knuth C-API features.\n\n```c\nkth_node_t node = kth_node_construct(\"my_config_file\", stdout, stderr);\n```\nConstruct a Knuth _node_ object, which is necessary to run the node, interact with the blockchain, with the P2P peers and other components of the API.\n\n`\"my_config_file\"` is the path to the configuration file; in the [config](https://github.com/k-nuth/config) repository you can find some example files.\nIf you pass an empty string (`\"\"`), default configuration will be used.\n\n`stdout` and `stderr` are pointers to the standard output and standard error streams. These are used to tell the Knuth node where to print the logs.\nYou can use any object of type `FILE*`. For example, you can make the Knuth node redirect the logs to a file.\nIf you pass null pointers (`NULL` or `0`), there will be no logging information.\n\n```c\nkth_node_initchain(node);\n```\n\nInitialize the filesystem database where the _blockchain_ will be stored.\nYou need to have enough disk space to store the blockchain.\n\nThis is equivalent to executing: `kth -i -c my_config_file`.\n\n```c\nkth_node_run_wait(node);\n```\n\nRun the node.\nIn this step, the connections and handshake with the peers will be established, and the initial process of downloading blocks will start. Once this stage has finished, the node will begin to receive transactions and blocks through the P2P network.\n\nThis is equivalent to executing: `kth -c my_config_file`.\n```c\nkth_chain_t chain = kth_node_get_chain(node);\n```\n\nGet access to the blockchain query interface (commands and queries).\n\n```c\nuint64_t height;\nchain_get_last_height(chain, \u0026height);\n\nprintf(\"%\" PRIu64 \"\\n\", height);\n```\n\nAsk the blockchain what is the height of the last downloaded block and print it in the standard output.\n\n```c\nkth_node_destruct(node);\n```\n\nDestroy the node object created earlier.\n(We are in land of _The C Programming Language_, there is no automatic handling of resources here, you have to do it manually.)\n\n### Build and run:\n\n_Note: Here we are building the code using the GNU Compiler Collection (GCC) on Linux. You can use other compilers and operating systems as well. If you have any questions, you can [contact us here](info@kth.cash)._\n\nTo build and run the code example, first you have to create a tool file called `conanfile.txt` in orded to manage the dependencies of the code:\n\n```sh\n$ printf \"[requires]\\nc-api/0.61.0\\n[options]\\nc-api:shared=True\\n[imports]\\ninclude/kth, *.h -\u003e ./include/kth\\ninclude/kth, *.hpp -\u003e ./include/kth\\nlib, *.so -\u003e ./lib\\n\" \u003e conanfile.txt\n```\n\nThen, run the following command to bring the dependencies to the local directory:\n\n```sh\n$ conan install .\n```\n\nNow, you can build our code example:\n\n```sh\n$ gcc -Iinclude -c hello_knuth.c\n$ gcc -Llib -o hello_knuth hello_knuth.o -lkth-c-api\n```\n\n...run it and enjoy the Knuth programmable APIs:\n\n```sh\n$ ./hello_knuth\n```\n\nFor more more detailed instructions, please refer to our [documentation](https://kth.cash/docs/).\n\n## Issues\n\nEach of our modules has its own Github repository, but in case you want to create an issue, please do so in our [main repository](https://github.com/k-nuth/kth/issues).\n\n\n\u003c!-- Links --\u003e\n[badge.Travis]: https://travis-ci.org/k-nuth/c-api.svg?branch=master\n[badge.Appveyor]: https://ci.appveyor.com/api/projects/status/github/k-nuth/c-api?svg=true\u0026branch=master\n[badge.Cirrus]: https://api.cirrus-ci.com/github/k-nuth/c-api.svg?branch=master\n[badge.GithubActions]: https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fk-nuth%2Fc-api%2Fbadge\u0026style=for-the-badge\n[badge.version]: https://badge.fury.io/gh/k-nuth%2Fkth-c-api.svg\n[badge.release]: https://img.shields.io/github/v/release/k-nuth/c-api?display_name=tag\u0026style=for-the-badge\u0026color=A8B9CC\u0026logo=c\n[badge.c]: https://img.shields.io/badge/C-23-blue.svg?logo=c\u0026style=for-the-badge\n[badge.telegram]: https://img.shields.io/badge/telegram-badge-blue.svg?logo=telegram\u0026style=for-the-badge\n[badge.slack]: https://img.shields.io/badge/slack-badge-orange.svg?logo=slack\u0026style=for-the-badge\n\n\u003c!-- [badge.Gitter]: https://img.shields.io/badge/gitter-join%20chat-blue.svg --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fk-nuth%2Fc-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fk-nuth%2Fc-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fk-nuth%2Fc-api/lists"}