Phantom Developer Docs
HomeDeveloper Forums
  • 👻Introduction
    • Introduction
  • 🟩Solana
    • Getting Started With Solana
    • Detecting the Provider
    • Establishing a Connection
    • Sending a Legacy Transaction
    • Sending a Versioned Transaction
    • Signing a Message
    • Error Messages and Codes
  • 🔷Ethereum, Monad Testnet, Base, & Polygon
    • Getting Started with EVM networks
    • Detecting the Provider
    • Establishing a Connection
    • Sending a Transaction
    • Signing a Message
    • Provider API Reference
      • Properties
        • isPhantom
        • chainId
        • networkVersion
        • selectedAddress
        • _events
        • _eventsCount
      • Events
        • Connect
        • Accounts Changed
        • Disconnect
        • Chain Changed
      • Methods
        • isConnected
        • request
      • Error Messages & Codes
  • 🌊Sui
    • Getting Started with Sui
    • Detecting the Provider
    • Establishing a Connection
    • Sending a Transaction
    • Signing a Message
  • 🟠Bitcoin
    • Getting Started With Bitcoin
    • Detecting the Provider
    • Establishing a Connection
    • Sending a Transaction
    • Signing a Message
    • Provider API Reference
  • ⛓️Phantom Deeplinks
    • Phantom Deeplinks
    • Provider Methods
      • Connect
      • Disconnect
      • SignAndSendTransaction
      • SignAllTransactions
      • SignTransaction
      • SignMessage
    • Other Methods
      • Browse
      • Fungible
      • Swap
    • Handling Sessions
    • Specifying Redirects
    • Encryption
    • Limitations
  • 🛠️Developer Powertools
    • Auto-Confirm
    • Domain and Transaction Warnings
    • Mobile Web Debugging
    • Phantom Blocklist
    • Shortcuts
    • Sign-In-With (SIW) Standards
    • Solana Actions & Blinks
    • Solana Priority Fees
    • Solana Token Extensions (Token22)
    • Solana Versioned Transactions
    • Testnet Mode
    • Token Pages
    • Wallet Standard
  • ✅Best Practices
    • Launching a Dapp
    • Displaying Apps within the Activity Tab
    • Displaying Apps within Dialogs
    • Displaying Tokens on Solana
      • Fungibles
      • NFTs & Semi-Fungibles
      • Supported Media Types
  • 🙋Resources
    • FAQ
    • Demo Applications
    • Community Guides & SDKs
    • Logos & Assets
Powered by GitBook
On this page
  • Signing and Sending a Transaction
  • Signing and Sending Multiple Transactions
  • Other Signing Methods
  • Signing a Transaction (Without Sending)
  • Signing Multiple Transactions

Was this helpful?

  1. Solana

Sending a Legacy Transaction

PreviousEstablishing a ConnectionNextSending a Versioned Transaction

Last updated 1 year ago

Was this helpful?

Once a web application is connected to Phantom, it can prompt the user for permission to send transactions on their behalf.

In order to send a transaction, a web application must:

  1. Create an unsigned transaction.

  2. Have the transaction be signed and submitted to the network by the user's Phantom wallet.

  3. Optionally await network confirmation using a Solana JSON RPC connection.

For more information about the nature of Solana transactions, please review the as well as the .

For a sample Phantom transaction, check out our .

Signing and Sending a Transaction

Once a transaction is created, the web application may ask the user's Phantom wallet to sign and send the transaction. If accepted, Phantom will sign the transaction with the user's private key and submit it via a Solana JSON RPC connection. By far the easiest and most recommended way of doing this is by using the signAndSendTransaction method on the provider, but it is also possible to do with request. In both cases, the call will return a for an object containing the signature.

const provider = getProvider(); // see "Detecting the Provider"
const network = "<NETWORK_URL>";
const connection = new Connection(network);
const transaction = new Transaction();
const { signature } = await provider.signAndSendTransaction(transaction);
await connection.getSignatureStatus(signature);
const provider = getProvider(); // see "Detecting the Provider"
const network = "<NETWORK_URL>";
const connection = new Connection(network);
const transaction = new Transaction();
const { signature } = await provider.request({
    method: "signAndSendTransaction",
    params: {
         message: bs58.encode(transaction.serializeMessage()),
    },
});
await connection.getSignatureStatus(signature);

You can also specify a SendOptions as a second argument into signAndSendTransaction or as an options parameter when using request.

For a live demo of signAndSendTransaction, please refer to the .

Signing and Sending Multiple Transactions

const provider = getProvider(); // see "Detecting the Provider"
const network = "<NETWORK_URL>";
const connection = new Connection(network);
const transactions = [new Transaction(), new Transaction()];
const { signatures, publicKey } = await provider.signAndSendAllTransactions(transactions);
await connection.getSignatureStatuses(signatures);

Other Signing Methods

The following methods are also supported, but are not recommended over signAndSendTransaction. It is safer for users, and a simpler API for developers, for Phantom to submit the transaction immediately after signing it instead of relying on the application to do so.

If you use the methods below, Phantom may display a warning message to users at the time of signing.

Signing a Transaction (Without Sending)

const provider = getProvider();
const network = "<NETWORK_URL>";
const connection = new Connection(network);
const transaction = new Transaction();
const signedTransaction = await provider.signTransaction(transaction);
const signature = await connection.sendRawTransaction(signedTransaction.serialize());
const provider = getProvider();
const network = "<NETWORK_URL>";
const connection = new Connection(network);
const transaction = new Transaction();
const signedTransaction = await provider.request({
    method: "signTransaction",
    params: {
         message: bs58.encode(transaction.serializeMessage()),
    },
});
const signature = await connection.sendRawTransaction(signedTransaction.serialize());

Signing Multiple Transactions

For legacy integrations, Phantom supports signing multiple transactions at once without sending them. This is exposed through the signAllTransactions method on the provider. This method is not recommended for new integrations. Instead, developers should make use of signAndSendAllTransactions.

const signedTransactions = await provider.signAllTransactions(transactions);
const message = transactions.map(transaction => {
    return bs58.encode(transaction.serializeMessage());
});
const signedTransactions = await provider.request({
    method: "signAllTransactions",
    params: { message },
});

It is also possible to sign and send multiple transactions at once. This is exposed through the signAndSendAllTransactions method on the provider. This method accepts an array of Solana transactions, and will optionally accept a object as a second parameter. If successful, it will return a for an object containing the array of string signatures and the publicKey of the signer.

Once a transaction is created, a web application may ask the user's Phantom wallet to sign the transaction without also submitting it to the network. The easiest and most recommended way of doing this is via the signTransaction method on the provider, but it is also possible to do via request. In both cases, the call will return a for the signed transaction. After the transaction has been signed, an application may submit the transaction itself via .

Please refer to the for an example of signTransaction.

For an example of signAllTransactions, please refer to the .

🟩
solana-web3.js docs
Solana Cookbook
developer sandbox
Promise
object
handleSignAndSendTransaction section of our developer sandbox
SendOptions
Promise
Promise
web3js's sendRawTransaction
handleSignTransaction section of our developer sandbox
handleSignAllTransactions section of our developer sandbox