Cardano Client Lib
A Java Library for Simplifying Transactions, Token Minting, Address Derivation, and CIP Implementations for Applications on the Cardano Blockchain!
Easy to Use Java Library
Address generation, transfer, token minting, Plutus contract call and more..
Out-of-box Backend Providers
Blockfrost, Koios, Ogmios
CIP Implementations
Java Api for
CIP-8, CIP-20, CIP-25, CIP-30, CIP-67/68 ...
- Key APIs
- QuickTx
- Composable Functions
Backend Providers
//Blockfrost Backend Service
BackendService backendService =
new BFBackendService(Constants.BLOCKFROST_PREPROD_URL, "<Project_id>")
//Koios Backend Service
BackendService koiosBackendService =
new KoiosBackendService(Constants.KOIOS_PREPROD_URL);
//Ogmios Backend Service
BackendService ogmiosBackendService = new OgmiosBackendService(OGMIOS_URL);
//Kupo Utxo Service
KupoUtxoService kupoUtxoService = new KupoUtxoService(KUPO_URL);
UtxoSupplier utxoSupplier = new DefaultUtxoSupplier(kupoUtxoService);
- Multiple out-of-box backend providers
- Write your own provider using supplier interfaces
Account API
//Mainnet account from mnemonic
Account mainnetAccount = new Account(mnemonic);
//Testnet account from mnemonic
Account testnetAccount = new Account(Networks.testnet(), mnemonic)
//New mainnet account
Account mainnetAccount = new Account()
//New testnet account
Account testnetAccount = new Account(Networks.testnet())
- Create new mainnet / testnet accounts
- Create accounts from mnemonic
- Create accounts from account private key
- Create accounts using derivation path
Simple declarative api to build and submit transactions.
Simple Payment
Tx tx = new Tx()
.payToAddress(receiver1, Amount.ada(1.5))
.payToAddress(receiver2, Amount.ada(2.5))
.from(sender1Addr);
- Define outputs with Tx api
Compose and Submit
QuickTxBuilder quickTxBuilder = new QuickTxBuilder(backendService);
Result<String> result = quickTxBuilder.compose(tx)
.withSigner(SignerProviders.signerFrom(sender1))
.completeAndWait(System.out::println);
- Compose transactions and provide signer
- Submit transaction to blockchain
Multiple Txs with Multiple Senders
Tx tx1 = new Tx()
.payToAddress(receiver1, Amount.ada(1.5))
.from(sender1Addr);
Tx tx2 = new Tx()
.payToAddress(receiver1, Amount.ada(1.5))
.from(sender2Addr);
Result<String> result = quickTxBuilder.compose(tx1, tx2)
.feePayer(sender1Addr)
.withSigner(SignerProviders.signerFrom(sender1))
.withSigner(SignerProviders.signerFrom(sender2))
.completeAndWait(System.out::println);
- Define Txs
- Compose and build transaction and provide signers
- Submit transaction to blockchain
Simple Token Minting with Metadata
//Create a policy
Policy policy
= PolicyUtil.createMultiSigScriptAtLeastPolicy("test_policy", 1, 1);
String assetName = "MyAsset";
BigInteger qty = BigInteger.valueOf(1000);
//Define mint Tx
Tx tx = new Tx()
.mintAssets(policy.getPolicyScript(),
new Asset(assetName, qty), receiver)
.attachMetadata(MessageMetadata.create().add("Sample Metadata"))
.from(sender1Addr);
//Compose and sign Tx
Result<String> result = quickTxBuilder.compose(tx)
.withSigner(SignerProviders.signerFrom(sender1))
.withSigner(SignerProviders.signerFrom(policy))
.complete();
- Create a policy
- Define minting transaction
- Provide signers for the account and policy
- Compose and submit transaction
Select a different UTxO Selection Strategy
UtxoSelectionStrategy randomSelectionStg =
new RandomImproveUtxoSelectionStrategy(
new DefaultUtxoSupplier(backendService.getUtxoService()))
Result<String> result = quickTxBuilder.compose(tx)
.withSigner(SignerProviders.signerFrom(sender1))
.withUtxoSelectionStrategy(randomSelectionStg)
.complete();
- Use an out-of-box UTxO selection strategy
- Create your own custom UTxO selection strategy by implementing the UtxoSelectionStrategy interface
Pay to a Contract Address
Tx tx = new Tx()
.payToContract(scriptAddr, amount, plutusData)
.from(sender2Addr);
- Use Tx api to pay to a contract address
Unlock Amount at a Contract Address
ScriptTx scriptTx = new ScriptTx()
.collectFrom(utxo, redeemer)
.payToAddress(receiver1, amount)
.attachSpendingValidator(plutusScript);
Result<String> result = quickTxBuilder.compose(scriptTx)
.feePayer(sender1Addr)
.withSigner(SignerProviders.signerFrom(sender1))
.completeAndWait(System.out::println);
- Use ScriptTx api to define a script unlock tx
- Attach validator script to the transaction
- Compose and submit transaction
A flexible way to build transactions using out-of-box composable functions and with your own custom functions.
Simple Payments
Output output = Output.builder()
.address(receiverAddress)
.assetName(LOVELACE)
.qty(adaToLovelace(2.1))
.build();
Output output2 = Output.builder()
.address(receiverAddress2)
.assetName(LOVELACE)
.qty(adaToLovelace(5))
.build();
TxBuilder txBuilder = output.outputBuilder()
.and(output2.outputBuilder())
.buildInputs(InputBuilders.createFromSender(senderAddress, senderAddress))
.andThen(BalanceTxBuilders.balanceTx(senderAddress, 1));
Transaction signedTransaction = TxBuilderContext.init(utxoSupplier, protocolParamsSupplier)
.buildAndSign(txBuilder, SignerProviders.signerFrom(sender));
- Define outputs
- Compose outputs using TxBuilder and out-of-box Composable Functions
- Initialize TxBuilderContext with UtxoSupplier and ProtocolParamsSupplier
- Build and Sign transaction
Submit Transaction
Result<String> result = transactionService.submitTransaction(signedTransaction.serialize());
- Get TransactionService from BackendService or create your own TransactionProcessor
- Submit transaction to blockchain
Mint Tokens
Policy policy = PolicyUtil.createMultiSigScriptAllPolicy("policy-1", 1);
Asset asset = new Asset("TestCoin", BigInteger.valueOf(50000));
MultiAsset multiAsset = MultiAsset.builder()
.policyId(policy.getPolicyId())
.assets(List.of(asset))
.build();
Output output = Output.builder()
.address(receiverAddress)
.policyId(policy.getPolicyId())
.assetName(asset.getName())
.qty(BigInteger.valueOf(50000))
.build();
Metadata metadata = MessageMetadata.create()
.add("Mint Test Coin");
TxBuilder txBuilder = output.mintOutputBuilder()
.buildInputs(InputBuilders.createFromSender(senderAddress, senderAddress))
.andThen(MintCreators.mintCreator(policy.getPolicyScript(), multiAsset))
.andThen(AuxDataProviders.metadataProvider(metadata))
.andThen(BalanceTxBuilders.balanceTx(senderAddress, 2));
Transaction signedTransaction = TxBuilderContext.init(utxoSupplier, protocolParamsSupplier)
.buildAndSign(txBuilder, signerFrom(sender).andThen(signerFrom(policy)));
- Create a policy
- Define multi-asset
- Define output with multi-asset
- Create metadata
- Compose transaction using TxBuilder and out-of-box Composable Functions
- Balance transaction with balanceTx composable function
- Build and sign transaction with sender account and policy key