{"id":24058284,"url":"https://github.com/genyleap/ethereum-cpp-sdk","last_synced_at":"2025-05-12T16:28:34.343Z","repository":{"id":266874309,"uuid":"899616701","full_name":"genyleap/ethereum-cpp-sdk","owner":"genyleap","description":"ethereum-cppsdk is a C++ SDK for interacting with the Ethereum blockchain. This SDK provides a set of tools for performing common Ethereum operations such as querying block information, estimating gas for transactions, and interacting with smart contracts using the Ethereum JSON-RPC API.","archived":false,"fork":false,"pushed_at":"2024-12-06T16:48:54.000Z","size":85,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T00:30:05.574Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/genyleap.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":"CITATION.md","codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-06T16:31:34.000Z","updated_at":"2024-12-25T20:12:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"52ec89d9-f6e0-430d-8a16-f9b60357006c","html_url":"https://github.com/genyleap/ethereum-cpp-sdk","commit_stats":null,"previous_names":["genyleap/ethereum-cpp-sdk"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genyleap%2Fethereum-cpp-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genyleap%2Fethereum-cpp-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genyleap%2Fethereum-cpp-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genyleap%2Fethereum-cpp-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/genyleap","download_url":"https://codeload.github.com/genyleap/ethereum-cpp-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253776178,"owners_count":21962447,"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":"2025-01-09T05:57:05.001Z","updated_at":"2025-05-12T16:28:34.325Z","avatar_url":"https://github.com/genyleap.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"Here’s a **README** for the **`ethereum-cpp-sdk`**:\n\n---\n\n# ethereum-cpp-sdk\n\n**ethereum-cpp-sdk** is a C++ SDK for interacting with the Ethereum blockchain. This SDK provides a set of tools for performing common Ethereum operations such as querying block information, estimating gas for transactions, and interacting with smart contracts using the Ethereum JSON-RPC API.\n\n## Features\n\n- **Blockchain Queries**: Retrieve block details, block numbers, and transaction data.\n- **Gas Estimation**: Estimate gas for transactions.\n- **Smart Contract Interaction**: Send and receive data from Ethereum smart contracts.\n- **Ethereum Network Info**: Fetch information about Ethereum network version, syncing status, and more.\n- **Customizable**: Easy integration into C++ applications with minimal dependencies.\n\n## Requirements\n\n- C++20 or higher.\n- [PT](https://github.com/genyleap/Project-Template) Based on Project Template\n- [libcurl](https://curl.se/libcurl/) for HTTP requests. (Enabled as default by PT)\n- [JSONcpp](https://github.com/open-source-parsers/jsoncpp) for JSON parsing. (Enabled as default by PT)\n\n## Installation\n\n### 1. Clone the repository\n\n```bash\ngit clone https://github.com/yourusername/ethereum-cpp-sdk.git\ncd ethereum-cpp-sdk\n```\n\n### 2. Install dependencies\n\nEnsure that you have `libcurl` and `jsoncpp` installed. You can install them using your system's package manager.\n\nFor Ubuntu/Debian:\n\n```bash\nsudo apt-get install libcurl4-openssl-dev libjsoncpp-dev\n```\n\nFor MacOS (using Homebrew):\n\n```bash\nbrew install curl jsoncpp\n```\n\n### 3. Build the project\n\n```bash\nmkdir build\ncd build\ncmake ..\nmake\n```\n\n### 4. Link to your project\n\nTo use `ethereum-cpp-sdk` in your project, link the compiled library files or copy the header and source files directly.\n\n---\n\n## Usage\n\n### Configuration\n\nBefore using the SDK, ensure you have an Ethereum node URL in a `config.json` file. Here’s an example of what the file might look like:\n\n```json\n{\n  \"nodeUrl\": \"https://your-ethereum-node-url\"\n}\n```\n\n### Example: Interacting with Ethereum\n\nHere's an example that demonstrates how to use the SDK to interact with Ethereum. This example fetches the current block number and estimates gas for a transaction.\n\n```cpp\n#include \"utility.hpp\"\n#include \"logger.hpp\"\n#include \"ethereumclient.hpp\"\n#include \u003ciostream\u003e\n\nint main() {\n    // Load the configuration (node URL)\n    auto nodeUrlOpt = loadConfig(\"config.json\");\n    if (!nodeUrlOpt) {\n        Logger::getInstance().log(\"Failed to load configuration.\");\n        return -1;\n    }\n    std::string nodeUrl = *nodeUrlOpt;\n\n    // Create NetworkAdapter and EthereumClient\n    NetworkAdapter networkAdapter;\n    EthereumClient client(nodeUrl, networkAdapter);\n\n    // Example 1: Get the current block number\n    auto blockNumber = client.getBlockNumber();\n    if (blockNumber) {\n        std::cout \u003c\u003c \"Current Block Number: \" \u003c\u003c *blockNumber \u003c\u003c std::endl;\n    }\n\n    // Example 2: Get block information by block number\n    std::string blockNumberStr = \"0x5d5f\"; // Block number in hexadecimal\n    auto blockData = client.getBlockByNumber(blockNumberStr, true); // Fetch full transaction data\n    if (blockData) {\n        std::cout \u003c\u003c \"Block Data: \" \u003c\u003c blockData-\u003etoStyledString() \u003c\u003c std::endl;\n    }\n\n    // Example 3: Estimate gas for a transaction\n    std::string from = \"0x7960f1b90b257bff29d5164d16bca4c8030b7f6d\";\n    std::string to = \"0x7960f1b90b257bff29d5164d16bca4c8030b7f6d\";\n    std::string value = \"0x9184e72a\"; // Value in hex\n    auto gasEstimate = client.estimateGas(from, to, value);\n    if (gasEstimate) {\n        std::cout \u003c\u003c \"Estimated Gas: \" \u003c\u003c *gasEstimate \u003c\u003c std::endl;\n    }\n\n    // Example 4: Get Ethereum network version\n    auto protocolVersion = client.getNetworkVersion();\n    if (protocolVersion) {\n        std::cout \u003c\u003c \"Ethereum Protocol Version: \" \u003c\u003c *protocolVersion \u003c\u003c std::endl;\n    }\n\n    return 0;\n}\n```\n\n### Supported Ethereum RPC Methods\n\nThe SDK supports the following Ethereum RPC methods:\n\n- `eth_blockNumber`: Get the current block number.\n- `eth_getBlockByNumber`: Get block data by block number.\n- `eth_getBlockByHash`: Get block data by block hash.\n- `eth_estimateGas`: Estimate gas for a transaction.\n- `eth_gasPrice`: Get the current gas price.\n- `eth_sendTransaction`: Send a transaction.\n- `eth_getLogs`: Fetch logs from the Ethereum network.\n- `eth_getTransactionReceipt`: Get the transaction receipt for a given hash.\n- `eth_getTransactionCount`: Get the transaction count (nonce) for an address.\n- `eth_chainId`: Get the Ethereum chain ID.\n- `eth_protocolVersion`: Get the protocol version of the connected Ethereum node.\n- `eth_syncing`: Check the syncing status of the node.\n\n---\n\n## API Reference\n\n### `EthereumClient` Class\n\n- **`EthereumClient(const std::string\u0026 nodeUrl, NetworkAdapter\u0026 networkAdapter)`**: Initializes the client with the Ethereum node URL and a network adapter for communication.\n  \n- **`std::optional\u003cstd::string\u003e getBlockNumber()`**: Retrieves the current block number.\n\n- **`std::optional\u003cJson::Value\u003e getBlockByNumber(const std::string\u0026 blockNumber, bool fullTransactionData)`**: Retrieves block data by block number.\n\n- **`std::optional\u003cJson::Value\u003e getBlockByHash(const std::string\u0026 blockHash, bool fullTransactionData)`**: Retrieves block data by block hash.\n\n- **`std::optional\u003cstd::string\u003e estimateGas(const std::string\u0026 from, const std::string\u0026 to, const std::string\u0026 value)`**: Estimates the gas required for a transaction.\n\n- **`std::optional\u003cstd::string\u003e getGasPrice()`**: Retrieves the current gas price.\n\n- **`std::optional\u003cstd::string\u003e sendTransaction(const std::string\u0026 rawTransaction)`**: Sends a raw transaction to the Ethereum network.\n\n- **`std::optional\u003cJson::Value\u003e getLogs(const Json::Value\u0026 params)`**: Fetches logs based on the provided parameters.\n\n- **`std::optional\u003cJson::Value\u003e getTransactionReceipt(const std::string\u0026 txHash)`**: Retrieves the receipt for a transaction by hash.\n\n---\n\n## Contributing\n\nFeel free to contribute to the development of this SDK. You can contribute by:\n\n1. Forking the repository and submitting a pull request with your changes.\n2. Reporting issues and bugs using the GitHub issue tracker.\n3. Suggesting new features or improvements.\n\nPlease ensure that any contributions follow the coding style and standards outlined in the repository.\n\n---\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenyleap%2Fethereum-cpp-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgenyleap%2Fethereum-cpp-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenyleap%2Fethereum-cpp-sdk/lists"}