Java
Java developers can easily operate on the Zetrix blockchain via the Zetrix Java SDK!
Overview
The Zetrix Java SDK empowers developers to seamlessly interact with the Zetrix blockchain. This robust toolkit provides a high-level abstraction over complex blockchain interactions, allowing you to focus on building innovative applications. With its intuitive API and comprehensive features, the SDK simplifies account management, smart contract deployment, transaction creation, block info and more.
Target Audience
The Zetrix Java SDK is designed for developers with a solid understanding of Java and intends to build an API service to interact with Zetrix. Whether you're a seasoned blockchain developer or new to the space, the SDK offers a user-friendly onramp to building on Zetrix.
Quick Start Guide
Installation
Getting started with the Zetrix Java SDK is straightforward. In this tutorial we will be using Maven for dependency management. Follow these steps to include the package in your pom.xml
.
The repositories required:
The dependencies required:
Do note that the individual environments may differ. Please create an issue here if you face any problems setting up your environment for development.
Prerequisites
Zetrix Wallet installed.
A Zetrix account with sufficient balance. Claim your faucet here.
Basic Usages
Included in this section are some sample code snippets to help you get started with the SDK.
Create a Zetrix Java SDK instance to begin using the SDK.
If you're using the Zetrix testnet, initialize with this URL:
If you're using the Zetrix mainnet, initialize with this URL:
Let's look at some examples:
Getting the nonce for a particular address:
Submitting a transaction:
Getting the balance of a particular address:
Getting transaction info:
API References
Account APIs
Purpose: Retrieves the nonce of an account.
Parameters:
AccountGetNonceRequest
- Contains the address of the account to retrieve the nonce for.Return:
AccountGetNonceResponse
- The response object containing the account's nonce.
Purpose: Retrieves metadata for an account.
Parameters:
AccountGetMetadataRequest
- Contains the address and key of the metadata to retrieve.Return:
AccountGetMetadataResponse
- The response object containing the account's metadata.
Purpose: Retrieves the balance of an account.
Parameters:
AccountGetBalanceRequest
- Contains the address of the account to retrieve the balance for.Return:
AccountGetBalanceResponse
- The response object containing the account's balance.
Purpose: Retrieves information about an account.
Parameters:
AccountGetInfoRequest
- Contains the address of the account to retrieve information for.Return:
AccountGetInfoResponse
- The response object containing the account information.
Purpose: Checks if an account address is valid.
Parameters:
AccountCheckValidRequest
- Contains the address to be validated.Return:
AccountCheckValidResponse
- The response object indicating whether the address is valid.
Purpose: Creates a new account by generating a new private key, public key, and address.
Parameters: None.
Return:
AccountCreateResponse
- The response object containing the new account's private key, public key, and address.
Purpose: Checks if an account is activated.
Parameters:
AccountCheckActivatedRequst
- Contains the address of the account to check.Return:
AccountCheckActivatedResponse
- The response object indicating whether the account is activated.
Block APIs
Purpose: Retrieves the current block number from the blockchain.
Parameters: None.
Return:
BlockGetNumberResponse
- Contains the block number and any error information if applicable.
Purpose: Retrieves information about a specific block.
Parameters:
BlockGetInfoRequest
- Contains the block number for which information is requested.Return:
BlockGetInfoResponse
- Contains block information and any error information.
Purpose: Retrieves transactions for a specific block number.
Parameters:
BlockGetTransactionsRequest
- Contains the block number for which transactions are requested.Return:
BlockGetTransactionsResponse
- Contains transaction details and any error information.
Purpose: Checks the synchronization status of the blockchain.
Parameters: None.
Return:
BlockCheckStatusResponse
- Indicates whether the blockchain is synchronized and includes any error information.
Purpose: Retrieves information about the latest block.
Parameters: None.
Return:
BlockGetLatestInfoResponse
- Contains the latest block information and any error information.
Purpose: Retrieves validator information for a specific block.
Parameters:
BlockGetValidatorsRequest
- Contains the block number for which validator information is requested.Return:
BlockGetValidatorsResponse
- Contains validator details and any error information.
Purpose: Retrieves information about the latest validators.
Parameters: None.
Return:
BlockGetLatestValidatorsResponse
- Contains the latest validator information and any error information.
Purpose: Retrieves reward distribution information for a specific block.
Parameters:
BlockGetRewardRequest
- Contains the block number for which reward information is requested.Return:
BlockGetRewardResponse
- Contains reward distribution details and any error information.
Purpose: Retrieves the latest reward distribution information.
Parameters: None.
Return:
BlockGetLatestRewardResponse
- Contains the latest reward distribution details and any error information.
Purpose: Retrieves fee information for a specific block.
Parameters:
BlockGetFeesRequest
- Contains the block number for which fee information is requested.Return:
BlockGetFeesResponse
- Contains fee details and any error information.
Purpose: Retrieves the latest fee information.
Parameters: None.
Return:
BlockGetLatestFeesResponse
- Contains the latest fee details and any error information.
Transaction APIs
Purpose: Constructs a transaction blob from the given request, which includes validating the request parameters and building the transaction.
Parameters:
TransactionBuildBlobRequest
- Contains details like source address, nonce, gas price, fee limit, metadata, and operations.Return:
TransactionBuildBlobResponse
- Contains the transaction blob and its hash if successful, or error details if an exception occurs.
Purpose: Parses a transaction blob into a readable format, converting it to JSON.
Parameters:
TransactionParseBlobRequest
- Contains the transaction blob to be parsed.Return:
TransactionParseBlobResponse
- Contains the parsed transaction details in JSON format or error details if an exception occurs.
Purpose: Signs a transaction blob using the provided private keys.
Parameters:
TransactionSignRequest
- Contains the transaction blob and an array of private keys for signing.Return:
TransactionSignResponse
- Contains the signatures and public keys if successful, or error details if an exception occurs.
Purpose: Submits a signed transaction to the blockchain network.
Parameters:
TransactionSubmitRequest
- Contains the transaction blob and signatures.Return:
TransactionSubmitResponse
- Contains the transaction hash if successful, or error details if an exception occurs.
Purpose: Retrieves information about a transaction using its hash.
Parameters:
TransactionGetInfoRequest
- Contains the hash of the transaction to be queried.Return:
TransactionGetInfoResponse
- Contains transaction details or error information if an exception occurs.
Purpose: Evaluates the fee required for a transaction based on the provided request details.
Parameters:
TransactionEvaluateFeeRequest
- Includes source address, nonce, signature number, metadata, and operations.Return:
TransactionEvaluateFeeResponse
- Contains the evaluated fee details or error information if an exception occurs.
Contract APIs
Purpose: Calls a contract with specified parameters.
Parameters:
ContractCallRequest
- An object containing details like source address, contract address, code, input, contract balance, gas price, and fee limit.Return:
ContractCallResponse
- The result of the contract call or error details if the call fails.
Purpose: Retrieves information about a specific contract using its address.
Parameters:
ContractGetInfoRequest
- An object containing the contract address.Return:
ContractGetInfoResponse
- Contains the contract information or error details if the request fails.
Purpose: Checks if a given contract address is valid.
Parameters:
ContractCheckValidRequest
- An object containing the contract address to be validated.Return:
ContractCheckValidResponse
- Indicates whether the contract address is valid or not.
Purpose: Retrieves the contract address associated with a given transaction hash.
Parameters:
ContractGetAddressRequest
- An object containing the transaction hash.Return:
ContractGetAddressResponse
- Containing the contract address information or error details if the retrieval fails.
For code references on Zetrix's Java SDK, please visit our GitHub repository.
Last updated