
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@solana/transactions
Advanced tools
This package contains types and functions for compiling, signing and sending transactions. It can be used standalone, but it is also exported as part of Kit @solana/kit.
Transactions are created by compiling a transaction message. They must then be signed before being submitted to the network.
compileTransaction()Given a TransactionMessage, this function returns a Transaction object. This includes the compiled bytes of the transaction message, and a map of signatures. This map will have a key for each address that is required to sign the transaction. The transaction will not yet have signatures for any of these addresses.
Whether a transaction message is ready to be compiled or not is enforced for you at the type level. In order to be signable, a transaction message must:
BaseTransactionMessage)TransactionMessageWithFeePayer)TransactionMessageWithBlockhashLifetime | TransactionMessageWithDurableNonceLifetime)In order to be landed on the network, a transaction must be signed by all of the private keys belonging to accounts that are required signers of the transaction.
FullySignedTransactionThis type represents a transaction that is signed by all of its required signers.
TransactionWithSizeLimitThis type represents a transaction that is under or equal to the maximum size limit for transactions on the Solana network.
SendableTransactionThis type represents a transaction that has all the required conditions to be sent to the network. Namely:
FullySignedTransaction)TransactionWithSizeLimit)The SendableTransaction type is a prerequisite of functions designed to land transactions on the network.
getSignatureFromTransaction()Given a transaction signed by its fee payer, this method will return the Signature that uniquely identifies it. This string can be used to look up transactions at a later date, for example on a Solana block explorer.
import { getSignatureFromTransaction } from '@solana/transactions';
const signature = getSignatureFromTransaction(tx);
console.debug(`Inspect this transaction at https://explorer.solana.com/tx/${signature}`);
signTransaction()Given an array of CryptoKey objects which are private keys pertaining to addresses that are required to sign a transaction, this method will return a new signed transaction of type FullySignedTransaction. This function will throw unless the resulting transaction is fully signed.
import { generateKeyPair } from '@solana/keys';
import { signTransaction } from '@solana/transactions';
const signedTransaction = await signTransaction([myPrivateKey], tx);
partiallySignTransaction()This function is the same as signTransaction() but does not require the transaction to be signed by all signers. A partially signed transaction cannot be landed on the network, but can be serialized and deserialized.
Before sending a transaction to be landed on the network, you must serialize it in a particular way. You can use these types and functions to serialize a signed transaction into a binary format suitable for transit over the wire.
Base64EncodedWireTransactionThis type represents the wire format of a transaction as a base64-encoded string.
getBase64EncodedWireTransaction()Given a signed transaction, this method returns the transaction as a string that conforms to the Base64EncodedWireTransaction type.
import { getBase64EncodedWireTransaction, signTransaction } from '@solana/transactions';
const serializedTransaction = getBase64EncodedWireTransaction(signedTransaction);
const signature = await rpc.sendTransaction(serializedTransaction, { encoding: 'base64' }).send();
FAQs
Helpers for creating and serializing transactions
The npm package @solana/transactions receives a total of 316,818 weekly downloads. As such, @solana/transactions popularity was classified as popular.
We found that @solana/transactions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.