Executing Transactions

Construct and send transactions for execution on Solana.

After connecting to Glow and (optionally) signing the user in, you are now ready to ask the user to sign transactions!

Glow offers the ability to either sign a single transaction, or sign multiple transactions at once. In addition, you can choose to let Glow submit the transaction(s) for you, or you can get the signed one(s) back and submit them yourself.

When prompting the user to approve, we simulate the transaction(s) and show the user any balance and delegation change. For security reasons, we don't offer auto-approve capability.

Signing Single Transaction

To sign a single transaction, use the window.glow.signTransaction function. It takes two parameters:

  • transactionBase64, the transaction to sign, in base-64 encoding, and
  • network, which can be either mainnet or devnet. This parameter is optional. If omitted, it defaults to mainnet.
const { 
  signature, // string
  signedTransactionBase64 // string
} = await window.glow.signTransaction({
    // string: transaction in base-64 encoding
    transactionBase64: transaction,
    // optional string: mainnet (default) or devnet
    network: "devnet",
});

The response contains the signed transaction in base 64 encoding, and the transaction signature.

Alternatively, you can use the window.glow.signAndSendTransaction function to let Glow sign and also send the transaction for you. It takes transactionBase64 and network like the plain signTransaction function, and an additional optional parameter, waitForConfirmation. If set to true, the function will only return after the transaction has been confirmed on the blockchain.

const { 
  signature // string
} = await window.glow.signAndSendTransaction({
    // string: transaction in base-64 encoding
    transactionBase64: transaction,
    // optional string: mainnet (default) or devnet
    network: "devnet",
    // optional boolean: default is false
    waitForConfirmation: true
});

TODO: Write about errors thrown here (we may need to standardize them).

Signing Multiple Transactions

You can also batch sign multiple transactions for execution. Similar to the above, you can either get the signed transactions back to submit yourself, or let Glow sign and submit for you. If you choose the latter, transactions are sent one at a time. Subsequent transactions are only submitted when the preceding transaction is confirmed on the blockchain, allowing you to execute transactions that depend on each other.

const { 
  signedTransactionsBase64 // string[]
} = await window.glow.signAllTransactions({
    // string[]: transactions in base-64 encoding
    transactionsBase64: transactions,
    // optional string: mainnet (default) or devnet
    network: "devnet",
});

// OR:
const { 
  signatures // string[]
} = await window.glow.signAndSendAllTransactions({
    // string[]: transactions in base-64 encoding
    transactionsBase64: transactions,
    // optional string: mainnet (default) or devnet
    network: "devnet",
});