Skip to content

szyzstop3/xuper-java-sdk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xuper-java-sdk

The java sdk of xuperunion https://github.com/xuperchain/xuperunion

Usage

Create client

XuperClient client = new XuperClient("127.0.0.1:37101");

Import account keys

// Import account from local keys
Account account = Account.create("./keys");

Create contract account

// The account name is XC1111111111111111@xuper
client.createContractAccount(account, "1111111111111111");

Transfer xuper to contract account

client.transfer(account, "XC1111111111111111@xuper", BigInteger.valueOf(1000000));

Query balance of account

 BigInteger result = client.getBalance("XC1111111111111111@xuper");

Deploy contract using contract account

// Using a contract account to deploy contract
account.setContractAccount("XC1111111111111111@xuper");
Map<String, byte[]> args = new HashMap<>();
args.put("creator", "icexin".getBytes());
String codePath = "./counter.wasm";
byte[] code = Files.readAllBytes(Paths.get(codePath));
// the runtime is c
client.deployWasmContract(account, code, "counter", "c", args);

Invoke contract

Map<String, byte[]> args = new HashMap<>();
args.put("key", "icexin".getBytes());
Transaction tx = client.invokeContract(account, "wasm", "counter", "increase", args);
System.out.println("txid: " + tx.getTxid());
System.out.println("response: " + tx.getContractResponse().getBodyStr());
System.out.println("gas: " + tx.getGasUsed());

Releases

No releases published

Packages

No packages published

Languages

  • Java 99.5%
  • PureBasic 0.5%