Skip to content

Introduce the autoCost helper for transaction requests #3535

Closed
@danielbate

Description

#3495 proposes a way of optimising perceived transaction speed through pre-bundling dependencies. However, as shown in #3513 this process can be simplified.

Currently, costing and funding transaction request looks like:

const txRequest = new ScriptTransactionRequest();
const txCost = await wallet.getTransactionCost(txRequest);
txRequest.maxFee = txCost.maxFee;
txRequest.gasLimit = txCost.gasUsed;
await wallet.fund(txRequest, txCost);
const tx = await wallet.sendTransaction(txRequest);
await tx.waitForResult();

This process is neater with a contract call:

const call = contract.functions.echo_b256(ADDRESS_B256);
const txRequest = await call.fundWithRequiredCoins();
const tx = await wallet.sendTransaction(txRequest);
await tx.waitForResult();

We should implement the following:

  • Introduce a method (e.g. autoCost) purely for transaction requests that can cost and fund a transaction in a single call
  • Have parity between tx requests and contract calls for this flow

The proposed API would then look as follows:

const txRequest = new ScriptTransactionRequest().autoCost(wallet);
const tx = await wallet.sendTransaction(txRequest);
await tx.waitForResult();

Metadata

Assignees

Labels

featIssue is a feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions