BlocknoteManager
When using Blocknote behind an API, it's important to address a few complexities:
Users should never share their mnemonic. Instead, they should sign using their wallet.
Asking users to manually sign numerous transactions before uploading is impractical.
Uploading, compressing, and sending large files can exceed standard web request time limits (typically 30 seconds).
The BlocknoteManager will help streamline these processes efficiently.
The following documentation explains how your frontend and your backend must work together.
The 'funder-sender-receiver' pattern
The BlocknoteManager uses a simple pattern so the user never has to share their mnemonic.
They only need to sign one transaction to fund the entire process:
The cost of the operation is calculated, 2 accounts are created, the sender and the receiver.
A transaction is built with the amount to fund, this is the bootstrap transaction.
The user, acting as the funder, sign and send the boostrap transaction to the sender.
The sender sends the payload & the upload to the receiver.
When the process is over, both receiver and sender are closed and the left funds are sent back to the funder.

Good to know
The bootstrap transaction has an encrypted note. It contains the mnemonic of the sender. The receiver is a child address of the sender (HD address) .
The bootstrap transaction amount is always slightly higher than the exact calculated upload cost, the fees of each transaction is multiplied by 3 (this setting can be changed). This is because Algorand fees are dynamic and may change after the calculation. This doesn’t make the upload more expensive, because any leftover funds are sent back to the user at the end.
Handling API web request time limits
To avoid web request time limitation on the API side, the methods of the BlocknoteManager are queued and processed in the background. For every call, a UUID will be returned immediately.
You can use this UUID to check the status of the queued process and later retrieve the final response.
To support this workflow flawlessly, you will need:
1. An API endpoint that receives a UUID and returns the current status of the process from the queue.
For this purpose, the method getFromQueue(uuid) must be used
2. A simple frontend function that polls this endpoint to check progress, errors, and completion.
Step 1 - Prepare the Bootstrap transaction
The first method from the BlocknoteManager you want to use is prepareBoostrapTransaction()
It will calculate the required funds for the given content and prepare a transaction for the user to sign.
You will be returned a UUID.
Use the frontend getQueued() method seen previously to poll your api until the process is done.
If the process is running, you will receive the onProgress status from the underlying Blocknote instance.
When completed, the response will include all relevant upload's details.
The response includes a transaction property containing the bootstrap transaction and a key property. As the transaction is base64 encoded, the frontend would need to decode it:
algosdk.decodeUnsignedTransaction(algosdk.base64ToBytes(transaction));
On the frontend, the user must sign and send the transaction using their wallet.
Once the transaction is sent, retrieve its transaction id.
Both the transaction id and the key are required for the next step in the process.
Step 2 - Start upload
Call the runFromBootstrapTransaction() method giving it the bootstrap transaction id and the key. This will start the on-chain writing process. Note that if you want to encrypt your upload, the encryption details have to be inserted here.
From now, the process of writing data on-chain will be initiate.
A UUID is returned.
Again, use the getQueued() method to check the status of that task.
Last updated