BLOOCK Docs
Search
⌃K

Synchronization

Once a data is sent for certification to BLOOCK, there's a time interval until it gets processed and transacted to the different blockchain networks. This time interval can be variable and, in some networks, pretty long,
We provide two ways of managing this time interval:

Asynchronous

This allows to get notified via Webhook every time an anchor is transacted to an specific network.
A webhook is an HTTP request, triggered by an event in the source system and then, sent to the destination system. Webhooks are automatically sent out when their event is fired in the source system.
To start using this method, you will need to Configure a Webhook on our managment website and selecting one or more networks to wait for.
Once a webhook is configured and a new anchor is processed for one of the selected networks, you will receive a POST request to the URL you configured with the following payload:
{
"created_at": <unix timestamp in seconds when the anchor was processed>,
"finalized": <if the anchor has finished processing, it will always be set to true>,
"id": <anchor identifier>,
"message_count": <number of records processed in this anchor>,
"network": {
"anchor_id": <anchor identifier>,
"created_at": <unix timestamp in seconds when the transaction was triggered>,,
"name": <name of the network>,
"status": <status of the transaction>,
"test": <if the transaction is for the test environment or not>,
"tx_hash": <blockchain transaction hash>
},
"root": <anchor root>,
"test": <if the transaction is for the test environment or not>
}

Synchronous

It's recommended to only use this method for networks with low internal times (<3 minutes)
It's also possible to wait for the interval in a synchronous manner by using our SDKs directly. This allows to keep a single code snippet that handles all the certification flow.
To do so, we provide a specific method that polls our APIs every second until the next anchor is processed. Here are some code examples to implement it:
Javascript
Java
Python
PHP
Golang
const { Bloock, IntegrityClient, RecordClient } = require("@bloock/sdk");
try {
// we set the API key and create a client
Bloock.setApiKey(process.env["API_KEY"]);
const recordClient = new RecordClient();
const integrityClient = new IntegrityClient();
let record = await recordClient.fromString("Hello world").build();
let hash = await record.getHash();
let records = [hash];
let sendReceipts = await integrityClient.sendRecords(records);
// Once we sent a record, we can wait for it's anochor
console.log("Waiting for anchor...");
// we can optionally specify a timeout (if not set, default is 120000)
let anchor = await integrityClient.waitAnchor(sendReceipts[0].anchor, 120000);
console.log("Done!");
} catch (e) {
console.log(e);
}
import com.bloock.sdk.Bloock;
import com.bloock.sdk.client.IntegrityClient;
import com.bloock.sdk.client.RecordClient;
import com.bloock.sdk.entity.Record;
import com.bloock.sdk.entity.RecordReceipt;
class Test {
public static void main(String[] args) throws Exception {
try {
// we set the API key and create a client
Bloock.apiKey = System.getenv("API_KEY");
RecordClient recordClient = new RecordClient();
IntegrityClient integrityClient = new IntegrityClient();
ArrayList<String> records = new ArrayList<>();
Record record = recordClient.fromString("Hello world").build();
records.add(record.getHash());
List<RecordReceipt> receipts = integrityClient.sendRecords(records);
// Once we sent a record, we can wait for it's anochor
System.out.println("Waiting for anchor...");
// we can optionally specify a timeout (if not set, default is 120000)
Anchor anchor = integrityClient.waitAnchor(receipts.get(0).getAnchor(), 120000);
System.out.println("Done!");
} catch (Exception e) {
System.out.println(e);
}
}
}
import os
import bloock
from bloock.client.integrity import IntegrityClient
from bloock.client.record import RecordClient
# we set the API key and create a client
bloock.api_key = os.environ["API_KEY"]
record_client = RecordClient()
integrity_client = IntegrityClient()
record = record_client.from_string("Hello world").build()
hash = record.get_hash()
records = [hash]
send_receipts = integrity_client.send_records(records)
# Once we sent a record, we can wait for it's anochor
print("Waiting for anchor...")
# we can optionally specify a timeout (if not set, default is 120000)
anchor = integrity_client.wait_anchor(send_receipts[0].anchor, timeout=120000)
print("Done!")
<?php
require "./vendor/autoload.php";
use Bloock\Bloock;
use Bloock\Client\IntegrityClient;
use Bloock\Client\RecordClient;
Bloock::$apiKey = getenv("API_KEY");
$integrityClient = new IntegrityClient();
$recordClient = new RecordClient();
$record = $recordClient->fromString("Hello world")->build();
$sendReceipts = $integrityClient->sendRecords([$record]);
$anchor = $integrityClient->waitAnchor($sendReceipts[0]->getAnchor());
import (
"log"
"os"
"github.com/bloock/bloock-sdk-go/v2"
"github.com/bloock/bloock-sdk-go/v2/client"
"github.com/bloock/bloock-sdk-go/v2/entity"
)
func main() {
bloock.ApiKey = os.Getenv("API_KEY")
recordClient := client.NewRecordClient()
integrityClient := client.NewIntegrityClient()
var records []entity.Record
record, err := recordClient.FromString("Hello world").Build()
// if err != nil { ... }
records = append(records, record)
receipt, err := bloockClient.SendRecords(records)
// if err != nil { ... }
params := entity.NewAnchorParams()
// we can leve the params as default or we can specify a timeout
params.Timeout = 120000 // default is 120000
// Once we sent a record, we can wait for it's anochor
log.Println("Waiting for anchor...")
_, err = integrityClient.WaitAnchor(receipt[0].Anchor, params)
// if err != nil { ... }
log.Println("Done!")
}