Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@solana/transactions
Advanced tools
Helpers for creating and serializing transactions
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 the Solana JavaScript SDK @solana/web3.js@rc
.
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
)ITransactionMessageWithFeePayer
)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.
FullySignedTransaction
This type represents a transaction that is signed by all of its required signers. Being fully signed 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
. The transaction must have a signature for all required signers after being signed by the input CryptoKey
objects.
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.
Base64EncodedWireTransaction
This 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 5,829 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 14 open source maintainers 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.