Function encodeGenesisData

  • Function to encode genesis data in order to launch a new blockchain. The different values are serialized using protobuffers. One of the arguments is the dictionary which contains the relevant information to perform the serialization. By default the function contains the dictionary for the following keys:

    • "object_key::head_block"
    • "object_key::chain_id"
    • "object_key::genesis_key"
    • "object_key::resource_limit_data"
    • "object_key::max_account_resources"
    • "object_key::protocol_descriptor"
    • "object_key::compute_bandwidth_registry"
    • "object_key::block_hash_code"

    Example

    const signer = Signer.fromSeed("seed");
    const genesisDataDecoded = {
    entries: [
    {
    space: { system: true },
    alias: "object_key::genesis_key",
    value: signer.address,
    },
    ],
    };

    const genesisData = await encodeGenesisData(genesisDataDecoded);
    console.log(genesisData);

    // {
    // entries: [
    // {
    // space: { system: true },
    // key: "EiC3nO+XbeKg4C8ugW7M7XdfmJKY4i3l91KoJWxosQPImA==",
    // value: "AMpASH7CjUHBpl2QR8E5lGKVjVLAvJRg5g==",
    // },
    // ],
    // }

    Example

    adding a custom dictionary

    const contractId = Signer.fromSeed("seed").address;
    const zone = encodeBase64(decodeBase58(contractId));
    const genesisDataDecoded = {
    entries: [
    {
    space: { system: true, zone, id: 1 },
    key: "difficulty_metadata_key",
    value: {
    target: encodeBase64url(toUint8Array("F".repeat(64))),
    last_block_time: "1641038400000",
    difficulty: encodeBase64url(toUint8Array("1".repeat(64))),
    target_block_interval: "10",
    },
    },
    ],
    };

    const powJson = {
    nested: {
    mypackage: {
    nested: {
    difficulty_metadata: {
    "fields": {
    "target": { "type": "bytes", "id": 1 },
    "last_block_time": { "type": "uint64", "id": 2,
    "options": { "jstype": "JS_STRING" }
    },
    "difficulty": { "type": "bytes", "id": 3 },
    "target_block_interval": { "type": "uint64", "id": 4,
    "options": { "jstype": "JS_STRING" }
    }
    }
    },
    }
    }
    }
    }

    const dic = {
    difficulty_metadata_key: {
    serializer: new Serializer(powJson),
    typeName: "difficulty_metadata",
    },
    };

    const genesisData = await encodeGenesisData(genesisDataDecoded, dic);
    console.log(genesisData);

    // {
    // entries: [
    // {
    // key: "difficulty_metadata_key",
    // space: {
    // id: 1,
    // system: true,
    // zone: "AMpASH7CjUHBpl2QR8E5lGKVjVLAvJRg5g==",
    // },
    // value:
    // "CiD//////////////////////////////////////////xCAlIus4S8aIBERERERERERERERERERERERERERERERERERERERERERIAo=",
    // },
    // ],
    // };

    Parameters

    • genesisDataDecoded: GenesisDataDecoded

      Genesis data where the values are objects.

    • dictionary: DictionaryGenesisData = {}

      Set of keys which contains the relevant information to perform the serialization

    Returns Promise<GenesisDataEncoded>

Generated using TypeDoc