Sending a Transaction
Once the web application is connected to Phantom, it can send transactions on behalf of the user, with the user's permission.
In order to send a transaction, the web application must:
  • Create an unsigned transaction or transactions.
  • Have it be signed and submitted to the network by the user's Phantom wallet.
  • Optionally await the confirmation using a Solana JSON RPC connection.
For more information about the nature of transactions on Solana, it is recommended to review the solana-web3.js docs as well as the official Solana docs.
For a sample transaction check out our developer sandbox.

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 using their account's private key and Solana JSON RPC connection. By far the easiest and 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 Promise for an object containing the signature.
signAndSendTransaction()
request()
1
const network = "<NETWORK_URL>";
2
const connection = new Connection(network);
3
const transaction = new Transaction();
4
const { signature } = await window.solana.signAndSendTransaction(transaction);
5
await connection.confirmTransaction(signature);
Copied!
1
const network = "<NETWORK_URL>";
2
const connection = new Connection(network);
3
const transaction = new Transaction();
4
const { signature } = await window.solana.request({
5
method: "signAndSendTransaction",
6
params: {
7
message: bs58.encode(transaction.serializeMessage()),
8
},
9
});
10
await connection.confirmTransaction(signature);
Copied!
You can also specify a SendOptions object as a second argument into signAndSendTransaction or as an options parameter when using request.

Deprecated Methods

The following methods are still supported, but are no longer recommended and may be removed in a future version of Phantom. 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. For now, if you use the methods below, Phantom will display a warning message to users.

Signing a Transaction

Once a transaction is created, the web application may ask the user's Phantom wallet to sign the transaction using their account's private key. By far the easiest and recommended way of doing this is by using the signTransaction method on the provider, but it is also possible to do with request. In both cases, the call will return a Promise for the signed transaction.
signTransaction()
request()
1
const network = "<NETWORK_URL>";
2
const connection = new Connection(network);
3
const transaction = new Transaction();
4
const signedTransaction = await window.solana.signTransaction(transaction);
5
const signature = await connection.sendRawTransaction(signedTransaction.serialize());
Copied!
1
const network = "<NETWORK_URL>";
2
const connection = new Connection(network);
3
const transaction = new Transaction();
4
const signedTransaction = await window.solana.request({
5
method: "signTransaction",
6
params: {
7
message: bs58.encode(transaction.serializeMessage()),
8
},
9
});
10
const signature = await connection.sendRawTransaction(signedTransaction.serialize());
Copied!

Signing Multiple Transactions

It is also possible to sign and send multiple transactions at once. This is exposed through the signAllTransactions method on the provider.
signAllTransactions()
request()
1
const signedTransactions = await window.solana.signAllTransactions(transactions);
Copied!
1
const message = transactions.map(transaction => {
2
return bs58.encode(transaction.serializeMessage());
3
});
4
const signedTransactions = await window.solana.request({
5
method: "signAllTransactions",
6
params: { message },
7
});
Copied!
Last modified 1mo ago