Java

Java developers can easily interact with the Zetrix blockchain using the Zetrix Java SDK, offering a streamlined and efficient way to build blockchain-enabled applications.

Overview

The Zetrix Java SDK enables developers to interact seamlessly with the Zetrix blockchain through a high-level, intuitive API. This powerful toolkit abstracts the complexities of blockchain operations, allowing you to focus on innovation. It streamlines tasks such as account management, smart contract deployment, transaction creation, block data retrieval, and more.

Target Audience

The Zetrix Java SDK is built for developers with a solid background in Java, especially those aiming to develop API services that interact with the Zetrix blockchain. Whether you're a veteran in blockchain or just getting started, the SDK provides an approachable and efficient path 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 packagearrow-up-right in your pom.xml.

The repositories required:

<repositories>
	<repository>
		<id>bubi-release</id>
		<name>releases</name>
		<url>http://maven.bubidev.cn/repository/releases</url>
	</repository>
	<repository>
		<id>bubi-snapshot</id>
		<name>snapshots</name>
		<url>http://maven.bubidev.cn/repository/snapshots</url>
	</repository>
	<repository>
		<id>bubi-thirdparty</id>
		<name>thirdparty</name>
		<url>http://maven.bubidev.cn/repository/thirdparty</url>
	</repository>
	<repository>
		<id>danubetech-maven-public</id>
		<url>https://repo.danubetech.com/repository/maven-public/</url>
	</repository>
</repositories>

The dependencies required:

Do note that the individual environments may differ. Please create an issue herearrow-up-right if you face any problems setting up your environment for development.

Prerequisites

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 repositoryarrow-up-right.

Last updated