StarkNet SDK for JVM languages (java, kotlin, scala)

Overview

starknet jvm

StarkNet SDK for JVM languages:

  • Java
  • Kotlin
  • Scala
  • Clojure
  • Groovy

Table of contents

Documentation

Documentation is provided in two formats:

Example usages

Making synchronous requests

import com.swmansion.starknet.account.Account;
import com.swmansion.starknet.account.StandardAccount;
import com.swmansion.starknet.data.types.BlockTag;
import com.swmansion.starknet.data.types.Felt;
import com.swmansion.starknet.provider.Provider;
import com.swmansion.starknet.provider.Request;
import com.swmansion.starknet.provider.gateway.GatewayProvider;

public class Main {
    public static void main(String[] args) {
        // Create a provider for interacting with StarkNet
        Provider provider = GatewayProvider.makeTestnetClient();

        // Create an account interface
        Felt accountAddress = Felt.fromHex("0x13241455");
        Felt privateKey = Felt.fromHex("0x425125");
        Account account = new StandardAccount(provider, accountAddress, privateKey);

        // Make a request
        Felt contractAddress = Felt.fromHex("0x42362362436");
        Felt storageKey = Felt.fromHex("0x13241253414");
        Request<Felt> request = account.getStorageAt(contractAddress, storageKey, BlockTag.LATEST);
        Felt response = request.send();

        System.out.println(response);
    }
}

Making asynchronous requests

import com.swmansion.starknet.account.Account;
import com.swmansion.starknet.account.StandardAccount;
import com.swmansion.starknet.data.types.BlockTag;
import com.swmansion.starknet.data.types.Felt;
import com.swmansion.starknet.provider.Provider;
import com.swmansion.starknet.provider.Request;
import com.swmansion.starknet.provider.gateway.GatewayProvider;

import java.util.concurrent.CompletableFuture;

public class Main {
    public static void main(String[] args) {
        // Create a provider for interacting with StarkNet
        Provider provider = GatewayProvider.makeTestnetClient();

        // Create an account interface
        Felt accountAddress = Felt.fromHex("0x13241455");
        Felt privateKey = Felt.fromHex("0x425125");
        Account account = new StandardAccount(provider, accountAddress, privateKey);

        // Make a request
        Felt contractAddress = Felt.fromHex("0x42362362436");
        Felt storageKey = Felt.fromHex("0x13241253414");
        Request<Felt> request = account.getStorageAt(contractAddress, storageKey, BlockTag.LATEST);
        CompletableFuture<Felt> response = request.sendAsync();

        response.thenAccept(System.out::println);
    }
}

Development

Hooks

Run

./gradlew addKtlintFormatGitPreCommitHook
./gradlew addKtlintCheckGitPreCommitHook

Ensuring idiomatic Java code

We want this library to be used by both kotlin & java users. In order to ensure a nice API for java always follow those rules:

  1. When using file level functions use @file:JvmName(NAME) to ensure a nice name without Kt suffix.
  2. When using a companion object mark every property/function with @JvmStatic. This way they are accessible as static from the class. Without it Class.INSTANCE would have to be used.
  3. When defining an immutable constant use @field:JvmField. This makes them static properties without getters/setters in java.
  4. If you are not sure how something would work in java just create a new java class, import your code and check yourself.

Building documentation

Documentation is written in Kdoc format and markdown and is generated using Dokka. Execute following commands from /lib to build docs.

  • ./gradlew dokkaHtml to build kotlin format docs
  • ./gradlew dokkaHtmlJava to build java format docs

Generated documentation can be found in their respective folders inside /build/dokka.

