Code Monkey home page Code Monkey logo

hedera-sdk-cpp's Introduction

Hedera™ C++ SDK

The SDK for interacting with Hedera Hashgraph: the official distributed consensus platform built using the hashgraph consensus algorithm for fast, fair and secure transactions. Hedera enables and empowers developers to build an entirely new class of decentralized applications.

Prerequisites

For MacOS and Linux users:

  • ninja
    • MacOS: brew install ninja
    • Linux: apt-get install ninja
  • pkg-config
    • MacOS: brew install pkg-config
    • Linux: apt-get install pkg-config
  • cmake
    • MacOS: brew install cmake
    • Linux: apt-get install cmake

📣 Note: Ensure you install all three ninja, pkg-config, and cmake to avoid errors in subsequent steps. The installations might take a few minutes.

For Windows users:

  • Visual Studio 2019/2022 Community/Pro with Universal Windows Platform Development Tools
  • Perl (perl.exe must be added to %PATH%)
  • NASM (nasm.exe must be added to %PATH%)

Build

This project features CMake Presets which simplify the setup of vcpkg based dependencies. The below commands are typically all that is required.

  1. Clone the project
git clone https://github.com/hashgraph/hedera-sdk-cpp.git
  1. CD to the project directory
cd hedera-sdk-cpp
  1. Complete the following tasks within your project directory for the build you want
# Ensure the VCPkg Submodule is initialized
git submodule update --init

# Windows (x64) Build
cmake --preset windows-x64-release
cmake --build --preset windows-x64-release

# Linux (x64) Build
cmake --preset linux-x64-release
cmake --build --preset linux-x64-release

# MacOS (Intel x64) Build
cmake --preset macos-x64-release
cmake --build --preset macos-x64-release

# MacOS (Aarch64) Build
cmake --preset macos-arm64-release
cmake --build --preset macos-arm64-release

Testing

To run all SDK tests (for Release or Debug builds):

ctest -C [Release|Debug] --test-dir build/<PRESET>

To run all SDK unit tests and test vectors:

ctest -C [Release|Debug] --test-dir build/<PRESET> -R "TestVectors|UnitTests"

To run all SDK integration tests:

ctest -C [Release|Debug] --test-dir build/<PRESET> -R "IntegrationTests"

To run a specific test:

ctest -C [Release|Debug] --test-dir build/<PRESET> -R <NAME OF TEST>

Running Integration Tests

To run the integration tests it's necessary to have a running Hedera Local Node. If the local node is already running, check the configuration JSON file for the network settings. Ensure the values for network tag contains a valid AccountId and a valid IP address for an operational node.

Example config file:

{
  "network": {
    "0.0.3": "127.0.0.1:50211"
  },
  "mirrorNetwork": [
    "127.0.0.1:5600"
  ],
  "operator": {
    "accountId": "0.0.2",
    "privateKey": "302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137"
  }
}

(Source: config/local_node.json)

Examples

Examples must be run from the root directory in order to correctly access the address book and configuration files located in the addressbook/ and config/ directories. Make sure your .env file is populated with:

  • OPERATOR_ID: The ID of the operator account.
  • OPERATOR_KEY: The DER-encoded hex private key of the operator account.
  • HEDERA_NETWORK: The Hedera network name. Must be one of mainnet, testnet, or previewnet.
  • PASSPHRASE: Optional variable used by hedera-sdk-cpp-generate-private-key-from-mnemonic-example to generate a private key from a mnemonic with a passphrase.

The command to run an example looks like:

build/<PRESET>/sdk/examples/[Release|Debug]/<EXAMPLE_NAME>
  • <PRESET>: the preset that was used to build in Step 3 under Build.
  • [Release|Debug]: Release if you built in Release mode, otherwise Debug.
  • <EXAMPLE_NAME>: The name of the example you are trying to run.

If you're trying to run an example from the release artifacts, you must first cd into the architecture folder of the OS on which you are trying to run the example. For example, if you are running an x86_64 architecture on Linux:

cd [Release|Debug]/Linux/x86_64

From there, you can run:

examples/<EXAMPLE_NAME>

NOTE: Make sure you copy your .env file with your environment variables into this folder as well.

Additionally, the examples can be run using the run_examples scripts(.sh for macOS, Linux/ .bat for Windows systems) from the project root directory. In the scripts you will find an EXECUTABLES_DIRECTORY variable.

EXECUTABLES_DIRECTORY = <build_folder_with_exec_binaries>

Make sure to set it to the proper build folder of the binaries after building the project.

Contributing to this Project

We welcome participation from all developers!

For instructions on how to contribute to this repo, please review the Contributing Guide for C++.

More instructions for contribution can be found in the Global Contributing Guide.

Code of Conduct

This project is governed by the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code of conduct.

If you need to prepare a new SDK release, then see the Step-by-Step guide how to do it.

License

Apache License 2.0

hedera-sdk-cpp's People

Contributors

dependabot[bot] avatar deyanzz avatar gsstoykov avatar isavov avatar litt3 avatar nathanklick avatar rbair23 avatar rbarkersl avatar rwalworth avatar simihunjan avatar theekrystallee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hedera-sdk-cpp's Issues

Implement a basic `AccountBalanceQuery`

Implement a basic AccountBalanceQuery, where a user can query for the balance of an account or a contract.

Include implementations of the following APIs:
AccountId getAccountId(); const
AccountBalanceQuery& setAccountId(const AccountId& accountId);
ContractId getContractId() const;
AccountBalanceQuery& setContractId(const ContractId& contractId);

Implement a basic `Transaction` base class

