Introducing RabbitStream⚡, earliest transaction detection from Solana Shreds with gRPC style filtering. Explore Now
shyft logo
Get API Key

Blogs

Dev Guides

How to Sign Transactions on Solana

Shyft Logo

Team Shyft

· January 21, 2026

In this post, we are going to generate a simple transaction and then sign it on Solana Blockchain.

There are 2 ways in which you can sign a Solana transaction:

  • Using a Solana wallet (phantom, sollet, etc) and approving manually in the browser.
  • Using a private key, which is useful if you want to automate the signing process say for example in the backend.

We have deployed a small project to test out transaction signing while working with Shyft APIs. Try it out here: https://shyft-insider.vercel.app/

In this tutorial, we will cover how to sign transactions automatically without having to approve every time through a wallet.

Get Team Shyft’s stories in your inbox

Join Medium for free to get updates from this writer.

We will create a simple transaction instruction to transfer some SOL from account A to B. Then sign it using a code snippet.

A = GE4kh5FsCDWeJfqLsKx7zC9ijkqKpCuYQxh8FYBiTJe
B = AaYFExyZuMHbJHzjimKyQBAH1yfA9sKTxSzBc6Nr5X4s

Generating Transaction Instruction

Below is the code to generate simple transfer instructions to transfer 1 SOL, on devnet:

import {
  clusterApiUrl,
  Keypair,
  PublicKey,
  SystemProgram,
  Transaction,
} from '@solana/web3.js';
async createTransferInstruction() : Promise<any> {
    const fromPubKey = new PublicKey('GE4kh5FsCDWeJfqLsKx7zC9ijkqKpCuYQxh8FYBiTJe');
    const tx = new Transaction().add(SystemProgram.transfer({
    fromPubkey: fromPubKey,
    /** Account that will receive transferred lamports */
    toPubkey: new PublicKey('AaYFExyZuMHbJHzjimKyQBAH1yfA9sKTxSzBc6Nr5X4s'),
    /** Amount of lamports to transfer */
    lamports: 100000000,
  }));
  const connection = new Connection(clusterApiUrl("devnet"), 'confirmed');
  const blockHash = (await connection.getLatestBlockhash('finalized')).blockhash;
  tx.feePayer = fromPubKey;
  tx.recentBlockhash = blockHash;
  const serializedTransaction = tx.serialize({ requireAllSignatures: false, verifySignatures: true });
  const transactionBase64 = serializedTransaction.toString('base64');
  return { 
    encoded_transaction: transactionBase64 
  };
}

The above code snippet returns base64 the encoded version of the transaction.

Signing Transaction

Now, let’s come to the second part where we take the response from the above function, sign, and send this transaction into the blockchain. Along with the encodedTransaction string from the previous function, this function also needs private_key the sender to successfully sign the transaction. The sender’s private key is needed because while creating the transaction above we assigned them fromPubKey as the tx.feePayer.

import { clusterApiUrl, Keypair, Transaction } from '@solana/web3.js';
async signTransaction(encodedTransaction: string, fromPrivateKey: string) : Promise<any> {
  try {    
    const connection = new Connection(clusterApiUrl("devnet"), 'confirmed');
    const feePayer = Keypair.fromSecretKey(decode(fromPrivateKey));
    const recoveredTransaction = Transaction.from(Buffer.from(encodedTransaction, 'base64'));
    recoveredTransaction.partialSign(feePayer);
    const txnSignature = await connection.sendRawTransaction(
      recoveredTransaction.serialize(),
    );
    return txnSignature;
  } catch (error) {
    console.log(error);    
  }
}

The above function signs and sends the transaction to Solana’s devnet and return the transaction signature.

Conclusion

You can use the code for the above 2 functions to create a backend API to transfer SOL. This can be achieved by exposing the first function via API call, which returns the encodedTransaction. You can put the code in the second function on your client-side or FE. So that, your users never have to pass their private keys over the network.

Hope this is useful. Happy hacking.

Related Posts

How to Reconnect and Replay Slots with Solana Yellowstone gRPC
Shyft

How to Reconnect and Replay Slots with Solana Yellowstone gRPC

In this article you will learn how to implement a reconnect logic for your Solana gRPC streams with replay functionality...

January 24, 2026

How to Update a Yellowstone gRPC Subscription Without Disconnecting the Stream
Shyft

How to Update a Yellowstone gRPC Subscription Without Disconnecting the Stream

Learn how to dynamically update your Yellowstone gRPC SubscribeRequest on Solana without disconnecting the stream. Inclu...

January 24, 2026

How to Stream Solana Accounts, Transactions &#038; Blocks with gRPC
Shyft

How to Stream Solana Accounts, Transactions & Blocks with gRPC

A comprehensive guide on how to stream real-time Solana accounts, transactions, and block updates using gRPC. Step-by-st...

January 22, 2026

Get in touch with our discord community and keep up with the latest feature
releases. Get help from our developers who are always here to help you take off.

GithubTwitterLinked inDiscordTelegramBlogsBlogs

Products

RabbitStreamgRPC NetworkSuperIndexerSolana APIs
Contact Us|Email: genesis@shyft.to