cardano-client-lib icon indicating copy to clipboard operation
cardano-client-lib copied to clipboard

Support for multiple outputs on transactions

Open bkreiser opened this issue 3 years ago • 5 comments

Nice library BTW. It would be nice to have support for multiple outputs on a TX. Currently you can only send lovelace or native assets to a single address per TX.

bkreiser avatar Dec 03 '21 16:12 bkreiser

Currently, there are two options to perform a transaction with multiple receivers.

1. Using PaymentTransaction high level api

You can call TransactionHelperService.transfer() with a list of PaymentTransaction. All these transactions will be part of one transaction in blockchain. You need to calculate total fee for all PaymentTransactions. There is a method in FeeCalculationService for that. But you need to set the total estimated fee as fee in only one of the PaymentTransaction.

You can check these tests: One sender multiple receivers : - https://github.com/bloxbean/cardano-client-lib/blob/9ed78f8fc11a63dcbb604664801ecd0fe98866d9/src/integration-test/java/com/bloxbean/cardano/client/backend/api/helper/TransactionHelperServiceIT.java#L268

Multiple senders multiple receivers : - https://github.com/bloxbean/cardano-client-lib/blob/9ed78f8fc11a63dcbb604664801ecd0fe98866d9/src/integration-test/java/com/bloxbean/cardano/client/backend/api/helper/TransactionHelperServiceIT.java#L207

2. Using lowlevel api But if you want more control, you can use lowlevel serialization apis like Transaction, TransactionBody etc.

Hope this helps.

satran004 avatar Dec 04 '21 12:12 satran004

It does; thank you!

On Sat, Dec 4, 2021 at 5:11 AM Satya @.***> wrote:

Currently, there are two options to perform a transaction with multiple receivers.

1. Using PaymentTransaction high level api

You can call TransactionHelperService.transfer() with a list of PaymentTransaction. All these transactions will be part of one transaction in blockchain. You need to calculate total fee for all PaymentTransactions. There is a method in FeeCalculationService for that. But you need to set the total estimated fee as fee in only one of the PaymentTransaction.

Check these tests: One sender multiple receivers : - https://github.com/bloxbean/cardano-client-lib/blob/9ed78f8fc11a63dcbb604664801ecd0fe98866d9/src/integration-test/java/com/bloxbean/cardano/client/backend/api/helper/TransactionHelperServiceIT.java#L268

Multiple senders multiple receivers : - https://github.com/bloxbean/cardano-client-lib/blob/9ed78f8fc11a63dcbb604664801ecd0fe98866d9/src/integration-test/java/com/bloxbean/cardano/client/backend/api/helper/TransactionHelperServiceIT.java#L207

**2. Using lowlevel api ** But if you want more control, you can use lowlevel serialization apis like Transaction, TransactionBody etc.

Hope this helps.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bloxbean/cardano-client-lib/issues/38#issuecomment-986017387, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2AWHVS7KCYI4GK5GRZQF3UPIAN7ANCNFSM5JKEC2AQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

bkreiser avatar Dec 04 '21 16:12 bkreiser

for multiasset payments, it would be really helpful if PaymentTransaction allowed to specify the amount of LOVELACE (greater than protocol minimum, of course) in addition to the amount of tokens. currently, the token-related output will always get lovelace amounts based on network minimum parameters automatically.

Or putting it differently: the use case is to "...send X amount LOVELACE and Y amount of TOKEN_AAA to a receiver"

  • there is no way (?) to do this with the convenient higher level classes as a single output, TOKEN_AAA output will add min_lovelace LOVELACE amounts
  • the caller needs to create another PaymentTransaction for LOVELACE that is "X - min_lovelace"... which is really clumsy AND also does not look that great on the blockchain transaction (unnecessary output)... or might not be even possible, if X-min_lovelace is less than min_lovelace
  • i know this should be doable with lower-level APIs which have the notion of multiasset output - but isn't the whole point of this library to provide convenient simplifications? so true multiasset support in PaymentTransaction would be great

is there any chance this functionality would come later?

when looking at UtxoTransactionBuilderImpl.buildTransaction, this is not trivial to implement by a general programmer not familiar with all the intricacies of Cardano transactions...

the trick could perhaps be somewhere in aggregating outputs per receiver address - i.e. when multiple PaymentTransaction are for same sender, this would be "merged" into single, multiasset output with correct amounts, etc?

the-vj avatar Jan 10 '22 18:01 the-vj

@the-vj This PR is going to merge all payments towards the same address together https://github.com/bloxbean/cardano-client-lib/pull/59 . Thanks to @nemo83

For future release, we can also explore the option to support an array of tokens (Array<unit, amount>) in PaymentTransaction instead of a single unit/amount pair.
So, caller can provide what to expect in the outputs and library will handle the how part.

satran004 avatar Jan 11 '22 12:01 satran004

thanks for pointing out, this sounds really great - so glad i voted for this project in Catalyst :-)

ps: for now, i got around the problem simply by hacking the MinAdaCalculator source code - not proud of it, but as a 10-minute workaround with no need for real UTXO competence, it did the trick too :-P

the-vj avatar Jan 11 '22 16:01 the-vj