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.
The sendTransaction
method is only available in the Node.js environment. Ensure you have set up your Node.js environment before proceeding.
If you're in a browser environment, please refer to WalletConnect Documentation for information on sending transactions.
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
ObjectField | Type | Description |
---|---|---|
signer | Signer | ECPairInterface | Signer to authorize the transaction. |
refundTo | string | Address to refund unused satoshis. |
priorityFee | bigint | (Optional) Fee for prioritizing the transaction. |
feeRate | number | (Optional) Fee rate in satoshis per byte. |
utxos | UTXO[] | (Optional) UTXOs to fund the transaction. |
maximumAllowedSatToSpend | bigint | Max satoshis allowed to spend. |
network | Network | The Bitcoin network (e.g., regtest, mainnet). |
InteractionTransactionReceipt
ObjectField | Type | Description |
---|---|---|
transactionId | string | The ID of the transaction on the network. |
newUTXOs | UTXO[] | Newly created UTXOs from the transaction. |
peerAcknowledgements | number | Number 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:
-
Simulate the Transaction: Obtain the simulation result from a contract interaction. For example:
const result = await op20Contract.approve(addressPublicKey, 1000n); // Simulate an `approve` transaction
-
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; -
Call
sendTransaction
: Using the simulation object, pass the necessary parameters tosendTransaction
: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
});