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 management 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:
- Typescript
- Python
- Java
- PHP
- Golang
import { Bloock, IntegrityClient, RecordClient } from '@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();
const record = await recordClient.fromString('Hello world').build();
const records = [record];
const 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)
const _anchor = await integrityClient.waitAnchor(
sendReceipts[0].anchor,
120000
);
console.log('Done!');
} catch (e) {
console.log(e);
}
import os
import bloock
from bloock.client.integrity import IntegrityClient
from bloock.client.record import RecordClient
if __name__ == "__main__":
# 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()
records = [record]
send_receipts = integrity_client.send_records(records)
# Once we sent a record, we can wait for it's anchor
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!")
import com.bloock.sdk.Bloock;
import com.bloock.sdk.client.IntegrityClient;
import com.bloock.sdk.client.RecordClient;
import com.bloock.sdk.entity.integrity.Anchor;
import com.bloock.sdk.entity.integrity.RecordReceipt;
import com.bloock.sdk.entity.record.Record;
import java.util.List;
public class WaitAnchor {
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();
Record record = recordClient.fromString("Hello world").build();
List<Record> records = List.of(record);
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);
}
}
}
<?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());
package main
import (
"log"
"os"
bloock "github.com/bloock/bloock-sdk-go/v2"
"github.com/bloock/bloock-sdk-go/v2/client"
"github.com/bloock/bloock-sdk-go/v2/entity/integrity"
"github.com/bloock/bloock-sdk-go/v2/entity/record"
)
func main() {
bloock.ApiKey = os.Getenv("API_KEY")
recordClient := client.NewRecordClient()
integrityClient := client.NewIntegrityClient()
var records []record.Record
record, _ := recordClient.FromString("Hello world").Build()
// if err != nil { ... }
records = append(records, record)
receipt, _ := integrityClient.SendRecords(records)
// if err != nil { ... }
params := integrity.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...")
_, _ = integrityClient.WaitAnchor(receipt[0].Anchor, params)
// if err != nil { ... }
log.Println("Done!")
}