SDK

The following code is implemented, taking typescript as an example, using \@bfchain/pc-sdk to call the interface

import {BFChainPC_SDK} from "@bfchain/pc-sdk";
export class BFChainPcSdkTest {
    private __sdk: BFChainPC_SDK;
    constructor() {
        this.__sdk = new BFChainPC_SDK();
    }
    async execute() {
        this.__sdk.init({ ip: "192.168.0.1", port: 19003, timeout: 10000 });
        let promises: Promise<any>[] = [];
        let funcNames: string[] = [];
        const pushPromise = (funcName: string, promise: Promise<any>) => {
            promises.push(promise);
            funcNames.push(funcName);
        };
        // Basic interface
        pushPromise("getLastBlock", this.getLastBlock());
        pushPromise("getBlock", this.getBlock());
        pushPromise("getTransactions", this.getTransactions());
        // Transaction interface
        pushPromise("trTransferAsset", this.trTransferAsset());
        pushPromise("trVote", this.trVote());
        const resp = await Promise.all(promises);
        for (let idx = 0; idx <resp.length; idx++) {
            const value = resp[idx];
            let data = `idx: ${idx} name: ${funcNames[idx]} --- ${JSON.stringify(
                value
            )}`;
            console.log(data);
        }
    }
    async getLastBlock() {
        /**
        * Get the latest block of the local node
        */
        return this.__sdk.getLastBlock();
    }
    async getBlock() {
        /**
        * Query the block with a block height of 11
        */
        return this.__sdk.getBlock({
            height: 11
        });
    }
    async getTransactions() {
        /**
        *
        Query all events where the block height is 11, the event initiator address is address1, and the event receiver address is address2
        */
        return this.__sdk.getTransactions({
            height: 11,
            senderId: address1,
            recipientId: address2
        });
    }
    async trTransferAsset(
        request?: BFChainPcSdk.ApiRequest.TRANSACTION.TrTransferAsset
    ) {
        /**
        * The account whose private key is secret2 transfers 50,000 BFT to the account whose address is address3, and the handling fee is 50 BFT
        */
        return this.__sdk.trTransferAsset(
            request ?? {
                secret: secret2,
                fee: "50",
                amount: "50000",
                recipientId: address3,
                assetType: "BFT"
            }
        );
    }
    async trVote() {
        /**
        * The account whose private key is secret1 votes for the account whose address is address2, the voting rights are 10, and the handling fee is 50 BFT
        */
        return this.__sdk.trVote({
            secret: secret1,
            fee: "50",
            recipientId: address2,
            equity: "10"
        });
    }
}
(async () => {
    const test = new BFChainPcSdkTest();
    await test.execute();
})().catch(err => {
    console.error(err);
});