Implement a basic transaction base class, which will hold information about the transaction's validity, cost, fee, and memo.

Include implementations of the following APIs:
std::chrono::duration<std::chrono::milliseconds> getTransactionValidDuration() const;
T& setTransactionValidDuration(const std::chrono::duration<std::chrono::milliseconds>& validDuration);
Hbar getMaxTransactionFee() const;
T& setMaxTransactionFee(const Hbar& maxTransactionFee);
Hbar getDefaultMaxTransactionFee() const;
std::string getTransactionMemo() const;
T& setTransactionMemo(const std::string& memo) const;
TransactionId getTransactionId() const;
T& setTransactionId(const TransactionId& transactionId) const;

Implement a basic `TransactionReceipt`

Implement a basic transaction receipt, which contains information about a transaction processed by the Hedera network.

Include implementations of the following APIs:
TransactionId transactionId;
Status status;
ExchangeRate exchangeRate;
AccountId accountId;

Implement a basic `Executable` base class

Implement a basic executable base class, which handles submitting transactions/queries.

Include implementations of the following APIs:
std::vector<AccountId> getNodeAccountIds() const;
SdkRequestType setNodeAccountIds(const std::vector<AccountId>& nodeAccountIds);
SdkResponseType execute(const Client& client);
SdkResponseType execute(const Client& client, std::chrono::duration<std::chrono::millisecond> timeout);

Combine alias member variables

  • Several classes currently hold onto a key alias member, as well as an EVM address alias member
  • Since any alias is a public key, and we can only have 1 alias at a time, it makes sense to combine these into a single member variable

Add support for GRPC and Protobuf Libraries in HAPI library artifacts

Problem

As reported by @rwalworth, the selective linker logic removes unused objects from the final libhapi.a static library. However, the SDK needs to use some of those GRPC / protobuf primitives which have been excluded from the libhapi static library by the linker.

Solution

The libhapi distribution has been updated to include the additional static libraries along side the libhapi.a static library. We need to update the cmake definitions to make use of these additional libraries.

Alternatives

No response

Implement a basic `TransactionRecord`

Implement a basic TransactionRecord type, which will contain more information about a transaction processed by the Hedera network.

Include implementations of the following APIs:
TransactionReceipt receipt;
std::string transactionHash;
std::chrono::system_clock::time_point consensusTimestamp;
TransactionId transactionId;
std::string transactionMemo;
Hbar transactionFee;

Implement a basic `Client`

Implement a basic client, useful for initial transaction and query signing and execution.

Include implementations of the following APIs:
static Client forTestnet();
Client setOperator(const AccountId& accountId, const PrivateKey& privateKey);
AccountId getOperatorAccountId() const;
PublicKey getOperatorPublicKey() const;
Hbar getDefaultMaxTransactionFee() const;
Hbar getDefaultMaxQueryPayment() const;
void close();
void close(std::chrono::duration<std::chrono::milliseconds> timeout);

Implement a basic `AccountCreateTransaction`

Implement a basic AccountCreateTransaction type, which will contain all fields needed to create a new account.

Include implementations for the following APIs:
AccountCreateTransaction& setKey(const Key& key);
AccountCreateTransaction& setInitialBalance(const Hbar& initialBalance);
AccountCreateTransaction& setReceiverSignatureRequired(bool receiveSignatureRequired);
AccountCreateTransaction& setAutoRenewPeriod(const std::chrono::seconds& autoRenewPeriod);
AccountCreateTransaction& setMaxAutomaticTokenAssociations(int32_t associations);
AccountCreateTransaction& setAccountMemo(const std::string& memo);
AccountCreateTransaction& setStakedAccountId(const AccountId& stakedAccountId);
AccountCreateTransaction& setStakedNodeId(const int64_t& stakedNodeId);
AccountCreateTransaction& setDeclineStakingReward(bool declineStakingReward);
AccountCreateTransaction& setAliasKey(const PublicKey& aliasKey);
AccountCreateTransaction& setAliasEvmAddress(const EvmAddress& aliasEvmAddress);
Key getKey() const;
Hbar getInitialBalance() const;
bool getReceiverSignatureRequired() const;
std::chrono::seconds getAutoRenewPeriod() const;
int32_t getMaxAutomaticTokenAssociations() const;
std::string getAccountMemo() const;
AccountId getStakedAccountId() const;
int64_t getStakedNodeId() const;
bool getDeclineStakingReward() const;
PublicKey getAliasKey() const;
EvmAddress getAliasEvmAddress() const;

Implement a basic `Query` base class

Implement a basic query base class, to contain payment and transaction informations for queries.

Include implementations of the following APIs:
T& setQueryPayment(Hbar queryPayment);
T& setMaxQueryPayment(Hbar maxQueryPayment)

Add support for using the prebuilt HAPI Library to CMake

Problem

We need to add support for using the prebuilt HAPI statically linked library to the CMake build. Additionally, we should also add support for vcpkg to manage dependencies along with CMake Presets.

Solution

  • Add FetchContents directives to pull in the library and include it in the build.
  • Update the .gitignore definitions.
  • Add vcpkg support to the build.

Alternatives

None

Implement a basic `TransferTransaction` for simple HBAR transfers only

Implement a basic TransferTransaction type, which will contain all fields needed to transfer Hbar between accounts.

Include implementations for the following APIs:
std::unordered_map<AccountId, Hbar> getHbarTransfers() const;
TransferTransaction& addHbarTransfer(const AccountId& accountId, const Hbar& value);
TransferTransaction& addApprovedHbarTransfer(const AccountId& accountId, const Hbar& value);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.