Skip to content

abahmanem/casper-scala-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About Casper Scala SDK

Scala client library for interracting with CasperLabs nodes.

Current version :1.2.3

How to install

SBT

In your build.sbt, add :

 libraryDependencies += "io.caspercommunity" %% "casper-scala-sdk" % "1.2.3"

Maven

In your maven pom file add :

<dependency>
  <groupId>io.caspercommunity</groupId>
  <artifactId>casper-scala-sdk_${scala.version}</artifactId>
  <version>1.2.3</version>
</dependency>  

scala.version is the scala version used, ex = 3.1.3

Documentation:

API

Serialization

Key Management

Casper-Scala-Sdk RPC

Running unit tests

Requirements:

JAVA

Make sure you have the Java 8 JDK (also known as 1.8)

If you don’t have version 1.8 or higher, install the JDK

SBT

Install sbt (version 1.5.2 or higher):

Mac : https://www.scala-sbt.org/1.x/docs/Installing-sbt-on-Mac.html

Windows : https://www.scala-sbt.org/1.x/docs/Installing-sbt-on-Windows.html

Linux : https://www.scala-sbt.org/1.x/docs/Installing-sbt-on-Linux.html

Clone the project

git clone https://github.com/abahmanem/casper-scala-sdk

Run the unit tests :

cd casper-scala-sdk

sbt test

Generate project artefact

sbt package

This will generate : casper-scala-sdk_${scala.version}{version}.jar.

Usage examples

Create a Client

Pass the url of the node to constructor

val client = new CasperSdk("http://node_ip_address:7777/rpc")

RPC Calls

Get network peers list

Retrieves the list of connected peers.

val tryPeers:Try[PeerResult] = client.getPeers()
val listOfPeers = tryPeers.getOrElse(List.empty)

Get State Root Hash

Retrieves the state root hash String.

 val tryStateRootHash:Try[StateRootHashResult] = client.getStateRootHash("")

Get Block

Retrieves a Block object.

using block hash :

call parameters :

  • block hash
val tryBlock:Try[BlockResult] = client.getBlock( HashBlockIdentifier("74dce8911A3EDf0f872dC11F0a63Ca9fE1b55b7188a9Feaaf431518bF9c508B4"))

using block height :

call parameters :

  • block height
val tryBlock:Try[BlockResult] = client.getBlockByHeight(HeightBlockIdentifier(371608L))

Get Deploy

Retrieves a Deploy object.

call parameters :

  • deploy hash
val tryDeploy:Try[DeployResult] = getDeploy("5545207665f6837F44a6BCC274319280B73a6f0997F957A993e60f878A736678")

Get Node Status

Retrieves a NodeStatus object.

 val tryNodeSatatus:Try[NodeSatatus] = client.getStatus

Get BlockTransfers

Retrieves Transfert List within a block.

call parameters :

  • block hash
val tryTransfers : Try[TransferResult] = client.getBlockTransfers("a623841478381D78C769636582305ef724f561d7314B4daED19A3EA6373Dd778")

Get current auction state

Retrieves an AutionState object.

call parameters :

  • block hash
val tryAuctionInfo : Try[AuctionStateResult] = client.getAuctionInfo(new HashBlockIdentifier("3a4EfA0AA223bF713bEDB5fa8D6dEc29a008C923aec0ACB02A3e4e449b9E01a8"))

can also be called without parameters :

val auctionInfo : Try[AuctionStateResult] = client.getAuctionInfo("")

Get EraInfo By Switch Block

Retrieves an EraSummury object.

call parameters :

  • switch block (last block within an era) hash
val tryErasummury :  Try[EraSummaryResult] = client.getEraInfoBySwitchBlock("1e46B4c173dB70fDE0E867FF679ACa24e1c5Bea3C4333af94e53B4E3BC548B6B")

Query Global state

Retrieves a StoredValue object.

It's one of three possible values :

A contract :

call parameters :

  • state root hash
  • contract hash
val tryStoredValue :  Try[GlobalStateResul] = client.queryGlobalState(StateRootHashIdentifier("30cE5146268305AeeFdCC05a5f7bE7aa6dAF187937Eed9BB55Af90e1D49B7956"),"hash-4dd10a0b2a7672e8ec964144634ddabb91504fe50b8461bac23584423318887d",Seq.empty)

 val contract  = tryStoredValue.success.value.stored_value.Contract

An account :

call parameters :

  • state root hash
  • account hash
val tryStoredValue : Try[GlobalStateResul] = client.queryGlobalState(StateRootHashIdentifier("30cE5146268305AeeFdCC05a5f7bE7aa6dAF187937Eed9BB55Af90e1D49B7956"),"account-hash-46dE97966cfc2F00C326e654baD000AB7a5E26bEBc316EF4D74715335cF32A88",Seq.empty)
val account  = tryStoredValue.success.value.stored_value.Account

A CLValue :

call parameters :

  • state root hash
  • account hash
val tryStoredValue :  Try[GlobalStateResul] = client.queryGlobalState(StateRootHashIdentifier("30cE5146268305AeeFdCC05a5f7bE7aa6dAF187937Eed9BB55Af90e1D49B7956"),"account-hash-46dE97966cfc2F00C326e654baD000AB7a5E26bEBc316EF4D74715335cF32A88",Seq.empty)
val clValue  = tryStoredValue.success.value.stored_value.CLValue

Get DictionaryItem

Retrieves a CLValue object.

call parameters :

  • state root hash
  • item key
  • seed uref hash
val tryStoredValue : Try[DictionaryItemResult] = client.getDictionaryItem("8180307A39A8583a4a164154C360FB9Ab9B15A5B626295635A62DFc7A82e66a3",
      "a8261377ef9cf8e741dd6858801c71e38c9322e66355586549b75ab24bdd73f2","uref-F5ea525E6493B41DC3c9b196ab372b6F3f00cA6F1EEf8fe0544e7d044E5480Ba-007")
val clValue =  tryStoredValue.success.value.stored_value.CLValue

Get Balance

Retrieves the balances(in motes) of an account

call parameters :

  • state root hash
  • account uref hash
 val  tryBalance :  Try[BalanceResult] = client.getBalance("30cE5146268305AeeFdCC05a5f7bE7aa6dAF187937Eed9BB55Af90e1D49B7956",new URef("uref-9cC6877ft07c211e44068D5dCc2cC28A67Cb582C3e239E83Bb0c3d067C4D0363-007"))

Get EraSummary

returns the era summary at either a specific block (by height or hash), or the most recently added block

call parameters :

  • BlockIdentifier (Hash or Height)
 val  eraSummary :  Try[EraSummaryResult] = client.getEraSummary(HeightBlockIdentifier(1730137L))

License

The Casper Scala SDK is open-sourced software licensed under the MIT license.