Create New Block
Here you will find the description on how new blocks structure should be configured
Requirements
Read the height and hash of the last block of the scope. See example here.
Authorized key-pair. See Authentication.

Build a new block
The following data is required to build a new block:
prevHash
: Hash of the last block of the scopeheight
: Height of the last block of the scope + 1version
: API version, at the time of writing this documentation is2
data
: Block content: Any type. will be stringified as default.timestamp
: Tiemstamp in Unix formatscope
:Name of the scope in which to write. This could be signer, child, or Smart Contract hash (soon to be SC alias).by
: Name of the authorized signer. Owner of the key-pair used to signsignature
: Block signaturehash
: Hash of the new block
To obtain the last two fields, it is necessary to go through a process to sign and generate the hash of the new block, which is explained below.
Sign a block
The signature of a new block is generated using a cryptographic tool that generates a hash based on the RSA-PSS algorithm.
The data used to generate the signature is an object that contains the following information:
{ prevHash, height, version, data, timestamp, by, scope }
Example:
let blockToSign = {
prevHash: "bd125e337f0cc7782b0e3465157b60535151362220f490650bed6b4be69bbb4b",
height: 14,
version: 2,
data: "Hello World!",
timestamp: 1669768443723,
scope: "DATA"
};
const algorithmParameters = {
name: "RSA-PSS",
saltLength: 32,
};
let signature0 = await subtle.sign(
algorithmParameters,
await getPrivateKey(),
Buffer.from(JSON.stringify(blockToSign, null, 2))
);
let signature = Buffer.from(signature0).toString("base64");
Generate a new hash
Once you have the signature of the block, you must generate the new hash using the SHA-256 cryptographic algorithm.
The data used to generate the hash is an object that contains the following information:
{prevHash, height, version, data, timestamp, by, scope, signature }
Example:
const blockToHash = {
prevHash: "bd125e337f0cc7782b0e3465157b60535151362220f490650bed6b4be69bbb4b",
height: 14,
version: 2,
data: "Hello World!",
timestamp: 1669768443723,
by: "DATA",
scope: "DATA",
signature: "WQJFA6B1cr8jZqGu08fh/LHk41nWif4Qun+2g1eIrrE8/l3WxSiSFicM86YLqCWwtFVQ+i5j8wsY8BfrxE4Cz/6Mc8FXOsUgYKdUzIKC5Og0+PgwlJOSLIaazNHS/4ypKExcIatB1dpQKU4Y5e+ozytQIM/i5E4tPbPTzP3avVYfnsAutINpGKcvhW6+6A8FUWH90OmeOpXE+c7OQb400z4BlCCQWE7rYnxSM4gUCJBuJ1T5ABm7/JfdGffNk+5xThe1NBVu7WEo85OhMMOFpOm48k9q53At1pAduJaTuO1IYU5qXfmQJa5w5tm7MLmOsC0mGJVY/PoRDQ9/K/xu/g==",
}
let hash256 = crypto.createHash("sha256");
const data = hash256.update(JSON.stringify(blockToHash));
let hash = data.digest("hex");
Last updated