Skip to content

Commit

Permalink
added docs on obtaining ophash before injecting (#2702)
Browse files Browse the repository at this point in the history
* added docs on obtaining ophash before injecting

* added versioned doc

* updated typo

* updated previous version
  • Loading branch information
dsawali authored Nov 7, 2023
1 parent e34e009 commit 3f4454e
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
49 changes: 49 additions & 0 deletions docs/ophash_before_injecting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: Getting the Operation Hash without Injecting
id: ophash_before_injecting
author: Davis Sawali
---

This section serves as a guide to get the operation hash without injecting it into the blockchain.

## Getting the Operation Hash

There might come a time when you, the developer, would like to grab the operation hash without injecting it into the blockchain.

To accomplish that, we have a utility function called `encodeOpHash()` in the `@taquito/utils` package. This function takes in the signed operation bytes in the form of a `string`, and outputs the operation hash of said transaction without injecting it.

### Usage example

Here is a simple example on getting the operation hash of a transaction (transfer) operation:

```js

// import { TezosToolkit } from '@taquito/taquito';
// import { encodeOpHash } from '@taquito/utils';
// import { LocalForger } from '@taquito/local-forging';

// const Tezos = new TezosToolkit('RPC_ENDPOINT');

const preparedTransfer = await Tezos.prepare.transaction({
amount: 1,
to: 'tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu'
});


// convert prepared operation into a forgeable object
const forgeParams = await Tezos.prepare.toForge(preparedTransfer);

// forge the transaction operation
const forger = new LocalForger();
const forgedBytes = await forger.forge(forgeParams);

// sign the transaction operation
const signedBytes = await Tezos.signer.sign(forgedBytes);

// get the operation hash using the encodeOpHash() function
const opHash = encodeOpHash(signedBytes.sbytes, new Uint8Array([3]));

```



1 change: 1 addition & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const sidebars = {
collapsed: false,
collapsible: false,
items: [
'ophash_before_injecting',
'drain_account',
'complex_parameters',
'confirmation_event_stream',
Expand Down
49 changes: 49 additions & 0 deletions website/versioned_docs/version-17.3.0/ophash_before_injecting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: Getting the Operation Hash without Injecting
id: ophash_before_injecting
author: Davis Sawali
---

This section serves as a guide to get the operation hash without injecting it into the blockchain.

## Getting the Operation Hash

There might come a time when you, the developer, would like to grab the operation hash without injecting it into the blockchain.

To accomplish that, we have a utility function called `encodeOpHash()` in the `@taquito/utils` package. This function takes in the signed operation bytes in the form of a `string`, and outputs the operation hash of said transaction without injecting it.

### Usage example

Here is a simple example on getting the operation hash of a transaction (transfer) operation:

```js

// import { TezosToolkit } from '@taquito/taquito';
// import { encodeOpHash } from '@taquito/utils';
// import { LocalForger } from '@taquito/local-forging';

// const Tezos = new TezosToolkit('RPC_ENDPOINT');

const preparedTransfer = await Tezos.prepare.transaction({
amount: 1,
to: 'tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu'
});


// convert prepared operation into a forgeable object
const forgeParams = await Tezos.prepare.toForge(preparedTransfer);

// forge the transaction operation
const forger = new LocalForger();
const forgedBytes = await forger.forge(forgeParams);

// sign the transaction operation
const signedBytes = await Tezos.signer.sign(forgedBytes);

// get the operation hash using the encodeOpHash() function
const opHash = encodeOpHash(signedBytes.sbytes, new Uint8Array([3]));

```



1 change: 1 addition & 0 deletions website/versioned_sidebars/version-17.3.0-sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"collapsed": false,
"collapsible": false,
"items": [
"ophash_before_injecting",
"drain_account",
"complex_parameters",
"confirmation_event_stream",
Expand Down

0 comments on commit 3f4454e

Please sign in to comment.