Zetrix Chain is a new generation of public chain for commercial use. An Internet infrastructure that is ubiquitous in value circulation is built on innovative core algorithms such as Gas Firework, Gas Orbits, Gas Canal, and developer-friendly smart contracts (Gas CodeMach). We provide comprehensive technical documentation and development tools for developers around the world to improve development efficiency and make it easier to access ecological applications. Developers have a better understanding of the Zetrix technical architecture and ecosystem by reading the documentation and using the tools. We welcome excellent developers, industry experts and influential leaders around the world to join the Zetrix developer ecosystem and become the cornerstone of Zetrix's global ecological development.
Zetrix provides public blockchain infrastructure services. This document helps developers access Zetrix and provides basic services such as creating blockchain accounts, issuing digital assets, and moving assets freely in the Zetrix network.
The following uses Java development as an example.
Instantiating the SDK
Note: Complete the basic configuration of the SDK before using it, such as setting the node for the SDK to access.
The example is as follows:
String url ="http://seed1-node.zetrix.com";SDK sdk =SDK.getInstance(url);The test network URL:http://seed1-node.zetrix.com
Creating Accounts
Note: You can create an account with the development toolkit provided by the development kit.
AccountCreateResult// privateKey The private key of the account// privbrosWxhfefT344E943xw2tnsiKVmuvG8hBHNFuxPZg7eHiMBPU6n// publicKey The private key of the account b00147b7c959f969079468e60c8f2d41f442b0f6a7b2d765d53e1a6fb272d496b2ebbe1158b5
// address The account address// ztxSnVDvg3gfW8as4BeodEJDDQAMXu9NobyvN
Note:
The account created in this mode is inactive (not chained) and cannot be found on the blockchain.
An account refers to a randomly generated digital identity of a user, item, institution, house, file, asset issuer account, etc. based on a cryptographic algorithm, usually called a blockchain account (public-private pair and blockchain account address). It is not controlled by any centralized organization and is completely controlled by the account owner.
Activating Accounts
Note:
An inactive account requires an account on the chain (an account that can be queried in Zetrix) to activate it.
Gas is a built-in token on Zetrix, and the transaction on the chain needs to consume Gas.
If you transfer the Gas of an account who is activated to target the account who is not activated, the target account will be activated.
Example code:
/** * Activate a new account */@TestpublicvoidactivateAccount() {// The account private key to activate a new accountString activatePrivateKey ="privbyQCRp7DLqKtRFCqKQJr81TurTqG6UKXMMtGAmPG3abcM9XHjWvq";Long initBalance =ToBaseUnit.ToUGas("1000");// The fixed write 1000L, the unit is UGasLong gasPrice =1000L;// Set up the maximum cost 0.01GasLong feeLimit =ToBaseUnit.ToUGas("0.01");// Transaction initiation account's nonce + 1Long nonce =8L;// Generate a new account to be activatedKeypair keypair =Keypair.generator();System.out.println(JSON.toJSONString(keypair,true));String destAccount =keypair.getAddress();// 1. Get the account address to send this transactionString activateAddresss =getAddressByPrivateKey(activatePrivateKey);// 2. Build activateAccountAccountActivateOperation operation =newAccountActivateOperation();operation.setSourceAddress(activateAddresss);operation.setDestAddress(destAccount);operation.setInitBalance(initBalance);operation.setMetadata("activate account");String[] signerPrivateKeyArr = {activatePrivateKey};// Record txhash for subsequent confirmation of the real result of the transaction.// After recommending five blocks, call again through txhash `Get the transaction information// from the transaction Hash'(see example: getTxByHash ()) to confirm the final result of the transactionString txHash =submitTransaction(signerPrivateKeyArr, activateAddresss, operation, nonce, gasPrice, feeLimit);if (txHash !=null) {System.out.println("hash: "+ txHash); }}
Recording Evidence Information
Note: The evidence information on the blockchain will be permanently stored
Obtaining the Account Nonce Value
Note: Each account maintains its own serial number, which starts from 1 and is incremented. A serial number marks a transaction for the account.
/** * Assembling the Operation for Storing Evidence * @param txOriginatorAddress The initiator's account address * @param evidenceKey Evidence KEY * @param evidenceInfo Evidence info * @param txFee Blockchain transaction fee,in Gas, Note: The more storage content, the more cost you need * @return */ public AccountSetMetadataOperation buildStoreEvidence(String txOriginatorAddress,String evidenceKey,String evidenceInfo){
//Assemble the evidence data of the transactions// The evidence key facilitate retrieval of evidence informationString key = evidenceKey;// Evidence contentString value = evidenceInfo;AccountSetMetadataOperation operation =newAccountSetMetadataOperation();operation.setSourceAddress(txOriginatorAddress);operation.setKey(key);operation.setValue(value);return operation; }
Serializing Transactions
Note: Serialize transactions for network transmission.
Example code:
publicStringseralizeTransaction(String txOriginatorAddress,BaseOperation[] operations,String txFee) {String transactionBlob =null;// The unit price of the transaction fee (transaction is charged in bytes, the unit is UGas, 1 Gas = 10^8 UGas)Long gasPrice =1000L;// Transaction cost (in UGas, 1 Gas = 10^8 UGas)Long feeLimit =ToBaseUnit.ToUGas(txFee);//1. Get the memory account nonceLong txOriginatorNonce =getAccountNonce(txOriginatorAddress);// Nonce plus 1 as the block transaction number txOriginatorNonce +=1;// Build transaction BlobTransactionBuildBlobRequest transactionBuildBlobRequest =newTransactionBuildBlobRequest();transactionBuildBlobRequest.setSourceAddress(senderAddresss);transactionBuildBlobRequest.setNonce(nonce);transactionBuildBlobRequest.setFeeLimit(feeLimit);transactionBuildBlobRequest.setGasPrice(gasPrice);for (int i =0; i <operations.length; i++) {transactionBuildBlobRequest.addOperation(operations[i]); } TransactionBuildBlobResponse transactionBuildBlobResponse = sdk.getTransactionService().buildBlob(transactionBuildBlobRequest);
if (transactionBuildBlobResponse.getErrorCode() ==0) { transactionBlob =transactionBuildBlobResponse.getResult().getTransactionBlob(); } else {System.out.println("error: "+transactionBuildBlobResponse.getErrorDesc()); }return transactionBlob;}// Note:// txFee: The transaction fee for this transaction, the more the certificate content, the more the cost
Note: After the transaction is serialized, the transaction initiator needs to identify the transaction data (sign with the private key), usually called the signature of the data. The signature results include signature data and a public key.
// (signatures)// signData: Blob// 6CGas42B11253BD49E7F1A0A90EB16448C6BC35E8684588DAB8C5D77B5E771BD5C7E1718942B32F9BDE14551866C00FEBA832D92F88755226434413F98E5A990C;
// publicKey: Account public key (transaction initiator's account public key)// b00179b4adb1d3188aa1b98d6977a837bd4afdbb4813ac65472074fe3a491979bf256ba63895
Submitting Transactions
Note:
After the transaction data is signed, the transaction metadata (transactionBlob) and signatures (transaction broadcast) need to be submitted (transaction broadcast) to the blockchain network.
When the transaction involves multiple parties (multiple signature accounts), multiple signatures must be submitted to the Zetrix network when submitting the transaction.
When a transaction involves multiple parties (multiple signature accounts), multiple signatures must be submitted to the Zetrix network when submitting the transaction.
After submitting the transaction (broadcast transaction), the final result of the transaction can be obtained in about 10 seconds. The developer can query the final status by using the query interface of transaction status.
Querying Transaction Status
Note: The final state of the query transaction can be queried through this interface. Usually, the final result of the transaction can be obtained 10 seconds after the transaction is submitted.