交易策略是可以规定交易如何处理的规则,由您传递给交易请求的交易参数 引入。可用的策略如下:
下面的片段将显示哪些交易参数设置了哪些策略:
// #import { ScriptTransactionRequest };
const transactionRequest = new ScriptTransactionRequest({
tip: bn(10), // Sets the tip policy
witnessLimit: bn(1), // Sets the witness limit policy
maturity: 1, // Sets the maturity policy
maxFee: bn(1), // Sets the max fee policy
});
可以使用 TransactionResponse
从交易中检索用于交易的策略。下面的片段将显示如何从交易中检索策略:
// #import { ScriptTransactionRequest, TransactionResponse, Policy };
// Instantiate the transaction request with transaction parameters that would
// set the respective policies.
const transactionRequest = new ScriptTransactionRequest({
script: scriptBytecode,
gasLimit: bn(2000),
maturity: 2,
tip: bn(3),
witnessLimit: 900,
maxFee: bn(60_000),
});
// Set the script main function arguments
transactionRequest.setData(scriptAbi, scriptMainFunctionArguments);
// Fund the transaction
transactionRequest.addResources(resources);
// Submit the transaction and retrieve the transaction response
const tx: TransactionResponse = await wallet.sendTransaction(transactionRequest);
const response = await tx.waitForResult();
// is undefined if the transaction had no policies applied.
const policies: Policy[] | undefined = response.transaction.policies;