Scala client library for interracting with CasperLabs nodes.
Current version :1.2.3
In your build.sbt, add :
libraryDependencies += "io.caspercommunity" %% "casper-scala-sdk" % "1.2.3"
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
- getPeers
- getStateRootHash
- getBlock by hash
- getBlock by height
- getStatus
- getBlockTransfers
- getAuctionInfo
- getDeploy
- getEraInfoBySwitchBlock
- queryGlobalState
- getAccountInfo
- getBalance
- getDictionaryItem
- putDeploy
- getEraSummary
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
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
git clone https://github.com/abahmanem/casper-scala-sdk
cd casper-scala-sdk
sbt test
sbt package
This will generate : casper-scala-sdk_${scala.version}{version}.jar.
Pass the url of the node to constructor
val client = new CasperSdk("http://node_ip_address:7777/rpc")
Retrieves the list of connected peers.
val tryPeers:Try[PeerResult] = client.getPeers()
val listOfPeers = tryPeers.getOrElse(List.empty)
Retrieves the state root hash String.
val tryStateRootHash:Try[StateRootHashResult] = client.getStateRootHash("")
Retrieves a Block object.
call parameters :
- block hash
val tryBlock:Try[BlockResult] = client.getBlock( HashBlockIdentifier("74dce8911A3EDf0f872dC11F0a63Ca9fE1b55b7188a9Feaaf431518bF9c508B4"))
call parameters :
- block height
val tryBlock:Try[BlockResult] = client.getBlockByHeight(HeightBlockIdentifier(371608L))
Retrieves a Deploy object.
call parameters :
- deploy hash
val tryDeploy:Try[DeployResult] = getDeploy("5545207665f6837F44a6BCC274319280B73a6f0997F957A993e60f878A736678")
Retrieves a NodeStatus object.
val tryNodeSatatus:Try[NodeSatatus] = client.getStatus
Retrieves Transfert List within a block.
call parameters :
- block hash
val tryTransfers : Try[TransferResult] = client.getBlockTransfers("a623841478381D78C769636582305ef724f561d7314B4daED19A3EA6373Dd778")
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("")
Retrieves an EraSummury object.
call parameters :
- switch block (last block within an era) hash
val tryErasummury : Try[EraSummaryResult] = client.getEraInfoBySwitchBlock("1e46B4c173dB70fDE0E867FF679ACa24e1c5Bea3C4333af94e53B4E3BC548B6B")
Retrieves a StoredValue object.
It's one of three possible values :
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
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
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
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
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"))
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))
The Casper Scala SDK is open-sourced software licensed under the MIT license.