Skip to content

syntifi/casper-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java CI GitHub tag (latest SemVer) Project license

Casper Java SDK

This project implements the SDK to interact with a Casper Node. It wraps the Json-RPC requests and maps the results to Java objects.

Dependencies

Build instructions

./gradlew build

Including the library

Using gradle:

implementation 'com.syntifi.casper:casper-sdk:0.2.1'

Using maven:

<dependency>
  <groupId>com.syntifi.casper</groupId>
  <artifactId>casper-sdk</artifactId>
  <version>0.2.1</version>
</dependency>

How to

casperService = CasperService.usingPeer("127.0.0.1","7777");

2. Query a block

Retrieve block info by a block identifier

JsonBlockData result = casperService.getBlock();
JsonBlockData result = casperService.getBlock(new HeightBlockIdentifier(1234));
JsonBlockData blockData = casperService.getBlock(new HashBlockIdentifier("--hash--"));

3. Query transfers

Retrieve block transfers by a block identifier

TransferData transferData = casperService.getBlockTransfers();
TransferData transferData = casperService.getBlockTransfers(new HeightBlockIdentifier(1234));
TransferData transferData = casperService.getBlockTransfers(new HashBlockIdentifier("--hash--"));

3. Query state root hash

Retrieve the state root hash given the BlockIdentifier

StateRootHashData stateRootData = casperService.getStateRootHash();
StateRootHashData stateRootData = casperService.getStateRootHash(new HeightBlockIdentifier(1234));
StateRootHashData stateRootData = casperService.getStateRootHash(new HashBlockIdentifier("--hash--"));

Get a Deploy from the network

DeployData deployData = casperService.getDeploy("--hash--");

Get network peers data

PeerData peerData = casperService.getPeerData();

Retrieve a stored value from the network

StoredValueData result = casperService.getStateItem("--stateRootHash--", "key", Arrays.asList("The path components starting from the key as base"));

Return the current status of the node

StatusData status = casperService.getStatus()

8. Get account info

Returns an Account from the network

AccountData account = casperService.getStateAccountInfo("--publicKey--", new HeightBlockIdentifier(1234));
AccountData account = casperService.getStateAccountInfo("--publicKey--", new HashBlockIdentifier("--hash--"));

9. Get auction info

Returns the Auction info for a given block

AuctionData auction = casperService.getStateAuctionInfo(new HeightBlockIdentifier(1234));
AuctionData auction = casperServiceMainnet.getStateAuctionInfo(new HashBlockIdentifier("--hash--"));

10. Get era info

Returns an EraInfo from the network

EraInfoData eraInfoData = casperService.getEraInfoBySwitchBlock(new HeightBlockIdentifier(1234));
EraInfoData eraInfoData = casperService.getEraInfoBySwitchBlock(new HashBlockIdentifier("--hash--"));

11. Deploy

Deploy deploy = CasperDeployService.buildTransferDeploy(from, to,
    BigInteger.valueOf(2500000000L), "casper-test",
    id, BigInteger.valueOf(100000000L), 1L, ttl, new Date(),
    new ArrayList<>());

DeployResult deployResult =  casperServiceTestnet.putDeploy(deploy);