Skip to content

Commit

Permalink
Merge pull request #1051 from multiversx/TOOL-444-add-relayed-v-3-doc…
Browse files Browse the repository at this point in the history
…umentation

Add relayed v3 documetation
  • Loading branch information
danielailie authored Jan 28, 2025
2 parents 82b9c1a + 9963d73 commit 7a65945
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v13.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,48 @@ const tx = new Transaction({
tx.nonce = 42n;
```

### Preparing a relayed transaction

We are currently on the third iteration of relayed transactions. V1 and V2 are soon to be deactivated so we'll focus on V3.
For V3, two new fields have been added on transactions: `relayer` and `relayerSignature`.
Before the sender signs the transaction, the relayer needs to be set. After the sender has signed the transaction, the relayer can also sign the transaction and broadcast it.
Keep in mind that, for relayed V3 transactions we need an extra 50_000 gas. Let's see how we can create a relayed transaction:

```js
import { Transaction } from "@multiversx/sdk-core";

const grace = await loadTestWallet("grace");

# alice will be our relayer, that means she is paying the gas for the transaction
const alice = await loadTestWallet("alice");
const transactionComputer = new TransactionComputer();

# fetch the sender nonce of the network
const nonce = (await apiProvider.getAccount(grace.getAddress())).nonce;
# create the transaction
const transaction = new Transaction({
receiver: grace.getAddress().bech32(),
sender: grace.getAddress().bech32(),
gasPrice: BigInt(1000000000),
gasLimit: BigInt(150000),
chainID: "D",
nonce: BigInt(nonce),
relayer: alice.getAddress(),
value: BigInt(1),
});

# sender signs the transaction
transaction.signature = await grace.signer.sign(transactionComputer.computeBytesForSigning(transaction));
const buffer = transactionComputer.computeBytesForSigning(transaction);

# relayer signs the transaction
const signature = await alice.signer.sign(Buffer.from(buffer));
transaction.relayerSignature = signature;

# broadcast the transaction
await proxyProvider.sendTransaction(transaction);
```

### Signing a transaction

:::important
Expand Down

0 comments on commit 7a65945

Please sign in to comment.