Skip to main content
Version: Next

Preparing Operations

warning

This feature is currently a work in progress and may be updated in the near future.

Before operations are forged, signed, and then injected, they first need to go through a Prepare step.

In Taquito, the act of preparing an operation is to create the Operation Object and the counter in one single object that we name PreparedOperation.

An example of PreparedOperation object for a ballot operation looks something like this:

{
opOb: {
branch: 'test_block_hash',
contents: [
{
kind: 'ballot',
ballot: 'yay',
period: 103,
proposal: 'PtKathmankSpLLDALzWw7CGD2j2MtyveTwboEYokqUCP4a1LxMg',
},
],
protocol: 'test_protocol',
},
counter: 0,
}

The PreparedOperation object used to be abstracted from the user and would require a lot of workarounds to expose. We realize some users might want more control and information on what happens before operations are forged and signed. This offers a few benefits, a few of them being:

  • The ability to retrieve information about the operation before injecting (operation hash, etc)
  • The ability to simulate an operation before injecting

The PrepareProvider class affords extension and control to users when preparing operations while also promoting modularity in Taquito as a design principle.

Usage example

Individual Operations

The PrepareProvider will be accessible via the TezosToolkit:

// const Tezos = new TezosToolkit('RPC_ENDPOINT');
const prepared = await Tezos.prepare.transaction({
to: 'tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn',
amount: 5
});

Let's break that transaction prepare call down.

The interface of the transaction member method is as follows:

transaction(params: TransferParams , source?: string): Promise<PreparedOperation>;
  • params is the Transaction operation parameters. In this case, the required properties are to and amount.
  • source is the source public key hash if you do wish to override the source. This parameter is optional by design. If you do not wish to override it, the source will be grabbed from the Context.

Batch Operations

The PrepareProvider also provides support for batch operations:

const prepared = await Tezos.prepare.batch([
{
kind: OpKind.TRANSACTION,
to: 'tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn',
amount: 2,
},
{
kind: OpKind.TRANSACTION,
to: 'tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn',
amount: 2,
},
]);
  • the parameters are the required parameters for each respective operation with the added kind property that denotes the operation kind. Users can also utilize OpKind which is an enum that holds operation kind values.

Contract Calls

Users are also able to utilize the PrepareProvider to prepare contract calls:

// contractAddress refers to an originated increment/decrement smart contract,
// omitted for brevity
const contractAbs = await Tezos.contract.at(contractAddress);
const method = await contractAbs.methods.increment(1);
const prepared = await Tezos.prepare.contractCall(method);

Provide detailed feedback