This package contains runnable code examples that use the Flow JVM SDK to interact with the Flow blockchain in Kotlin. The examples use the Flow Emulator to simulate a live network connection.
The emulator is bundled with the Flow CLI, a command-line interface for working with Flow.
This repository is configured to run with Cadence 1.0. Follow these steps to install the Cadence 1.0 CLI.
Each code example has a corresponding test file located in /kotlin-example/src/test
. Each test file provides a series of runnable functions which boot up the emulator and invoke the corresponding code example. We recommend using IntelliJ IDEA (see the free Community Edition here) to interact with and run the tests. However, you can also trigger an individual test run with ./gradlew :kotlin-example:test --tests "com.example.MyTestClass.myTestMethod"
.
Below is a list of all Kotlin code examples currently supported in this repo:
Get blocks by ID, height, or latest sealed.
- Get the latest sealed block
- Get block by ID
- Get block by height
- Get account balance
- Get account from the latest block
- Get account from block by height
- Get account key at latest block
- Get account keys at latest block
- Get account key at block height
- Get account keys at block height
Get events emitted by transactions.
- Get events for height range
- Get events for block IDs
- Get events directly from transaction result
- Get collection by id
- Get full collection by id (returns all transactions in collection response)
Get execution data by block ID.
Get the current network parameters.
- Get transaction
- Get system transaction
- Get transaction result
- Get system transaction result
- Get transaction result by index
- Send transaction
- Send transaction with arguments
- Execute a simple Cadence script
- Execute a more complex Cadence script with arguments
Add a key to an existing account.
Deploy a Cadence smart contract.
Common paradigms for signing transactions.
- Single party, single signature
- Single party, multiple signatures
- Multiple parties
- Multiple parties, 2 authorizers
- Multiple parties, multiple signatures
Common paradigms for signing messages.
- Signing an arbitrary message.
- Signing an arbitrary user message and verifying it using the public keys on an account, respecting the weights of each key.
- Signing an arbitrary user message and verifying it using the public keys on an account. Return success if any public key on the account can sign the message.
Utilizing the Access API subscription endpoints to stream event and execution data.
- Streaming events.
- Streaming events and reconnecting in the event of a failure.
- Streaming execution data.