Let’s see how we can use this library to create and post a transfer transaction with Ada.Add cardano-client-lib dependency to your application
If you are using Maven,<dependency> <groupId>com.bloxbean.cardano</groupId> <artifactId>cardano-client-lib</artifactId> <version>0.1.0</version></dependency>
If you are using Gradle,implementation 'com.bloxbean.cardano:cardano-client-lib:0.1.0'
Note: You can check the latest released version in project’s GitHub.
2. Create a new AccountAccount account = new Account(Networks.testnet());String baseAddress = account.baseAddress();
3. Import from Mnemonic Phrase
Provide 24 words mnemonic phrase to derive the base account address.String mnemonic = "behind hope swing table fat joy phone spoil response exercise dose fame mystery day food lens debate slam lawsuit board behind allow excuse extend";Account account = new Account(Networks.testnet(), mnemonic);String baseAddress = account.baseAddress();
4. Get Backend Service
Provide Blockfrost Cardano network and Project Id to get an instance of Blockfrost backend service.
Register at https://blockfrost.io/ to get a free account and a project id for Cardano Testnet.BackendService backendService = BackendFactory.getBlockfrostBackendService( Constants.BLOCKFROST_TESTNET_URL, <project_id>);
5. Get Other services from Backend Service
The followings are the example of few major services you can get from BackendService. You can use these services to interact with Cardano blockchain.
a. Get an instance of TransactionHelperService to build a payment or token mint transaction and submit to the Cardano network.TransactionHelperService txnHelperService = backendService.getTransactionHelperService();
b. Get an instance of FeeCalculationService to calculate the estimated fees of a transaction.FeeCalculation...