The token issuer issues 1000000000 assets on Zetrix, the token code is GLA and the token name is Global. The specific information is as follows:
Explain:
code: Capitalized spell is recommended.
decimals: The number of decimal places which is in the range of 0~8, and 0 means no decimal place.
totalSupply: The total supply of the assets which are in the range of 0~2^63-1, and 0 means no limitation for the assets. For example, when issuing 10000 assets with 8 decimal places, the value of totalSupply is 1000000000000 (10 ^ 8 * 10000)
icon: Base64 bit encoding, and the size of the icon file is less than 32k,200*200 pixels is recommended.
version: The version number of the protocol, and its present value is 1.0.
Development Process for Token Issuing
In this document we use the Java language as an example to create an token issuer and issue 1000000000 assets.
Note: Please replace the [AccountAddressOfTokenIssuer] in the examples with the account address of the token to be issued by the token issuer. And replace the [AccountPrivateKeyOfTokenIssuer] in the examples with the account private key of the token to be issued by the token issuer.
Creating an SDK Instance
We create an instance with the following code and set its url (the IP and Port of the node).
A transaction can consist of multiple operations, each pointing to a specific transaction content.
Two operations are needed to issue assets: AssetIssueOperation, and AccountSetMetadataOperation.
The specific code for grouping operations for token issuing is as follows:
publicBaseOperation[] buildOperations() {// The account address to issue apt1.0 tokenString issuerAddress = [AccountAddressOfTokenIssuer];// The token nameString name ="Global";// The token codeString code ="GLA";// The apt token versionString version ="1.0";// The apt token iconString icon ="";// The total supply number of assetsLong totalSupply =1000000000L;// The present supply number of assetsLong nowSupply =1000000000L;// The token descriptionString description ="GLA TOKEN";// The token decimalsInteger decimals =0;// Build token issuance operationAssetIssueOperation assetIssueOperation =newAssetIssueOperation();assetIssueOperation.setSourceAddress(issuerAddress);assetIssueOperation.setCode(code);assetIssueOperation.setAmount(nowSupply);// If this is an asset you must set metadata like thisJSONObject assetsJson =newJSONObject();assetsJson.put("name", name);assetsJson.put("code", code);assetsJson.put("description", description);assetsJson.put("decimals", decimals);assetsJson.put("totalSupply", totalSupply);assetsJson.put("icon", icon);assetsJson.put("version", version);String key ="asset_property_"+ code;String value =assetsJson.toJSONString();// Build setMetadataAccountSetMetadataOperation accountSetMetadataOperation =newAccountSetMetadataOperation();accountSetMetadataOperation.setSourceAddress(issuerAddress);accountSetMetadataOperation.setKey(key);accountSetMetadataOperation.setValue(value);BaseOperation[] operations = {assetIssueOperation, accountSetMetadataOperation};return operations; }
Serializing Transactions
Transactions are serialized for network transmission.
Note:
feeLimit: The maximum fee the transaction initiator will pay for the transaction, and please fill in 50.03 Gas when the operation is issuing assets.
nonce: The nonce value of this transaction initiator, which can be obtained by adding 1 to the current nonce value.
The specific code for serializing transactions is as follows. In the example, nonce is the series number of account obtained by calling getAccountNonce, and operations is the operations for issuing assets obtained by calling buildOperations.
publicStringseralizeTransaction(Long nonce,BaseOperation[] operations) {String transactionBlob =null;// The account address to issue tokenString senderAddresss =[AccountAddressOfTokenIssuer];// The gasPrice is fixed at 1000L, the unit is UGasLong gasPrice =1000L;// Set up the maximum cost 50.03GasLong feeLimit =ToBaseUnit.ToUGas("50.03");// Nonce should add 1 nonce +=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; }
All transactions need to be signed to be valid. The signing result includes the signature data and the public key.
The specific code for signing transactions is as follows. In the example, transactionBlob is the string of the seralized transactions obtained by calling seralizeTransaction.
Sending transactions refers to sending the serialized transactions and the signatures to Zetrix.
The specific code for sending transactions is as follows. In the example, transactionBlob is the string of the seralized transactions obtained by calling seralizeTransaction, and signatures is the signature data obtained by calling signTransaction.
Note: The returned result of transactions sent represents whether the transaction is submitted successfully.
The specific code to call the interface is as follows. In the example, txHash is the hash value of transactions which is the unique identification obtained by calling submitTransaction.