Query_blocks <-- ICP ledger Candid 🙌

Here’s kind of a dirty workaround if you want to stick to typescript and you’re using node

const getBlocksWorkaround = (start: bigint, length: bigint) => {
    const result: Buffer = execSync(
        `dfx canister --network ic call "qjdve-lqaaa-aaaaa-aaaeq-cai" ` +
        `get_blocks '(record {start = 4 : nat64; length = 20 : nat64} )' ` +
        `--candid ${process.cwd()}/src/nns_interfaces/archive/archive.did`
    );
    return result.toString();
};

Unfortunately it looks like you’ll have to parse or serialize this into JSON yourself, unless there’s some feature of DFX I’m unaware of.

icx looks like it could be useful, but i think it only serializes messages that are meant to be sent.

And if you want to use https://github.com/dfinity/idl2json:

const getBlocksWorkaround = (start: bigint, length: bigint) => {
    const path_to_idl2json_binary = '/Users/asdfpath/debug/idl2json';
    const cmd = `dfx canister --network ic call "${ARCHIVE_CANISTER_ID}" ` +
        `get_blocks '(record {start = ${start} : nat64; length = ${length} : nat64} )' ` +
        `--candid ${process.cwd()}/src/nns_interfaces/archive/archive.did` +
        `| ${path_to_idl2json_binary}`;
    const result: Buffer = execSync(cmd);
    const parsed_result = JSON.parse(result.toString());
    return parsed_result.Ok;
};

console.log(getBlocksWorkaround(4n, 20n));
console.log(getBlocksWorkaround(4n, 20n).blocks[0]);

Seems as if they ran into the same exact issue in this thread