Skip to content

Beet Maintainers' Handbook 1. Preparation for adding new API methods

Alex Megalokonomos edited this page Aug 30, 2018 · 1 revision

Beet uses the transaction builder of bitsharesjs behind the scenes in order to generate and sign transactions.

The flow of generating, signing and broadcasting a transaction is as follows (where tr is a transaction builder instance):

 tr.add_type_operation(operation.op_type, operation.op_data);
 tr.set_required_fees().then(async () => {
        tr.add_signer(pKey, pKey.toPublicKey().toPublicKeyString());
        let result = await tr.broadcast();
});

As you can see, the dynamic part is the op_type and op_data of the required transaction.

In order to add a new API method to Beet, we need to generate these 2 objects from the API method payload.

The relevant files for PREPARING a new API method for addition are:

https://github.com/bitshares/beet/blob/master/src/lib/Actions.js where the new API name is added to the list of constants.

and

https://github.com/bitshares/beet/blob/master/src/lib/Operations.js where the API method payload is transformed to the relevant operation object.

For example, a new transfer() API method would need a payload of rcpt_account_id, asset_id, amount, memo

We would simply add a case 'transfer' to the Operations.js file where the op_type would be set to transfer and payload data would be used to generate the following op_data:

{
    fee: {
        amount: 0,
        asset_id: asset_id
    },
    from: beet_account_id
    to: rcpt_account_id
    amount: { amount: amount, asset_id: asset_id },
    memo: memo_object
}

(More details about how to generate this & memo object here: https://github.com/bitshares/bitsharesjs/blob/master/examples/transfer.js)

With the above example, and the current voteFor API method implementation, I hope others can feel confident enough to propose/add more possible API calls.