Skip to main content

Sending a Simulated Transaction

After simulating a transaction and ensuring it behaves as expected, the next step is to send the transaction on the OP_NET network. This guide explains how to build and send a transaction based on simulation results using the sendTransaction method.


Method

sendTransaction(interactionParams: TransactionParameters): Promise<InteractionTransactionReceipt>;
  • Parameters:

    • interactionParams: TransactionParameters: The parameters required to send the transaction.
  • Returns:

    • Promise<InteractionTransactionReceipt>: An object containing details about the submitted transaction.

Object Definitions

TransactionParameters Object
FieldTypeDescription
signerSigner | ECPairInterfaceSigner to authorize the transaction.
refundTostringAddress to refund unused satoshis.
priorityFeebigint(Optional) Fee for prioritizing the transaction.
feeRatenumber(Optional) Fee rate in satoshis per byte.
utxosUTXO[](Optional) UTXOs to fund the transaction.
maximumAllowedSatToSpendbigintMax satoshis allowed to spend.
networkNetworkThe Bitcoin network (e.g., regtest, mainnet).
InteractionTransactionReceipt Object
FieldTypeDescription
transactionIdstringThe ID of the transaction on the network.
newUTXOsUTXO[]Newly created UTXOs from the transaction.
peerAcknowledgementsnumberNumber of peers that acknowledged the transaction.

Sending the Transaction

Once you have the simulation result, you can call the sendTransaction method directly on the simulation object. Here’s a conceptual explanation:

  1. Simulate the Transaction: Obtain the simulation result from a contract interaction. For example:

    const result = await op20Contract.approve(addressPublicKey, 1000n); // Simulate an `approve` transaction
  2. Signer Setup: Use the Wallet.fromWif for example, to create a signer object:

    const wallet = Wallet.fromWif("your-wif-key", networks.regtest); // Replace with your actual WIF
    const signer = wallet.keypair;
  3. Call sendTransaction: Using the simulation object, pass the necessary parameters to sendTransaction:

    const receipt = await result.sendTransaction({
    signer: signer,
    refundTo: "bcrt1...address", // Replace with your refund address
    feeRate: 100, // Optional: Fee rate in satoshis per byte
    priorityFee: 300n, // Optional: Priority fee in satoshis
    maximumAllowedSatToSpend: 100_000n, // Maximum satoshis to spend
    network: networks.regtest, // Network configuration
    });