Comments
  • Add missing transaction properties.

    Add missing transaction properties.

    Make sure that all transaction properties that are present in starknet-spec are also present in our transaction data classes.

    My proposal for working with both gateway and rpc:

    • fields present in gateway, but not in rpc => Ignore them
    • fields present in rpc but not in gateway => Make them non-optional (if they are so in the spec) and use some dummy value for them (like 0 for felts)
    blocked 
    opened by bartekryba 5
  • Support signed declare transaction

    Support signed declare transaction

    Describe your changes

    This PR adds support for signing declare transactions and sending them.

    Linked issues

    Closes #145

    Breaking changes

    • [ ] This issue contains breaking changes
    opened by cptartur 3
  • Feat/account methods

    Feat/account methods

    Draft of the new account methods #56.

    Main problem to consider here: Provider returns Requests, that can be called both synchronously, or asynchronously as futures. Provider's methods however make only one call. Both estimateFee and execute in Account make multiple calls. I was wondering if we would like to align account methods interface with the provider methods interface, i.e. also use Request. But this would require rethinking our Request model a bit and modifying it.

    opened by bartekryba 3
  • Add ConvertibleToTransactionPayload interface

    Add ConvertibleToTransactionPayload interface

    Describe your changes

    This PR attempts to standardize the behavior of toPayload method in Transactions by adding ConvertibleToTransactionPayload (subject to change) interface that indicates if Transaction (or any object for that matter) is convertible to TransactionPayload object.

    This PR is a suggestion, if the used approach is not preferred by other developers, it can be closed.

    Linked issues

    Closes

    Breaking changes

    • [ ] This issue contains breaking changes
    opened by cptartur 2
  • Support deploy account tx

    Support deploy account tx

    Describe your changes

    • Added deploy_account support to GatewayProvider and Account (signing txs).
    • Unfortunately cairo 10.1 changed a lot (required for deploy_account) in CLI and had to change DevnetClient.
    • Bumped devnet to version supporting cairo 10.1
    • Moved hash calculations to a separate utility class

    Linked issues

    Closes https://github.com/software-mansion/starknet-jvm/issues/131

    Breaking changes

    • [x] This issue contains breaking changes

    Adds one more transaction type

    opened by Solpatium 2
  • starknet-jvm doesn't work on Amazon Linux 2 ARM

    starknet-jvm doesn't work on Amazon Linux 2 ARM

    Versions of GLIBCXX supported by Amazon Linux 2: image

    Our native component uses symbol

    0000000000000000      DF *UND*	0000000000000000 (GLIBCXX_3.4.26) _ZNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEC1Ev
    

    which requires version 3.4.26, two minor versions above supported by AL2. We have to use older libstdc++ version during build to support Amazon Linux 2. Using GCC 7 should fix the issue.

    enhancement 
    opened by Solpatium 2
  • Consider exposing more details as public

    Consider exposing more details as public

    I did a quick check through the SDK and I think those functions / classes could be public instead of internal:

    • HttpRequest` & HttpResponseDeserializer
    • Request, Felt`, Json extensions
    • Transaction#toPayload
    • GatewayProvider` - all constructor params could be public, it's useful if u want to make the request on your own
    enhancement question 
    opened by Solpatium 2
  • Network errors when trying to estimate fees

    Network errors when trying to estimate fees

    Summary

    When trying to estimate fees I have come across a few issues with incorrect request

    Incorrect parameter blockTag

    InvokeStandardAccount#estimateFee Error returned: {"code": "StarkErrorCode.MALFORMED_REQUEST", "message": "Query fields should be a subset of {'blockHash', 'blockNumber'}; got: {'blockTag'}."} RCA: blockNumber should be used instead of blockTag

    Missing type

    Invoke:GatewayProvider#getEstimateFee(request: InvokeTransaction, blockNumber: Int) Error returned: {"code": "StarkErrorCode.MALFORMED_REQUEST", "message": "Transaction of version 1 is expected to contain the `type` field."} RCA: missing type in the request body

    bug 
    opened by kamilargent 2
  • Extend javademo

    Extend javademo

    Describe your changes

    This PR extends the javademo adding some more "real life like" usages of the starknet-jvm library.

    Linked issues

    Closes #117

    Breaking changes

    • [ ] This issue contains breaking changes
    opened by cptartur 2
  • Add starknet-jvm to lists of Starknet tools

    Add starknet-jvm to lists of Starknet tools

    We need to add PRs to:

    • https://github.com/gakonst/awesome-starknet
    • https://github.com/beautyisourbusiness/cairo-goldmine
    • https://www.starknet-ecosystem.com/

    There might be more lists like that.

    opened by Solpatium 2
  • Add `@Throws(...)` annotation to all interfaces

    Add `@Throws(...)` annotation to all interfaces

    Feature Request

    Everywhere we define our custom exceptions, we should add @Throw(MyException) annotation so they are translated to checked exceptions in java. Currently, it's not possible to try catch our custom exceptions from java.

    enhancement 
    opened by cptartur 1
  • Refactor transaction serialization in gateway

    Refactor transaction serialization in gateway

    Feature Request

    https://github.com/software-mansion/starknet-jvm/pull/212#discussion_r1054198311

    The input is being encoded, decoded and then encoded egain to achieve two serialization techniques (transform -> polymorphic). We should try and do it somehow better if possible.

    enhancement 
    opened by THenry14 0
  • Unify get transaction receipt behavior across providers

    Unify get transaction receipt behavior across providers

    Describe your changes

    RPC provider raises an exception when querying for transactions that was never received. Gateway provider however returns an empty GatewayTransactionReceipt with status NOT_RECEIVED.

    This PR changes GatewayProvider#getTransactionReceipt so it throws an RequestFailedException on unknown transactions.

    This PR simplifies transaction status mapping test.

    Linked issues

    Closes #211

    Breaking changes

    • [x] This issue contains breaking changes
    • GatewayProvider#getTransactionReceipt throws an exception on unknown transaction
    • Changed TransactionStatus serialization logic
    opened by cptartur 1
  • Update docs and GatewayProvider factories

    Update docs and GatewayProvider factories

    Describe your changes

    This PR extends the documentation.

    It also renames GatewayProvider.Factory methods to make_Provider from make_Client.

    Linked issues

    Closes #98

    Breaking changes

    • [x] This issue contains breaking changes
    • Renamed GatewayProvider.Factory methods to make_Provider from make_Client.
    opened by cptartur 1
  • Support RPC 0.2.1 + drop deploy transaction

    Support RPC 0.2.1 + drop deploy transaction

    Describe your changes

    This PR introduces support for RPC 0.2.1 spec and drops support for deploy transaction (gateway + rpc).

    Linked issues

    Closes https://github.com/software-mansion/starknet-jvm/issues/146 Closes https://github.com/software-mansion/starknet-jvm/issues/148 Closes https://github.com/software-mansion/starknet-jvm/issues/190 Closes https://github.com/software-mansion/starknet-jvm/issues/184 Closes https://github.com/software-mansion/starknet-jvm/issues/202

    Breaking changes

    • [X] This issue contains breaking changes

    • RPC 0.1.0 support is dropped

    • provider.deployContract is dropped

    opened by THenry14 1
  • Unify the RPC and Gateway provider getTransactionReceipt behavior

    Unify the RPC and Gateway provider getTransactionReceipt behavior

    RPC provider throws and error when trying to access receipt of transaction with unknown class hash.

    Gateway returns

    {
        "status": "NOT_RECEIVED"
    }
    

    instead. That works with our current data class and doesn't raise an error. Perhaps this should be unified.

    Originally posted by @Solpatium in https://github.com/software-mansion/starknet-jvm/pull/210#discussion_r1045554556

    opened by cptartur 2
Releases(0.3.4)
Owner
Software Mansion
Software Mansion
A simple, lightweight, non-bloated redis client for kotlin and other JVM languages

rekt is a lightweight, non-bloated redis client, primarily written for the kotlin programming language, while also supporting other JVM-based languages, such as Java, Scala, and obviously way more.

Patrick 8 Nov 2, 2022
Utility library dedicated for functional & non-functional codebases to simplify modelling of success and failure responses for the JVM languages 🔀

Expressible Utility library, part of the panda-lang SDK, dedicated for functional codebases that require enhanced response handling. Express yourself

Panda 28 Nov 14, 2022
Scala 3 Standard Library with bracket syntax.

Scala 3 Library with braces Scala adds a terrible new feature, optional braces, which allow use indentation instead of braces. The new syntax is widel

Glavo 10 Dec 30, 2021
A multiversion gradle scala plugin

WIP Work in Progress: Learning how to write a gradle plugin. A Scala multiversion plugin Inspired by: https://github.com/ADTRAN/gradle-scala-multivers

Ross Lawley 1 Dec 8, 2021
Kotlin SDK for Jellyfin supporting Android and the JVM.

Jellyfin Kotlin SDK Part of the Jellyfin Project The Jellyfin Kotlin SDK is a library implementing the Jellyfin API to easily access servers. It is cu

Jellyfin 60 Dec 18, 2022
Archimedes's implementation for the Java Virtual Machine (JVM)

Archimedes Give me a place to stand, and I shall move the earth. Archimedes's implementation for the Java Virtual Machine (JVM) Building From Source T

Archimedes 24 Aug 20, 2022
Create libraries for all types of Kotlin projects: android, JVM, Multiplatform, Gradle plugins, and so on.

JavierSC Kotlin template Create libraries for all types of Kotlin projects: android, JVM, Multiplatform, Gradle plugins, and so on. Features Easy to p

Javier Segovia Córdoba 2 Dec 14, 2022
An implementation of MediatR on JVM for Spring using Kotlin coroutines

Kpring MediatR In this project, an attempt has been made to implement the mediator pattern on the JVM with simplicity using Kotlin with native corouti

Mahdi Bohloul 4 Aug 6, 2022
Kotlin jvm + android packages for bdk-ffi

bdk-kotlin This project builds .jar and .aar packages for the jvm and android platforms that provide Kotlin language bindings for the bdk library. The

Bitcoin Dev Kit 14 Nov 15, 2022
Asynchronous Spring Initializr API wrapper for Kotlin/JVM

initializr-kt Asynchronous Spring Initializr API wrapper for Kotlin/JVM. This library provides the simplest DSL for initializing Spring Boot projects

Mikhail Titov 2 May 8, 2022
Depenject - a lightweight, minimalistic dependency injection library for Kotlin/JVM.

depenject depenject is a lightweight, minimalistic dependency injection library for Kotlin/JVM. Our goal is similar to flavor's to simplify the usage

Patrick 1 Mar 22, 2022
JVM Open Asset Import Library (Assimp)

assimp JVM porting of Assimp This port is being written trying to stick as much as possible close to the C version in order to: minimize maintenance t

null 83 Oct 30, 2022
Collection of JVM library logic that the Sirloin software development team is currently using

Collection of JVM library logic that the Sirloin software development team is currently using

Sirloin Dev 4 May 10, 2022
This is the interpreter of Hime language, a dialect of Lisp, run on JVM platform.

Hime Language About This is the interpreter of Hime language, a dialect of Lisp, running on JVM platform. Once a feature is finished and tested, and n

Hime Programming Language 8 Jul 12, 2022
A Kotlin-first SDK for Firebase

Firebase Kotlin SDK Built and maintained with ?? by GitLive Real-time code collaboration inside any IDE The Firebase Kotlin SDK is a Kotlin-first SDK

GitLive 522 Jan 3, 2023
Sample app to demonstrate the integration code and working of Dyte SDK for android, using Kotlin.

Dyte Kotlin Sample App An example app in kotlin using the Dyte Mobile SDK Explore the docs » View Demo · Report Bug · Request Feature Table of Content

Dyte 8 Dec 3, 2021
Application includes Admob SDK, In-App Messaging, Crashlytics, Lottie, Flurry

AdvertisementApplication This application includes Admob SDK, In-App Messaging, Crashlytics, Lottie, Flurry. * Admob: AdMob helps you monetize your mo

Alparslan Köprülü 2 Nov 8, 2021
HQ OpenAPI Specification and Client & Server SDK Generators

HQ-API HQ OpenAPI Specification and Client & Server SDK Generators Cloning Github Repository Get access to Flocktory team in Github Adding a new SSH k

Flocktory Spain, S.L. 1 Sep 2, 2022
Android SDK development environment Docker image

AndroidSDK Android SDK development environment Docker image Goals It contains the complete Android SDK enviroment, is able to perform all regular Andr

Jing Li 1k Dec 30, 2022