Kotlin SDK for Blockfrost.io API
Currently, Kotlin SDK is distributed via JitPack:
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency to your module build.gradle
dependencies {
implementation 'com.github.blockfrost:blockfrost-kotlin:0.0.4'
}
For usage with Maven and other tools, check out the JitPack page.
Check out build.gradle of an Example application using Kotlin SDK library.
API is asynchronous, coroutine based.
import io.blockfrost.sdk_kotlin.api.CardanoAddressesApi
import io.blockfrost.sdk_kotlin.infrastructure.BlockfrostConfig
// Use default configuration, mainnet, project_id loaded from BF_PROJECT_ID env var
val api = CardanoAddressesApi(config = BlockfrostConfig.defaulMainNetConfig)
// coroutine call, returns model object
val details = api.getAddressDetails("addr1q8zu4smzyf2r2mfqjd6tc6vxf2p8rccdfk82ye3eut2udkw9etpkygj5x4kjpym5h35cvj5zw83s6nvw5fnrnck4cmvshkfm4y")
Default configuration for IPFS, project ID is loaded from env var BF_IPFS_PROJECT_ID
val apiIpfsAdd = IPFSAddAPI(config = BlockfrostConfig.defaultIpfsConfig)
You can also define API-specific configuration
val config = BlockfrostConfig(
baseUrl = BlockfrostConfig.UrlIpfs,
projectId = BlockfrostConfig.getEnvProjectIdIpfs(),
socketTimeoutMilli = 90_000,
)
val apiIpfsAdd = IPFSAddAPI(config = config)
Check out Example application or integration tests for more usage examples.
Methods with paging parameters (count, page, order) have paging methods enabling to load all results, iterating over all pages in the background. For example
val api = CardanoAddressesApi(config = BlockfrostConfig.defaulMainNetConfig)
val flow: Flow<AddressTransactionsContent> = api.getAddressTransactionsAll(address = "addr1q8zu4smzyf2r2mfqjd6tc6vxf2p8rccdfk82ye3eut2udkw9etpkygj5x4kjpym5h35cvj5zw83s6nvw5fnrnck4cmvshkfm4y")
flow.collect {
println("Transaction: $it")
}
OperationAll methods return a Flow object enabling processing of individual results as they are produced by the loading method. I.e., once first page is loaded with results, consumer can immediately start processing the results form the flow without need to wait for downloading all pages. It is also possible to stop page download on a consumer side.
Alternative to fetch All methods are fetch AllList methods. E.g.,
val api = CardanoAddressesApi(config = BlockfrostConfig.defaulMainNetConfig)
val res: List<AddressTransactionsContent> = api.getAddressTransactionsAllList(address = "addr1q8zu4smzyf2r2mfqjd6tc6vxf2p8rccdfk82ye3eut2udkw9etpkygj5x4kjpym5h35cvj5zw83s6nvw5fnrnck4cmvshkfm4y")
The method returns list once all pages are downloaded.
First, create the gradle wrapper script:
gradle wrapper
Then, run:
./gradlew check assemble
This runs all tests and packages the library.
All URIs are relative to https://cardano-mainnet.blockfrost.io/api/v0
Class | Method | HTTP request | Description |
---|---|---|---|
CardanoAccountsApi | getAccountAddresses | GET /accounts/{stake_address}/addresses | Account associated addresses |
CardanoAccountsApi | getAccountAssets | GET /accounts/{stake_address}/addresses/assets | Assets associated with the account addresses |
CardanoAccountsApi | getAccountByStakeAddress | GET /accounts/{stake_address} | Specific account address |
CardanoAccountsApi | getAccountDelegationHistory | GET /accounts/{stake_address}/delegations | Account delegation history |
CardanoAccountsApi | getAccountHistory | GET /accounts/{stake_address}/history | Account history |
CardanoAccountsApi | getAccountMirHistory | GET /accounts/{stake_address}/mirs | Account MIR history |
CardanoAccountsApi | getAccountRegistrationHistory | GET /accounts/{stake_address}/registrations | Account registration history |
CardanoAccountsApi | getAccountRewardHistory | GET /accounts/{stake_address}/rewards | Account reward history |
CardanoAccountsApi | getAccountWithdrawalHistory | GET /accounts/{stake_address}/withdrawals | Account withdrawal history |
CardanoAddressesApi | getAddress | GET /addresses/{address} | Specific address |
CardanoAddressesApi | getAddressDetails | GET /addresses/{address}/total | Address details |
CardanoAddressesApi | getAddressTransactions | GET /addresses/{address}/transactions | Address transactions |
CardanoAddressesApi | getAddressTxs | GET /addresses/{address}/txs | Address transactions |
CardanoAddressesApi | getAddressUtxos | GET /addresses/{address}/utxos | Address UTXOs |
CardanoAssetsApi | getAsset | GET /assets/{asset} | Specific asset |
CardanoAssetsApi | getAssetAddresses | GET /assets/{asset}/addresses | Asset addresses |
CardanoAssetsApi | getAssetHistory | GET /assets/{asset}/history | Asset history |
CardanoAssetsApi | getAssetTransactions | GET /assets/{asset}/transactions | Asset transactions |
CardanoAssetsApi | getAssetTxs | GET /assets/{asset}/txs | Asset transactions |
CardanoAssetsApi | getAssets | GET /assets | Assets |
CardanoAssetsApi | getPolicyAssets | GET /assets/policy/{policy_id} | Assets of a specific policy |
CardanoBlocksApi | getBlock | GET /blocks/{hash_or_number} | Specific block |
CardanoBlocksApi | getBlockInEpochInSlot | GET /blocks/epoch/{epoch_number}/slot/{slot_number} | Specific block in a slot in an epoch |
CardanoBlocksApi | getBlockInSlot | GET /blocks/slot/{slot_number} | Specific block in a slot |
CardanoBlocksApi | getBlockTransactions | GET /blocks/{hash_or_number}/txs | Block transactions |
CardanoBlocksApi | getLatestBlock | GET /blocks/latest | Latest block |
CardanoBlocksApi | getNextBlocks | GET /blocks/{hash_or_number}/next | Listing of next blocks |
CardanoBlocksApi | getPreviousBlocks | GET /blocks/{hash_or_number}/previous | Listing of previous blocks |
CardanoBlocksApi | getTransactionsInLatestBlock | GET /blocks/latest/txs | Latest block transactions |
CardanoEpochsApi | getActiveStakesForEpoch | GET /epochs/{number}/stakes | Stake distribution |
CardanoEpochsApi | getActiveStakesForEpochAndPool | GET /epochs/{number}/stakes/{pool_id} | Stake distribution by pool |
CardanoEpochsApi | getBlocksForEpoch | GET /epochs/{number}/blocks | Block distribution |
CardanoEpochsApi | getBlocksForEpochAndPool | GET /epochs/{number}/blocks/{pool_id} | Block distribution by pool |
CardanoEpochsApi | getEpoch | GET /epochs/{number} | Specific epoch |
CardanoEpochsApi | getEpochParam | GET /epochs/{number}/parameters | Protocol parameters |
CardanoEpochsApi | getLatestEpoch | GET /epochs/latest | Latest epoch |
CardanoEpochsApi | getLatestEpochParam | GET /epochs/latest/parameters | Latest epoch protocol parameters |
CardanoEpochsApi | getNextEpochs | GET /epochs/{number}/next | Listing of next epochs |
CardanoEpochsApi | getPreviousEpochs | GET /epochs/{number}/previous | Listing of previous epochs |
CardanoLedgerApi | getGenesis | GET /genesis | Blockchain genesis |
CardanoMetadataApi | getTransactionMetadataCborForLabel | GET /metadata/txs/labels/{label}/cbor | Transaction metadata content in CBOR |
CardanoMetadataApi | getTransactionMetadataJsonForLabel | GET /metadata/txs/labels/{label} | Transaction metadata content in JSON |
CardanoMetadataApi | getTransactionMetadataLabels | GET /metadata/txs/labels | Transaction metadata labels |
CardanoNetworkApi | getNetwork | GET /network | Network information |
CardanoPoolsApi | getPool | GET /pools/{pool_id} | Specific stake pool |
CardanoPoolsApi | getPoolBlocks | GET /pools/{pool_id}/blocks | Stake pool blocks |
CardanoPoolsApi | getPoolDelegators | GET /pools/{pool_id}/delegators | Stake pool delegators |
CardanoPoolsApi | getPoolHistory | GET /pools/{pool_id}/history | Stake pool history |
CardanoPoolsApi | getPoolMetadata | GET /pools/{pool_id}/metadata | Stake pool metadata |
CardanoPoolsApi | getPoolRelays | GET /pools/{pool_id}/relays | Stake pool relays |
CardanoPoolsApi | getPoolUpdates | GET /pools/{pool_id}/updates | Stake pool updates |
CardanoPoolsApi | getPools | GET /pools | List of stake pools |
CardanoPoolsApi | getRetiredPools | GET /pools/retired | List of retired stake pools |
CardanoPoolsApi | getRetiringPools | GET /pools/retiring | List of retiring stake pools |
CardanoScriptsApi | getScript | GET /scripts/{script_hash} | Specific script |
CardanoScriptsApi | getScriptRedeemers | GET /scripts/{script_hash}/redeemers | Redeemers of a specific script |
CardanoScriptsApi | getScripts | GET /scripts | Scripts |
CardanoTransactionsApi | getTransaction | GET /txs/{hash} | Specific transaction |
CardanoTransactionsApi | getTransactionDelegations | GET /txs/{hash}/delegations | Transaction delegation certificates |
CardanoTransactionsApi | getTransactionMetadata | GET /txs/{hash}/metadata | Transaction metadata |
CardanoTransactionsApi | getTransactionMetadataCbor | GET /txs/{hash}/metadata/cbor | Transaction metadata in CBOR |
CardanoTransactionsApi | getTransactionMirs | GET /txs/{hash}/mirs | Transaction MIRs |
CardanoTransactionsApi | getTransactionPoolRetires | GET /txs/{hash}/pool_retires | Transaction stake pool retirement certificates |
CardanoTransactionsApi | getTransactionPoolUpdates | GET /txs/{hash}/pool_updates | Transaction stake pool registration and update certificates |
CardanoTransactionsApi | getTransactionRedeemers | GET /txs/{hash}/redeemers | Transaction redeemers |
CardanoTransactionsApi | getTransactionStakes | GET /txs/{hash}/stakes | Transaction stake addresses certificates |
CardanoTransactionsApi | getTransactionUtxos | GET /txs/{hash}/utxos | Transaction UTXOs |
CardanoTransactionsApi | getTransactionWithdrawals | GET /txs/{hash}/withdrawals | Transaction withdrawal |
CardanoTransactionsApi | submitTransaction | POST /tx/submit | Submit a transaction |
HealthApi | getApiRoot | GET / | Root endpoint |
HealthApi | getCurrentBackendTime | GET /health/clock | Current backend time |
HealthApi | getHealth | GET /health | Backend health status |
IPFSAddApi | add | POST /ipfs/add | Add a file to IPFS |
IPFSGatewayApi | get | GET /ipfs/gateway/{IPFS_path} | Relay to an IPFS gateway |
IPFSPinsApi | getPinList | GET /ipfs/pin/list/ | List pinned objects |
IPFSPinsApi | getPinListByIpfsPath | GET /ipfs/pin/list/{IPFS_path} | Get details about pinned object |
IPFSPinsApi | pinAdd | POST /ipfs/pin/add/{IPFS_path} | Pin an object |
IPFSPinsApi | removePin | POST /ipfs/pin/remove/{IPFS_path} | |
MetricsApi | getMetrics | GET /metrics/ | Blockfrost usage metrics |
MetricsApi | getMetricsEndpoints | GET /metrics/endpoints | Blockfrost endpoint usage metrics |
NutLinkApi | getAddress | GET /nutlink/{address} | |
NutLinkApi | getAddressTickers | GET /nutlink/{address}/tickers | |
NutLinkApi | getTickerRecordsByAddressAndTicker | GET /nutlink/{address}/tickers/{ticker} | |
NutLinkApi | getTickerRecordsByTicker | GET /nutlink/tickers/{ticker} |