{"id":13669728,"url":"https://github.com/onflow/flow-jvm-sdk","last_synced_at":"2025-09-11T23:37:36.704Z","repository":{"id":38228105,"uuid":"395369023","full_name":"onflow/flow-jvm-sdk","owner":"onflow","description":"Flow JVM SDK","archived":false,"fork":false,"pushed_at":"2024-11-26T11:37:22.000Z","size":1893,"stargazers_count":18,"open_issues_count":4,"forks_count":16,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-05-06T15:48:31.777Z","etag":null,"topics":["blockchain","cadence-lang","flow","java","kotlin"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"the-nft-company/flow-jvm-sdk","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onflow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-08-12T15:45:40.000Z","updated_at":"2024-12-24T06:56:40.000Z","dependencies_parsed_at":"2025-05-06T15:46:49.061Z","dependency_job_id":"11f6e408-d120-46ac-804e-3a45390f06db","html_url":"https://github.com/onflow/flow-jvm-sdk","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/onflow/flow-jvm-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onflow%2Fflow-jvm-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onflow%2Fflow-jvm-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onflow%2Fflow-jvm-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onflow%2Fflow-jvm-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onflow","download_url":"https://codeload.github.com/onflow/flow-jvm-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onflow%2Fflow-jvm-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274726844,"owners_count":25338396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","cadence-lang","flow","java","kotlin"],"created_at":"2024-08-02T09:00:20.767Z","updated_at":"2025-09-11T23:37:36.626Z","avatar_url":"https://github.com/onflow.png","language":"Kotlin","funding_links":[],"categories":["Flow区块链"],"sub_categories":["开发工具"],"readme":"# Flow JVM SDK\n\n[![Maven Central](https://img.shields.io/maven-central/v/org.onflow/flow-jvm-sdk)](https://search.maven.org/search?q=g:org.onflow%20AND%20a:flow-jvm-sdk) \n[![Sonatype OSS](https://img.shields.io/nexus/s/org.onflow/flow-jvm-sdk?label=snapshot\u0026server=https%3A%2F%2Fs01.oss.sonatype.org%2F)](https://s01.oss.sonatype.org/content/repositories/snapshots/org/onflow/flow-jvm-sdk/)\n\nThe Flow JVM SDK is a library for JVM languages (e.g. Java, Kotlin, Scala, Groovy) that provides utilities to interact with the Flow blockchain.\n\nFor a summary of the breaking changes introduced in the latest release, please refer to [BREAKING_CHANGES.md](./BREAKING_CHANGES.md).\n\nAt the moment, this SDK includes the following features:\n- [x] Communication with the [Flow Access API](https://docs.onflow.org/access-api) over gRPC \n- [x] Transaction preparation and signing\n- [x] Cryptographic key generation, parsing, and signing\n- [x] Marshalling \u0026 unmarshalling of [JSON-Cadence](https://docs.onflow.org/cadence/json-cadence-spec/)\n- [x] DSL for creating, signing, and sending transactions and scripts\n\n## Table of Contents\n- [Repository structure](#repository-structure)\n  - [SDK](#sdk)\n  - [Java Examples](#java-examples)\n  - [Kotlin Examples](#kotlin-examples)\n  - [Common Utils](#common-utils)\n- [Contribute to this SDK](#contribute-to-this-sdk)\n- [Dependencies](#dependencies)\n- [Getting Started](#getting-started)\n  - [Installation](#installation)\n  - [Generating Keys](#generating-keys)\n  - [Supported Curves](#supported-curves)\n  - [Accessing the Flow Network](#accessing-the-flow-network)\n  - [Creating an Account](#creating-an-account)\n  - [Signing Transactions](#signing-transactions)\n  - [Sending Transactions](#sending-transactions)\n  - [Querying Transaction Results](#querying-transaction-results)\n  - [Querying Blocks](#querying-blocks)\n  - [Executing a Script](#executing-a-script)\n  - [Querying Events](#querying-events)\n  - [Querying Accounts](#querying-accounts)\n  - [Examples Summary](#examples-summary)\n- [Credit](#credit)\n\n## Repository structure\n\nThis repository is organized as a multi-module project, consisting of the following modules:\n\n### SDK\nThe core module that includes all the necessary tools and libraries to interact with the Flow blockchain. This module provides the main functionalities such as transaction preparation, signing, and interaction with the Flow Access API. \nIt also implements and tests use of the SDK via Java Annotations or Kotlin Extensions which can optionally be used when integrating.\n\n### Java Examples\nThis module contains example implementations demonstrating how to use the Flow JVM SDK in a Java application. It includes sample code for various use cases, making it easier for developers to understand and integrate the SDK into their Java projects.\n\n### Kotlin Examples\nSimilar to the Java Example module, this module provides sample implementations in Kotlin. It showcases how to leverage the SDK's capabilities in a Kotlin environment.\n\n### Common Utils\nThe common utils module contains resources shared across all 3 above sub-modules, such as Cadence scripts and testing infrastructure.\n\n## Contribute to this SDK\n\nWe welcome all community contributions and will gladly review improvements and other proposals as PRs.\n\nRead the [contributing guide](./CONTRIBUTING.md) to get started.\n\n## Dependencies\n\nThis SDK requires Java Developer Kit (JDK) 8 or newer.\n\n## Getting Started\n\n### Installation\n\nTo add the SDK to your project, check out [this README](/sdk/README.md/#installation) for sample Maven and Gradle setup configurations.\n\n### Generating Keys\n\nFlow uses [ECDSA](https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm)\nto control access to user accounts. Each key pair can be used in combination with\nthe SHA2-256 or SHA3-256 hashing algorithms.\n\nHere's how to generate an ECDSA key pair for the P-256 (secp256r1) curve:\n\n```kotlin\nval keyPair = Crypto.generateKeyPair(SignatureAlgorithm.ECDSA_P256)\n\nval privateKey = keyPair.private\nval publicKey = keyPair.public\n```\nOne can then retrieve the hexadecimal representation of the key or encode it as bytes:\n\n```kotlin\nval privateKeyHex = privateKey.hex\nval privateKeyBytes = privateKey.hex.toByteArray()\n```\n\n#### Supported Curves\n\nThe example above uses an ECDSA key pair on the P-256 (secp256r1) elliptic curve.\nFlow also supports the secp256k1 curve used by Bitcoin and Ethereum.\n\nHere's how to generate an ECDSA private key for the secp256k1 curve:\n\n```kotlin\nval keyPair = Crypto.generateKeyPair(SignatureAlgorithm.ECDSA_SECP256k1)\n```\n\nHere's a full list of the supported signature and hash algorithms on Flow: [Flow Signature \u0026 Hash Algorithms](https://cadence-lang.org/docs/language/crypto#hashing).\n\n### Accessing the Flow Network\n\nYou can communicate with any Flow Access Node using the Flow JVM SDK. This includes official Access Nodes, nodes you run yourself, and hosted nodes. Flow JVM SDK currently only supports gRPC communication with Access Nodes.\n\nHere's how to create a new gRPC client for any network:\n\n```kotlin\nprivate const val MAINNET_HOSTNAME = \"access.mainnet.nodes.onflow.org\"\nprivate const val TESTNET_HOSTNAME = \"access.devnet.nodes.onflow.org\"\n\nfun newAccessApiConnnection(): FlowAccessApi = Flow.newAccessApi(MAINNET_HOSTNAME)\n\nval accessAPIConnection = newAccessApiConnnection()\n```\n\n### Creating an Account\n\nOnce you have [generated a key pair](#generating-keys), you can create a new account\nusing its public key. Check out the **Create Account** example for a runnable code snippet in [Java](java-example/src/main/java/org/onflow/examples/java/createAccount/CreateAccountExample.java) or [Kotlin](kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/createAccount/CreateAccountExample.kt).\n\n### Signing Transactions\n\nTransaction signing is accomplished through the `Crypto.Signer` interface. Below is a simple example of how to sign a transaction using a `PrivateKey` generated with `Crypto.generateKeyPair()`.\n\n```kotlin\n\nval latestBlockId\nval payerAddress\nval payerAccountKey\n\nvar tx = FlowTransaction(\n  script = FlowScript(ExamplesUtils.loadScript(scriptName)),\n  arguments = listOf(),\n  referenceBlockId = latestBlockID,\n  gasLimit = gasLimit,\n  proposalKey = FlowTransactionProposalKey(\n    address = payerAddress,\n    keyIndex = payerAccountKey.id,\n    sequenceNumber = payerAccountKey.sequenceNumber.toLong()\n  ),\n  payerAddress = payerAddress,\n  authorizers = listOf(payerAddress)\n)\n\nval signer = Crypto.getSigner(privateKey, payerAccountKey.hashAlgo)\ntx = tx.addEnvelopeSignature(payerAddress, payerAccountKey.id, signer)\n```\n\nCheck out the **Transaction Signing** example for runnable code snippets in [Java](java-example/src/main/java/org/onflow/examples/java/signTransaction/SignTransactionExample.java) or [Kotlin](kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/signTransaction/SignTransactionExample.kt).\n\nThe Transaction Signing example introduces multiple transaction signing paradigms, including:\n- Single party, single signature\n- Single party, multiple signatures\n- Multiple parties\n- Multiple parties, 2 authorizers\n- Multiple parties, multiple signatures\n\nBefore trying these examples, we recommend that you read through the [transaction signature documentation](https://developers.flow.com/build/basics/transactions#signing-a-transaction).\n\n### Sending Transactions\n\nYou can submit a transaction to the Flow network using the Access API client.\n\nSee the **Send Transaction** example for runnable code snippets in [Java](java-example/src/main/java/org/onflow/examples/java/sendTransaction/SendTransactionExample.java) or [Kotlin](kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/sendTransaction/SendTransactionExample.kt); we include both a simple transaction and a more complex transaction with passed arguments.\n\n### Querying Transaction Results\n\nAfter you have submitted a transaction, you can query its status by ID:\n\n```kotlin\nfun getTransactionResult(txID: FlowId): FlowTransactionResult = when (val response = accessAPI.getTransactionResultById(txID)) {\n        is FlowAccessApi.AccessApiCallResponse.Success -\u003e {\n            if (response.data.errorMessage.isNotEmpty()) {\n                throw Exception(response.data.errorMessage)\n            }\n            response.data\n        }\n        is FlowAccessApi.AccessApiCallResponse.Error -\u003e throw Exception(response.message, response.throwable)\n    }\n```\n\nThe result includes a `status` field that will be one of the following values:\n\n- `UNKNOWN` - The transaction has not yet been seen by the network.\n- `PENDING` - The transaction has not yet been included in a block.\n- `FINALIZED` - The transaction has been included in a block.\n- `EXECUTED` - The transaction has been executed but the result has not yet been sealed.\n- `SEALED` - The transaction has been executed and the result is sealed in a block.\n\n```kotlin\nval txResult = getTransactionResult(txID)\nif (txResult.status == FlowTransactionStatus.SEALED) {\n  println(\"Transaction Sealed\")\n}\n```\n\nIn the event of a failure, the `FlowAccessApi.AccessApiCallResponse` class returns an `Error` object which contains the corresponding error `message` and throwable `Exception`.\n\nSee the **Get Transaction** example for runnable code snippets in [Java](java-example/src/main/java/org/onflow/examples/java/getTransaction/GetTransactionAccessAPIConnector.java) or [Kotlin](kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getTransaction/GetTransactionAccessAPIConnector.kt).\n\n### Querying Blocks\n\nThe Access API exposes `getLatestBlock`, `getBlockById`, and `getBlockByHeight` methods for querying blocks on-chain. See the **Get Blocks** example for runnable code snippets in [Java](java-example/src/main/java/org/onflow/examples/java/getBlock/GetBlockAccessAPIConnector.java) or [Kotlin](kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getBlock/GetBlockAccessAPIConnector.kt).\n\nA block contains the following fields:\n\n`id` - The ID (hash) of the block.\n`parentId` - The ID of the previous block in the chain.\n`height` - The height of the block in the chain.\n`collectionGuarantees` - The list of collections included in the block.\n\n### Executing a Script\n\nYou can use the `simpleFlowScript` method to execute a Cadence script against the latest sealed execution state.\n\nThis is an example of a valid script:\n```cadence\naccess(all) fun main(a: Int): Int {\n    return a + 10\n}\n```\n```kotlin\n\nfun executeSimpleScript(): FlowScriptResponse {\n        val loadedScript = ExamplesUtils.loadScriptContent(\"cadence/execute_simple_script_example.cdc\")\n\n        return accessAPI.simpleFlowScript {\n            script { loadedScript }\n            arg { JsonCadenceBuilder().int(5) }\n        }.let { response -\u003e\n            when (response) {\n                is FlowAccessApi.AccessApiCallResponse.Success -\u003e response.data\n                is FlowAccessApi.AccessApiCallResponse.Error -\u003e throw Exception(response.message, response.throwable)\n            }\n        }\n    }\n```\n\nSee the **Execute Script** example for runnable code snippets in [Java](java-example/src/main/java/org/onflow/examples/java/executeScript/ExecuteScriptAccessAPIConnector.java) or [Kotlin](kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/executeScript/ExecuteScriptAccessAPIConnector.kt).\n\n### Querying Events\n\nThe Access API exposes `getEventsForHeightRange`, `getEventsForBlockIds`, and `getTransactionResultById` methods for querying events on-chain. See the **Get Events** example for runnable code snippets in [Java](java-example/src/main/java/org/onflow/examples/java/getEvent/GetEventAccessAPIConnector.java) or [Kotlin](kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getEvent/GetEventAccessAPIConnector.kt).\n\n### Querying Accounts\n\nThe Access API exposes `getAccountAtLatestBlock` and `getAccountByBlockHeight`methods for querying accounts on-chain. See the **Get Accounts** example for runnable code snippets in [Java](java-example/src/main/java/org/onflow/examples/java/getAccount/GetAccountAccessAPIConnector.java) or [Kotlin](kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getAccount/GetAccountAccessAPIConnector.kt).\n\nA `FlowAccount` contains the following fields:\n\n`address`: `FlowAddress` - The account address.\n`balance`: `BigDecimal` - The account balance.\n`contracts`: `Map\u003cString, FlowCode\u003e` - The contracts deployed at this account.\n`keys`: `List\u003cFlowAccountKey\u003e` - A list of the public keys associated with this account.\n\n### Examples Summary\n\nFor a complete list of supported examples use-cases, see the [Examples Summary](kotlin-example/README.md/#examples-summary).\n\n## Credit\n\nThe Flow JVM SDK maintainers have included\n* [The NFT Company](https://nftco.com)\n   * [@briandilley](https://github.com/briandilley)  \n   * [@jereanon](https://github.com/jereanon) \n* [Purple Dash](https://purpledash.dev)\n   * [@lealobanov](https://github.com/lealobanov)\n \n     \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonflow%2Fflow-jvm-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonflow%2Fflow-jvm-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonflow%2Fflow-jvm-sdk/lists"}