sendBatchRequest
Batch submit multiple independent requests in a single call. Each request executes independently — a failure in one does not affect others.
Additionally, when a signMessage request needs to depend on the result of a preceding request, you can link them via the dependsOn field. See the Dependent Requests section below for details.
Limitation: Maximum 5 requests per batch.
Supported Methods
sendTransaction- Send transactionsignMessage- Sign messagesignTransaction- Sign transactionsignAssociatedTransaction- Sign associated transactionencrypt- Encrypt datadecrypt- Decrypt data
Usage
import { useTuringWallet } from "turing-wallet-provider";
const wallet = useTuringWallet();
const requests = [
{
method: "sendTransaction",
params: {
flag: "P2PKH",
address: "recipient_address",
satoshis: 10000,
broadcastEnabled: true,
},
},
{
method: "signMessage",
params: {
message: "Hello World",
encoding: "utf8",
},
},
{
method: "encrypt",
params: {
message: "Secret message",
},
},
];
const results = await wallet.sendBatchRequest(requests);Parameters
type BatchRequestMethod =
| "sendTransaction"
| "signMessage"
| "signTransaction"
| "signAssociatedTransaction"
| "encrypt"
| "decrypt";
interface BatchRequest {
method: BatchRequestMethod;
params: Record<string, any>;
dependsOn?: string; // Field name to inject txids into (only for signMessage)
}| Field | Type | Description |
|---|---|---|
method | BatchRequestMethod | The wallet method to invoke |
params | Record<string, any> | Parameters for the specified method |
dependsOn | string | (Optional, signMessage only) The field name in this request's message (a JSON string) into which the txid array produced by the preceding request will be injected. See Dependent Requests |
Returns
Returns an array of results, each corresponding to a request at the same index.
type BatchResponse = Array<Record<string, any>>;Each element contains the response for the corresponding method (e.g. txid, sig, error, etc.).
Error Handling
const results = await wallet.sendBatchRequest(requests);
results.forEach((result, index) => {
if (result.error) {
console.error(`Request ${index + 1} failed:`, result.error);
} else {
console.log(`Request ${index + 1} success:`, result);
}
});Examples
Batch Transfer
Send multiple P2PKH transactions in a single batch call.
const batchTransfer = [
{
method: "sendTransaction",
params: {
flag: "P2PKH",
address: "address1",
satoshis: 10000,
broadcastEnabled: true,
},
},
{
method: "sendTransaction",
params: {
flag: "P2PKH",
address: "address2",
satoshis: 20000,
broadcastEnabled: true,
},
},
];
const results = await wallet.sendBatchRequest(batchTransfer);
results.forEach((result, index) => {
if (result.error) {
console.error(`Request ${index + 1} failed:`, result.error);
} else {
console.log(`Request ${index + 1} success:`, result.txid);
}
});Mixed Operations
Combine different method types — signing, sending, and encrypting — in a single batch.
const mixedOperations = [
{
method: "signMessage",
params: {
message: "Proof of ownership",
encoding: "utf8",
},
},
{
method: "sendTransaction",
params: {
flag: "P2PKH",
address: "recipient",
satoshis: 50000,
broadcastEnabled: true,
},
},
{
method: "encrypt",
params: {
message: "Sensitive data",
},
},
];
const results = await wallet.sendBatchRequest(mixedOperations);Dependent Requests
What problem does it solve?
Some workflows require: "first send one (or more) on-chain transactions, then have the wallet sign a message whose payload must include the txids of those just-sent transactions". But txids are not known until the transactions are constructed, so the caller cannot put them into signMessage's parameters in advance.
dependsOn is designed for exactly this case: in a batch request, the wallet automatically extracts a txid array from the result of the preceding request and injects it into the JSON message of the following signMessage.
If dependsOn is omitted, the two requests in the batch run as fully independent requests with no effect on each other.
When can it be used?
When using dependsOn, the batch request must satisfy:
- Exactly two requests
- Request 1:
signAssociatedTransactionorsendTransaction - Request 2:
signMessage, andparams.messagemust be a valid JSON string (the wallet parses the JSON before writing the field) dependsOnis a string specifying the field name to inject into that JSON (e.g."txids")
Note: this constraint only applies when using
dependsOn. In normal (non-dependent)signMessage,messagecan be any string.
What gets injected?
The wallet always injects a txid string array into the message JSON — even when there is only one txid (it will still be an array of length 1).
The first request may produce multiple txids (e.g. STABLECOIN_CREATE / FT_MINT / POOLNFT_MINT return two; signAssociatedTransaction may also return multiple). The wallet places all of them into the array in order. The table below shows how the wallet derives this array from each possible return shape:
| First request | Return shape of the first request | How the wallet builds the txid array |
|---|---|---|
signAssociatedTransaction | { txraws: string[] } | Compute the txid of each txraw in txraws, giving [txid1, txid2, ...] |
sendTransaction (broadcastEnabled: true, single txid) | { txid: "txid1" } | ["txid1"] |
sendTransaction (broadcastEnabled: true, multiple txids) | { txid: "txid1,txid2" } (comma-separated) | Split by comma → ["txid1", "txid2"] |
sendTransaction (broadcastEnabled: false, single txraw) | { txraw: "hex1" } | Compute its txid → ["txid1"] |
sendTransaction (broadcastEnabled: false, multiple txraws) | { txraw: "hex1,hex2" } (comma-separated) | Split by comma, compute each txid → ["txid1", "txid2"] |
Note: when
sendTransactionruns withbroadcastEnabled: falsefor a multi-tx flow (e.g.FT_MINT,POOLNFT_MINT,STABLECOIN_CREATE), the returnedtxrawis several hex strings joined by commas, and they must be broadcast in order externally. The wallet only splits by comma to compute txids here — it does not broadcast.
Where it is injected
The injection target field is determined by dependsOn. For example, dependsOn: "txids" is equivalent to:
JSON.parse(message).txids = [/* the extracted txid array */];The message that signMessage actually signs is the resulting full JSON string after injection.
Execution flow
- Execute request 1 (
signAssociatedTransactionorsendTransaction). - Build the txid array from the result, following the table above.
- Parse
params.messageof request 2 (must be a JSON string) and write the txid array into the field named bydependsOn. - Run
signMessagewith the resulting full JSON string as its message.
If request 1 fails, signMessage is not executed and the corresponding result entry contains the error.
Example 1: signAssociatedTransaction + signMessage (multiple txids)
const requests = [
{
method: "signAssociatedTransaction",
params: {
sourceTxraw: "...",
sourceUtxos: [
{
txId: "",
outputIndex: 0,
satoshis: 500,
script: ftcode,
scriptSigType: "tbc20",
},
{
txId: "",
outputIndex: 2,
satoshis: 10000,
script: p2pkh,
scriptSigType: "p2pkh",
},
],
inputs: [
[
{ outputIndex: 0, scriptSigType: "tbc20" },
{ outputIndex: 2, scriptSigType: "p2pkh" },
],
],
outputs: [
[
{ script: ftcode, satoshis: 500 },
{ script: fttape, satoshis: 0 },
{ script: p2pkh, satoshis: 8000 },
],
],
},
},
{
method: "signMessage",
params: {
message: JSON.stringify({
action: "mint",
amount: 100,
}),
encoding: "utf8",
},
dependsOn: "txids",
},
];
const results = await wallet.sendBatchRequest(requests);
// results[0] => signAssociatedTransaction result: { txraws: string[] }
// results[1] => signMessage result: { address, pubkey, sig, message }
// where message is the complete JSON with txids, e.g.:
// { "action": "mint", "amount": 100, "txids": ["txid1", "txid2", ...] }Example 2: sendTransaction + signMessage (preceding request returns multiple txids)
The STABLECOIN_CREATE call below returns two txids (joined by a comma in the txid field); the wallet automatically splits and injects them. The same applies to FT_MINT, POOLNFT_MINT, etc.
const requests = [
{
method: "sendTransaction",
params: {
flag: "STABLECOIN_CREATE",
ft_data: JSON.stringify({
name: "USD Test",
symbol: "USDT",
decimal: 6,
amount: 100000000,
}),
address: "",
mint_message: "SourceChain: BSC, TXID: 34434...",
broadcastEnabled: true,
domain: "",
},
},
{
method: "signMessage",
params: {
message: JSON.stringify({
action: "create_stablecoin",
}),
encoding: "utf8",
},
dependsOn: "txids",
},
];
const results = await wallet.sendBatchRequest(requests);
// results[0] => sendTransaction result: { txid: "txid1,txid2" }
// results[1] => signMessage result: { address, pubkey, sig, message }
// where message is the complete JSON with txids, e.g.:
// { "action": "create_stablecoin", "txids": ["txid1", "txid2"] }