Skip to main content

Sending and Signing a Transaction

Nightly will prompt user to send transaction on their behalf, on a condition that application is connected to Nightly successfully. Application is required to follow the steps below for the transaction to be executed:

  1. Create new unsigned transaction.
  2. Nightly wallet sign and submit this transaction to Solana.
  3. As an option, application can get back confirmation of status of this transaction by using a Solana JSON RPC connection.
info

Please visit the following link to get better look at Solana transactions flow solana-web3.js, alongside with Solana Cookbook.

Signing single transaction

After a new transaction is created, application will prompt user's Nightly wallet to approve and send the transaction, by signing it. If the user approves transaction, Nightly will submit transaction details alongside with user's private key to Solana JSON RPC.

In order to do so, please use signTransaction() method provided below. This will sing and return the transaction back to the application.

  async signTransaction(transaction: Transaction) {
if (!this._provider) {
return transaction
}

return await this._provider.signTransaction(transaction)
}
const ix = SystemProgram.transfer({
fromPubkey: userPublicKey,
lamports: 1_000_000,
toPubkey: new PublicKey(toPublicKey)
})
const tx = new SolanaTx().add(ix).add(ix).add(ix)
const a = await connection.getRecentBlockhash()
tx.recentBlockhash = a.blockhash
tx.feePayer = userPublicKey
const signedTx = await NightlySolana.signTransaction(tx)
const id = await connection.sendRawTransaction(signedTx.serialize())

Signing Multiple Transactions

If you would like to execute the above method on multiple transactions, we recommend do it in a single call with signAllTransactions() method. This will sign all transactions and return a Promise for an object containing the signature.

  public async signAllTransactions(transactions: Transaction[]): Promise<Transaction[]> {
if (!this._provider) {
return transactions
}
return await this._provider.signAllTransactions(transactions)
}