Introduction to BighchainDB and Setup Part 1

Posted By : Himanshu Bhatt | 26-Jul-2019

Today in this blog I will show you how to set up the BigchainDB in your local machine through docker and send your data to the BigchainDB using java.

Bigchaindb is software it has blockchain properties it is a decentralized database there are two types of data that go to BigchainDB one is an asset and the other one is metadata. Asset data is immutable we cannot change it is the fixed data and metadata can be updated but if we have the private and public keys then only it can be updated. It follows the concept of the blockchain it is a type of a blockchain but we use it to store the data usually keys and URLs. There is no concept of any cryptocurrency. It has two things one is tender mint which checks the blocks and validates the blocks and the other one is MongoDB on which all the information related to a blockchain is saved.

Setup of BigchainDB on your local machine using docker

  • Install docker on your machine.

  • Clone the project from git clone [email protected]:bigchaindb/bigchaindb.git

  • cd BigchainDB

  • make run

This will start BigchainDB in your local machine and to check if it is running go to http://localhost:9984

Sending your data to BigchainDB  using spring boot

  • We need to add maven dependency for BigchainDB in our pom.xml:






  • Let's send the data to the BigchainDB. We will make a bigchainDbDetails domain class to save the user’s credentials in the domain. We will save the private and public key of the user it’s asset id and transaction id in the database.
public class BigChainDbDetails{
    private String assetId;
    private String publicKey;
    private String privateKey;
    private String transactionId;

    public BigChainDbDetails() {


    public BigChainDbDetails(String assetId, String publicKey, String privateKey, String transactionId) {
        this.assetId = assetId;
        this.publicKey = publicKey;
        this.privateKey = privateKey;
        this.transactionId = transactionId;
  • We will make a controller class to post the data to BigchainDB:
public class BigChainController {
    private BigChainDbService bigChainDbService;
    public ResponseEntity<Object>postBigChainData(@RequestBody MetaDataDto metaDataDto){
        return ResponseHandler.response(bigChainDbService.saveBigchainDataToDb(metaDataDto),"data saved");

  • Let's write the service class for the BigchainDB where all the business logic will be written. Here BigchainDB URL is the URL of the BigchainDB in which port it is running. We will use the KeyPair class for signing the public and private key.

public class BigChainDbService {
    private String bigChainDbUrl;
    private BigChainDbRepo bigChainDbRepo;

public boolean saveBigchainDataToDb(MetaDataDto metaDataDto) {
        KeyPair keyPair = new KeyPairGenerator().generateKeyPair();
            Optional<String> trasnactionID = saveNewCertificatesBlockchain(keyPair, metaDataDto, user.getEmail());
            if (trasnactionID.isPresent()) {
                BigChainDbDetails newBigChainDbDetails = new BigChainDbDetails(trasnactionID.get(), getBigchainPublicKey(keyPair), getBigchainPrivateKey(keyPair), trasnactionID.get(), user);


public Optional<String> saveNewCertificatesBlockchain(KeyPair keyPair, MetaDataDto metaDataDto, String assetData) {
        //Save new claim with asset info and meta data
        Map<String, Object> map = new HashMap<>();
        map.put("email", assetData);
        BigChainDbGenericCallback callback = new BigChainDbGenericCallback();
        Transaction createTransaction = null;
        try {
            createTransaction = BigchainDbTransactionBuilder.init()
                    .addAssets(map, HashMap.class)
                    .buildAndSign((EdDSAPublicKey) keyPair.getPublic(), (EdDSAPrivateKey) keyPair.getPrivate())
  "transactionId : {} , done : {} ", createTransaction.getId(), callback.isDone());
            while (!callback.isDone()) {
      "waiting ....");
  "task done : {} succes : {} ", callback.isDone(), callback.isSuccess());
            if (!callback.isSuccess()) {
                return Optional.empty();
        } catch (Exception e) {
            logger.error("exception from createTransaction : {}", e.getMessage());
            return Optional.empty();
        }"transcaction id is :::::{}", createTransaction.getId());
        return Optional.of(createTransaction.getId());
        //end new claim with asset info and metaData
  • Let’s make the dto for metadata in my case I only need two fields in metadata a url and name.
public class MetaDataDto {
    private String url;
    private String name;

That’s all in this part of the blog you can test the API by sending the metadata and you can assign the asset data. In the next part we will update the data and view the data.


About Author

Author Image
Himanshu Bhatt

Himanshu is a bright java developer. He is keen to learn new technologies. His hobbies are to travel and listen music.

Request for Proposal

Name is required

Comment is required

Sending message..