/
shyft.js
33 lines (30 loc) · 1.27 KB
/
shyft.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import {clusterApiUrl, Connection, Keypair, Transaction } from '@solana/web3.js';
import { NodeWallet } from '@metaplex/js';
import { WalletAdapterNetwork } from '@solana/wallet-adapter-base';
import { decode } from 'bs58';
import { Buffer } from 'buffer';
//import { ShyftWallet } from '../types';
export async function confirmTransactionFromBackend(network, encodedTransaction, privateKey) {
const connection = new Connection(clusterApiUrl(network), 'confirmed');
const feePayer = Keypair.fromSecretKey(decode(privateKey));
const wallet = new NodeWallet(feePayer);
const recoveredTransaction = Transaction.from(
Buffer.from(encodedTransaction, 'base64')
);
const signedTx = await wallet.signTransaction(recoveredTransaction);
const confirmTransaction = await connection.sendRawTransaction(
signedTx.serialize()
);
return confirmTransaction;
}
export async function confirmTransactionFromFrontend(connection, encodedTransaction, wallet) {
console.log(encodedTransaction);
const recoveredTransaction = Transaction.from(
Buffer.from(encodedTransaction, 'base64')
);
const signedTx = await wallet.signTransaction(recoveredTransaction);
const confirmTransaction = await connection.sendRawTransaction(
signedTx.serialize()
);
return confirmTransaction;
}