Skip to content

Commit

Permalink
Show VersionedTransaction in the tx requests doc
Browse files Browse the repository at this point in the history
  • Loading branch information
mcintyre94 committed Dec 15, 2023
1 parent f766d4d commit 1c0e4ca
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions docs/src/core/transaction-request/MERCHANT_INTEGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ The `GET` endpoint should respond with two properties. `label` describes the sou
The second part of the transaction request spec is the `POST` request.

```javascript
import { clusterApiUrl, Connection, Keypair, PublicKey, Transaction } from '@solana/web3.js';
import { clusterApiUrl, Connection, Keypair, PublicKey, VersionedTransaction } from '@solana/web3.js';
import BigNumber from 'bignumber.js';
import { createTransferCheckedInstruction, getAccount, getAssociatedTokenAddress, getMint } from '@solana/spl-token';
import { TEN } from '@solana/pay';
Expand All @@ -103,18 +103,18 @@ const post = async (request, response) => {
const splTransferIx = await createSplTransferIx(sender, connection);

// create the transaction
const transaction = new Transaction();

// add the instruction to the transaction
transaction.add(splTransferIx);

// Serialize and return the unsigned transaction.
const serializedTransaction = transaction.serialize({
verifySignatures: false,
requireAllSignatures: false,
});

const base64Transaction = serializedTransaction.toString('base64');
const transaction = new VersionedTransaction(
new TransactionMessage({
payerKey: sender,
recentBlockhash: '11111111111111111111111111111111',
// add the instruction to the transaction
instructions: [splTransferIx]
}).compileToV0Message()
)

const serializedTransaction = transaction.serialize()

const base64Transaction = Buffer.from(serializedTransaction).toString('base64');
const message = 'Thank you for your purchase of ExiledApe #518';

response.status(200).send({ transaction: base64Transaction, message });
Expand Down

0 comments on commit 1c0e4ca

Please sign in to comment.