BigInteger result = client.getBalance("XC1111111111111111@xuper");
Query balance details of account
XuperClient.BalDetails[] result = client.getBalanceDetails("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);
String abi = "[{\"inputs\":[{\"internalType\":\"uint256\"......";
String bin = "6080604......";
Map<String, String> args = new HashMap<>();
args.put("num", "5889");
Transaction t = client.deployEVMContract(account, bin.getBytes(), abi.getBytes(), contractName, args);
System.out.println("txID:" + t.getTxid());
// storagepay is a payable method. Amount param can be NULL if there is no need to transfer to the contract.
Transaction t1 = xuperClient.invokeEVMContract(account, contractName, "storepay", args, BigInteger.ONE);
System.out.println("txID:" + t1.getTxid());
System.out.println("tx gas:" + t1.getGasUsed());
Transaction t2 = xuperClient.queryEVMContract(account, contractName, "retrieve", null);
System.out.println("tx res getMessage:" + t2.getContractResponse().getMessage());
System.out.println("tx res getBodyStr:" + t2.getContractResponse().getBodyStr());
xuper-java-sdk
The java sdk of xuperunion https://github.com/xuperchain/xuperunion
Usage
Add Dependency
If your’re using Maven, just add the following dependency in
pom.xml.Config file
If you use the endorsement feature, set the configuration file like this:
The config file is here: src/main/java/com/baidu/xuper/conf/sdk.yaml.
Test net config file is here: src/main/java/com/baidu/xuper/conf/sdk.testnet.yaml.
Create client
Import account keys
Create account and mnemonic
Create contract account
Transfer xuper to contract account
Query balance of account
Query balance details of account
Deploy contract using contract account
Invoke contract
EVM contract