algorandfoundation / algokit-utils-ts

MIT License
19 stars 8 forks source link

Populate Resources of a method call and return transactions array #271

Closed webdevalgo closed 7 months ago

webdevalgo commented 7 months ago

Problem

Currently calling a method on client generate just sends transactions to the blockchain but there can be cases where it would be very useful to call two or many methods on that client in same txn group.

For example: Trying to call client.approve() and client.sell(), has to be in two different txn groups.

Solution

We can add an option to method calls so it returns array of txns instead of sending it to the blockchain.

const approveTxns = await client.approve(...args,{ returnTxns: true });
const sellTxns = await client.sell(...sellArgs,{ returnTxns: true });
const allTxns = [...aproveTxns, ...sellTxns];
for(const txn of allTxns){
    txn.group = undefined;
}
algosdk.assignGroup(allTxns);
algod.sendTransactions(allTxns);
joe-p commented 7 months ago

Currently you can pass the ATC to populateAppCallResources which will return a new ATC with the same tx group + references. I agree though that it would be nice to have a way to do this automatically.

https://github.com/algorandfoundation/algokit-utils-ts/blob/0e4562431dfce5f5e0e9a2339cd365932c6d3335/src/transaction/transaction.ts#L288

robdmoore commented 7 months ago

You can also use .compose to compose multiple calls together into one atomic group :)

webdevalgo commented 7 months ago

Getting this error with populateAppCallResources()

Box ref with appId xxxxxx not in foreign-apps