Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving Doc Around Forwarding Amounts in Contract Calls with Custom Steps #3485

Open
Torres-ssf opened this issue Dec 16, 2024 · 0 comments
Assignees
Labels
docs Requests pertinent to documentation

Comments

@Torres-ssf
Copy link
Contributor

The TS SDK Docs need some improvements around executing custom steps within a contract call that forwards an amount to a contract.

The problem:

When executing a contract call that requires amounts to be forwarded to the contract, the TS SDK can properly estimate, fund, and submit the transaction:

const forwardQuantity: CoinQuantity = {
  amount: bn(1000),
  assetId: TestAssetId.A.value,
};

await contract.functions
   .increment_counter(1)
   .callParams({
     forward: forwardQuantity,
   })
   .call();

However, when custom steps are required such as modifying the TransactionRequest before sending the transaction, the forward amount must be explicitly included during estimation and funding steps to ensure accurate cost calculations.

const forwardQuantity: CoinQuantity = {
  amount: bn(1000),
  assetId: TestAssetId.A.value,
};

const txRequest = await contract.functions
  .increment_counter(1)
  .callParams({
    forward: forwardQuantity,
  })
  .getTransactionRequest();

const txCost = await wallet.getTransactionCost(txRequest, {
  quantities: [forwardQuantity],
});

txRequest.gasLimit = txCost.gasUsed;
txRequest.maxFee = txCost.maxFee;

await wallet.fund(txRequest, txCost);

const tx = await wallet.sendTransaction(txRequest);
const txResult = await tx.waitForResult();

We need to update our docs to give our users a clearer understanding of handling custom transaction workflows when forwarding amounts in contract calls.

@Torres-ssf Torres-ssf added the docs Requests pertinent to documentation label Dec 16, 2024
@Torres-ssf Torres-ssf self-assigned this Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Requests pertinent to documentation
Projects
None yet
Development

No branches or pull requests

1 participant