- Notifications
You must be signed in to change notification settings - Fork4
virtualeconomy/java-v-sdk
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Java library for V Systems
To use this SDK, we need Java 1.8. First of all, update the repository
$ sudo apt-get update
Install Java in your machine
$ sudo apt-get install openjdk-8-jdk
Check Java version (remove the old version Java if needed).
$ java -versionopenjdk version"1.8.0_181"OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-0ubuntu0.16.04.1-b13)OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
clone this project
$ git clone https://github.com/virtualeconomy/java-v-sdk.git
import GSON jar to your project. You can download gson.jar fromGson Release. If you are using Maven, you can add dependency looks like this:
<dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.5</version></dependency>
For testnet chain:
importv.systems.Blockchain;importv.systems.type.NetworkType;Blockchainchain =newBlockchain(NetworkType.Testnet,"http://test.v.systems:9922");
For mainnet chain:
importv.systems.Blockchain;importv.systems.type.NetworkType;Blockchainchain =newBlockchain(NetworkType.Mainnet,"https://wallet.v.systems/api");
Call node internal used API with API key (to avoid
Provided API key is not correct
error):importv.systems.Blockchain;importv.systems.type.NetworkType;Blockchainchain =newBlockchain(NetworkType.Testnet,"http://test.v.systems:9922","<API_KEY>");List<Transaction>txList =chain.getActiveLeaseTransactions(testAddress);
Create account by seed
importv.systems.Account;importv.systems.type.NetworkType;Accountacc =newAccount(NetworkType.Testnet,"<your seed>",0);
Create account by private key
importv.systems.Account;importv.systems.type.NetworkType;Accountacc =newAccount(NetworkType.Testnet,"<base58 private key>");
Create account by public key
importv.systems.Account;importv.systems.type.NetworkType;Accountacc =newAccount(NetworkType.Testnet,"<base58 public key>",null);
Create account by address
importv.systems.Account;importv.systems.type.NetworkType;Accountacc =newAccount(NetworkType.Testnet,null,"<base58 address>");
Send Payment transaction
Longamount =1 *Blockchain.V_UNITY;// Send 1.0 V coinPaymentTransactiontx =TransactionFactory.buildPaymentTx("<recipient address>",amount);StringtxId =tx.getId();// get Tx ID offline// Usage 1: for hot wallet sending transactionTransactionresult =acc.sendTransaction(chain,tx);// Usage 2: for cold wallet signing transactionStringsignature =acc.getSignature(tx);
Send Lease transaction
Longamount =1 *Blockchain.V_UNITY;// Lease 1.0 V coinLeaseTransactiontx =TransactionFactory.buildLeaseTx("<recipient address>",amount);StringtxId =tx.getId();// get Tx ID offline// Usage 1: for hot wallet sending transactionTransactionresult =acc.sendTransaction(chain,tx);// Usage 2: for cold wallet signing transactionStringsignature =acc.getSignature(tx);
Send Token by executing contract function
First of all, if we do not know any Token information, we could get information by
tokenId
ContractTypetokenType =chain.getContractTypeByTokenId(tokenId);TokenInfotokenInfo =chain.getTokenInfo(tokenId);LongtokenUnity =tokenInfo.getUnity();
Then we send the token by executing contract function
Longamount =1 *tokenUnity;// Send 1.0 TokenExecuteContractFunctionTransactiontx =TransactionFactory.buildSendTokenTx(tokenId,tokenType,"<recipient address>",amount);StringtxId =tx.getId();// get Tx ID offline// Usage 1: for hot wallet sending transactionTransactionresult =acc.sendTransaction(chain,tx);// Usage 2: for cold wallet signing transactionStringsignature =acc.getSignature(tx);
About
Java library for V Systems