Go
Go developers can now easily operate on the Zetrix blockchain via the Zetrix Go SDK!
Overview
The Zetrix Go 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, and more.
Target Audience
The Zetrix Go SDK is designed for developers with a solid understanding of Go/Golang. 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 Go SDK is straightforward. Follow these steps to install the package in your go.mod
file:
Let's create a main.go
file as your main executable file. Include these in your import statement:
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 Go SDK instance to begin using the SDK. Under the main()
function in your main.go
file, add the following snippet:
If you're using the Zetrix testnet, initialize the SDK with the testnet node URL:
If you're using Zetrix mainnet, initialize the SDK with the mainnet node URL:
Now, let's look at some simple 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: Checks the validity of a given account address.
Parameters:
reqData
(type: model.AccountCheckValidRequest) - Contains the account address to be validated.Return Value:
model.AccountCheckValidResponse
- Contains a boolean indicating if the address is valid and an error code.
Purpose: Creates a new account with a public and private key pair.
Parameters: None.
Return Value:
model.AccountCreateResponse
- Contains the public key, private key, address, and an error code.
Purpose: Retrieves information about an account.
Parameters:
reqData
(type: model.AccountGetInfoRequest) - Contains the account address for which information is requested.Return Value:
model.AccountGetInfoResponse
- Contains account information and an error code.
Purpose: Retrieves the nonce for a given account.
Parameters:
reqData
(type: model.AccountGetNonceRequest) - Contains the account address for which the nonce is requested.Return Value:
model.AccountGetNonceResponse
- Contains the nonce and an error code.
Purpose: Retrieves the balance of a given account.
Parameters:
reqData
(type: model.AccountGetBalanceRequest) - Contains the account address for which the balance is requested.Return Value:
model.AccountGetBalanceResponse
- Contains the balance and an error code.
Purpose: Retrieves the assets of a given account.
Parameters:
reqData
(type: model.AccountGetAssetsRequest) - Contains the account address for which assets are requested.Return Value:
model.AccountGetAssetsResponse
- Contains the assets and an error code.
Purpose: Retrieves metadata associated with a given account.
Parameters:
reqData
(type: model.AccountGetMetadataRequest) - Contains the account address and key for which metadata is requested.Return Value:
model.AccountGetMetadataResponse
- Contains the metadata and an error code.
Purpose: Checks if an account is activated.
Parameters:
reqData
(type: model.AccountCheckActivatedRequest) - Contains the account address to be checked.Return Value:
model.AccountCheckActivatedResponse
- Contains a boolean indicating if the account is activated and an error code.
Contract APIs
Purpose: Checks the validity of a contract address.
Parameters:
reqData
(type: model.ContractCheckValidRequest) - Contains the contract address to be validated.Return Value:
model.ContractCheckValidResponse
- Contains a boolean indicating if the contract address is valid and an error code.
Purpose: Retrieves information about a contract.
Parameters:
reqData
(type: model.ContractGetInfoRequest) - Contains the contract address for which information is requested.Return Value:
model.ContractGetInfoResponse
- Contains contract information and an error code.
Purpose: Calls a contract with specified parameters.
Parameters:
reqData
(type: model.ContractCallRequest) - Contains details such as contract address, code, input, balance, fee limit, gas price, operation type, and source address.Return Value:
model.ContractCallResponse
- Contains the result of the contract call and an error code.
Purpose: Retrieves the contract address from a transaction hash.
Parameters:
reqData
(type: model.ContractGetAddressRequest) - Contains the transaction hash.Return Value:
model.ContractGetAddressResponse
- Contains contract address information and an error code.
Transaction APIs
Purpose: Constructs a transaction blob from the provided transaction details.
Parameters:
reqData
(type: model.TransactionBuildBlobRequest) - Contains transaction details such as source address, nonce, operations, etc.Return Value:
model.TransactionBuildBlobResponse
- Contains the transaction blob and an error code.
Purpose: Estimates the fee required for a transaction based on its details.
Parameters:
reqData
(type: model.TransactionEvaluateFeeRequest) - Contains transaction details such as source address, nonce, operations, etc.Return Value:
model.TransactionEvaluateFeeResponse
- Contains the estimated fee limit, gas price, and an error code.
Purpose: Signs a transaction blob using the provided private keys.
Parameters:
reqData (type: model.TransactionSignRequest): Contains the transaction blob and private keys for signing.
Return Value:
model.TransactionSignResponse
- Contains the signatures and an error code.
Purpose: Submits a signed transaction to the blockchain network.
Parameters:
reqData
(type: model.TransactionSubmitRequest) - Contains the transaction blob and signatures.Return Value:
model.TransactionSubmitResponse
- Contains the transaction hash and an error code.
Purpose: Retrieves information about a transaction using its hash.
Parameters:
reqData
(type: model.TransactionGetInfoRequest) - Contains the transaction hash.Return Value:
model.TransactionGetInfoResponse
- Contains transaction details and an error code.
Block APIs
Purpose: Retrieves the current block number from the blockchain.
Parameters: None.
Return Value:
model.BlockGetNumberResponse
- Contains the block number and an error code.
Purpose: Checks if the blockchain is synchronized.
Parameters: None.
Return Value:
model.BlockCheckStatusResponse
- Contains a boolean indicating synchronization status and an error code.
Purpose: Retrieves transactions for a specific block number.
Parameters:
reqData
(type: model.BlockGetTransactionRequest) - Contains the block number.Return Value:
model.BlockGetTransactionResponse
- Contains transaction details and an error code.
Purpose: Retrieves information about a specific block.
Parameters:
reqData
(type: model.BlockGetInfoRequest) - Contains the block number.Return Value:
model.BlockGetInfoResponse
- Contains block information and an error code.
Purpose: Retrieves information about the latest block.
Parameters: None.
Return Value:
model.BlockGetLatestResponse
- Contains the latest block information and an error code.
Purpose: Retrieves validators for a specific block number.
Parameters:
reqData
(type: model.BlockGetValidatorsRequest) - Contains the block number.Return Value:
model.BlockGetValidatorsResponse
- Contains validator information and an error code.
Purpose: Retrieves validators for the latest block.
Parameters: None.
Return Value:
model.BlockGetLatestValidatorsResponse
- Contains the latest validator information and an error code.
Purpose: Retrieves reward distribution for a specific block number.
Parameters:
reqData
(type: model.BlockGetRewardRequest) - Contains the block number.Return Value:
model.BlockGetRewardResponse
- Contains reward distribution details and an error code.
Purpose: Retrieves the latest reward distribution.
Parameters: None.
Return Value:
model.BlockGetLatestRewardResponse
- Contains the latest reward distribution details and an error code.
Purpose: Retrieves fee information for a specific block number.
Parameters:
reqData
(type: model.BlockGetFeesRequest) - Contains the block number.Return Value:
model.BlockGetFeesResponse
- Contains fee information and an error code.
Purpose: Retrieves the latest fee information.
Parameters: None.
Return Value:
model.BlockGetLatestFeesResponse
- Contains the latest fee information and an error code.
For code references on Zetrix's Go SDK, please visit our GitHub repository.
Last updated