Skip to Content
Getting StartedAccount & Backend Provider Setup

Account & Backend Provider Setup

Select a Network and Provider

First we need to select a network for our transaction. You can choose one of the available public test network.

  • Preprod
  • Preview
  • Local Devnet (Yaci DevKit) — for local development and testing

Similarly, choose a backend provider to interact with Cardano blockchain. You can select either Koios or Blockfrost as backend provider.

Please check dependencies page to find the required dependency for your selected backend provider.

For Blockfrost as backend provider, you need to first create an account on blockfrost.io  and get a Project Id for the selected network.

For Koios backend provider, you don’t need any registration.

For Yaci DevKit as a local development environment, install and run Yaci DevKit . It provides a local Cardano devnet with built-in Yaci Store that exposes Blockfrost-compatible APIs. No registration or API key is required.

Create Accounts

The following code snippet shows how to create a new testnet account.

Account account = new Account(Networks.testnet()); String baseAddress = account.baseAddress(); String mnemonic = account.mnemonic();

If you already have mnemonic for an existing account, you can create the account from mnemonic.

String mnemonic = "<24 words mnemonic>"; Account account = Account.createFromMnemonic(Networks.testnet(), mnemonic);

Two types of address can be generated, mainnet address or testnet address.

To generate a test network address, you can use any of the network constant Networks.testnet(), Networks.preprod() or Networks.preview(). The generated testnet address can be used on any of the test network. (The address generation depends on the NetworkId in Network object not protocol magic. These public test networks have same network id (0))

For mainnet address, you need to use Networks.mainnet()

Topup account with test Ada

Based on your selected network, get some test Ada from one of the below faucet. You need to provide an address generated in the previous section to get some test Ada.

https://docs.cardano.org/cardano-testnet/tools/faucet 

Create Backend Service

For Blockfrost :

Use the correct Blockfrost url for the selected network and project id to create an instance of BackendService.

String bfProjectId = "preprod..."; BackendService backendService = new BFBackendService(Constants.BLOCKFROST_PREPROD_URL, bfProjectId);

Note: You can find Blockfrost urls for the supported networks in com.bloxbean.cardano.client.backend.blockfrost.common.Constants.

or,

For Koios :

BackendService backendService = new KoiosBackendService(Constants.KOIOS_PREVIEW_URL);

Note: You can find other Koios urls in com.bloxbean.cardano.client.backend.koios.Constants

or,

For Yaci DevKit (Local Devnet) :

BackendService backendService = new BFBackendService("http://localhost:8080/api/v1/", "dummy-key");

Note: Yaci DevKit uses Yaci Store which provides Blockfrost-compatible APIs.

Last updated on