I am using methods such as forgeOperations, injectOperation provided by '@taquito/rpc' package.

However, this method works for already revealed accounts to complete the transfer between two tz1 accounts.

But, the above approach doesn't work if a tz1 account is transferring for the first time. I came to know that we should do reveal operation first before transaction operation.

How could we forge reveal and transaction operations at once and fulfil the requirement? Thanks in advance.

1 Answer 1


You have to just append the reveal operation to the contents of the (batched) operation you'd like to inject.

Here is a code snipped extracted from some TS code we wrote:

    let header = await getInjectionHeader(tk, injectionBranchOffset);
    level = header.level;
    let source = await tk.signer.publicKeyHash();
    let contract = await tk.rpc.getContract(source);
    let counter = parseInt(contract.counter || '0', 10)
    let contents: Array<RPCOperation> = []; // This will contain the contents of the TX

    let revealEstimate = await tk.estimate.reveal();
    if (revealEstimate !== undefined) { // Pk revelation needed. Put it at the beginning
      let publicKey = await tk.signer.publicKey();
      let revealParams = {
        fee: revealEstimate.suggestedFeeMutez,
        gasLimit: revealEstimate.gasLimit,
        storageLimit: revealEstimate.storageLimit
      let rpcRevealOperation = await createRevealOperation(revealParams, source, publicKey);
      contents.push(({ ...rpcRevealOperation, source, counter: counter } as RPCOperation))
    let len = transfersParams.length;
    // process all TXs (enforce sequentiality and ordering with an aux function)
    let processTX = async function (i: number): Promise<void> {
      if (i >= len) return;
      let transferParams = transfersParams[i];
      let estimate = await tk.estimate.transfer(transferParams);
      const rpcTransferOperation = await createTransferOperation({
        fee: estimate.suggestedFeeMutez,
        gasLimit: estimate.gasLimit,
        storageLimit: estimate.storageLimit
      let v = {
        parameter: transferParams.parameter,
        counter: counter,
      await processTX(i + 1);
    await processTX(0);
    let op = objToString({
      branch: header.hash,
      contents: contents
    let forgedOp = await tk.rpc.forgeOperations(op)
    let signOp = await tk.signer.sign(forgedOp, new Uint8Array([3]));

Hope this helps.

  • I am unable to understand parseInt(contract.counter || '0', 10) May I know why are you using || 0, 10 here ? I am using (Number(contract.counter) + 1).toString() as logic to assign counter for the operation. Correct me if I am wrong. @iguerNL Dec 2, 2021 at 20:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.