I am getting the error when using @emurgo\cardano-serialization-lib-asmjs
txBuilder.add_change_if_needed(shelleyChangeAddress)
throws an exception Not enough ADA leftover to include non-ADA assets in a change address
I am getting the error when using @emurgo\cardano-serialization-lib-asmjs
txBuilder.add_change_if_needed(shelleyChangeAddress)
throws an exception Not enough ADA leftover to include non-ADA assets in a change address
Comment converted into answer:
I'm not familiar with that code, but in general moving native assets needs to go along with some ADA eg 1 or 2 ADA. Does your input UTxO have enough ADA balance to cover everything eg fees and output ADA? If not then you can add a second input UTxO that has more ADA into the transaction.
(1) Make sure you have enough ADA in your wallet that can be used to pay for transaction fees. Transaction fees are increasing the more native assets you add to the transaction.
(2) If you use add_change_if_needed
make sure to add enough inputs before calling this method that can cover the transaction fees.
(3) If you hardcode your input UTxO like you probably did with 278ad827cb923ed800fcb2028114ee8e9bca875059e1389ca1f49755c1c9a629
then running your code multiple time with of course fail, because you've consumed the unspent output with your first execution. Any second try won't be able to spend this output again, since it's already been spent.
You will need to update your code manually or write some logic to select the new UTxO.