Anchoring trees to blockchains

Contents

Importing

import { anchor } from "provendb-sdk-node";

Creating The Client

let client = anchor.connect(anchor.withCredentials("YOUR_API_KEY"));

Submitting a Proof

To submit a quick proof with defaults:

let proof = await client.submitProof("da63e4bd82fc6e5fd7337e6bd9147d8cada6652d9049020edc6deb69b18cf69c");

To submit a proof and wait for the proof to be CONFIRMED before resolving the promise, add the submitProofWithAwaitConfirmed option:

let proof = await client.submitProof("da63e4bd82fc6e5d7337e6bd9147d8cada6652d9049020edc6deb69b18cf69c", 
    anchor.submitProofWithAwaitConfirmed(true));

To submit a proof with different anchor types, add the submitProofWithAnchorType option:

let hederaProof = await client.submitProof("da63e4bd82fc6e5fd7337e6bd9147d8cada6652d9049020edc6deb69b18cf69c", 
    anchor.submitProofWithAnchorType(anchor.Anchor.Type.HEDERA_MAINNET));

let ethereumProof = await client.submitProof("da63e4bd82fc6e5fd7337e6bd9147d8cada6652d9049020edc6deb69b18cf69c", 
    anchor.submitProofWithAnchorType(anchor.Anchor.Type.ETH_MAINNET));

let bitcoinProof = await client.submitProof("da63e4bd82fc6e5fd7337e6bd9147d8cada6652d9049020edc6deb69b18cf69c", 
    anchor.submitProofWithAnchorType(anchor.Anchor.Type.BTC_MAINNET));

Subscribing to Proof Changes

When a proof is submitted, it is yet to be confirmed (unless your specify submitProofWithAwaitConfirmed option). Depending on the chosen anchor type, it may take a while for a proof to be CONFIRMED status. By subscribing to a proof, you will receive an updated proof when its status changes.

let proof = await client.submitProof("da63e4bd82fc6e5fd7337e6bd9147d8cada6652d9049020edc6deb69b18cf69c")

client.subscribeProof(proof.id, proof.anchorType, callback(err, proof) => {
    if (err) {
        // handle error
    } else {
        // do something with proof
    }
})

Alternatively, you can retrieve a proof without subscribing by periodically calling getProof.

// Submit the proof
let submitted = await client.submitProof("da63e4bd82fc6e5fd7337e6bd9147d8cada6652d9049020edc6deb69b18cf69c")

// Wait 
// Update the proof with getProof
let updated = await getProof(proof.id, proof.anchorType)