Issues sending tokens, help understanding

Hi All,
I have an address with some tokens in it, This address is not connected to a wallet, i only have the .vkey/.skey and payment.addr available, and access to a node. I would like to send them to another address

Im following the below to build the tx:

cardano-cli transaction build-raw \
    --fee <fee> \
    --tx-in <tx_in> \
    --tx-out <your_address>+<change> \
    --tx-out <destination_address>+<minUtxO>+10000 <Tokens> \
    --out-file <outputfile.raw>

The question is, do i need to include all the list of tokens that will not be sent in with my --tx-out <your_address>+ . i.e., say i only want to send token X, and my address has one of each token(s), X, Y, Z. Do i need to say:

--tx-out <destination_address>+<minUtxO>+10000 + "1 <policy for token X>.X+"\
--tx-out <original_address>+<ADA_value>+"0 <policy for token X>.X+"1 <policy for token Y>.Y+"1 <policy for token Z>.Z" \

that is, do i need to list all the tokens and policies and amounts that will not change?

Ive tried both methods of listing them all out, and only listing the one that will change, and im getting a hell of a mess with an error output on submissions:

Command failed: transaction submit  Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (OutputTooSmallUTxO [(Addr Mainnet (KeyHashObj (KeyHash "7b728f5a7cafe611706572bf27205868eda929e674ed3ef261505866")) (StakeRefBase (KeyHashObj (KeyHash "e016ca7de1a5402d4813d1efc5ba621c3756ec1019994a35404dd303"))),Value 1000000 (fromList [(PolicyID {policyID = ScriptHash "b788fbee71a32d2efc5ee7d151f3917d99160f78fb1e41a1bbf80d8f"},fromList [("LEAFTOKEN",70985035)])]),SNothing)]))),UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (ValueNotConservedUTxO (Value 24274166 (fromList [(PolicyID {policyID = ScriptHash "544571c086d0e5c5022aca9717dd0f438e21190abb48f37b3ae129f0"},fromList [("GROW",1)]),(PolicyID {policyID = ScriptHash "8654e8b350e298c80d2451beb5ed80fc9eee9f38ce6b039fb8706bc3"},fromList [("LOBSTER",1000000)]),(PolicyID {policyID = ScriptHash "a0028f350aaabe0545fdcb56b039bfb08e4bb4d8c4d7c3c7d481c235"},fromList [("HOSKY",1000000)]),(PolicyID {policyID = ScriptHash "af2e27f580f7f08e93190a81f72462f153026d06450924726645891b"},fromList [("DRIP",1000000000)]),(PolicyID {policyID = ScriptHash "b788fbee71a32d2efc5ee7d151f3917d99160f78fb1e41a1bbf80d8f"},fromList [("LEAFTOKEN",70985035)]),(PolicyID {policyID = ScriptHash "d030b626219d81673bd32932d2245e0c71ae5193281f971022b23a78"},fromList [("Cardogeo",420)]),(PolicyID {policyID = ScriptHash "d3558649b7874a1a596378515f9b80da63e73f324439ea113d34c9bb"},fromList [("BEAG",25)])])) (Value 24274166 (fromList [(PolicyID {policyID = ScriptHash "b788fbee71a32d2efc5ee7d151f3917d99160f78fb1e41a1bbf80d8f"},fromList [("LEAFTOKEN",70985035)])])))))])

that is, do i need to list all the tokens and policies and amounts that will not change?

Yes. Everything left over that you are not sending to your destination needs to go back to your originator (sender) address. This is the essence of UTXO.

Took me a little bit to wrap my head around this, but once you fail and few and then do it right, it’ll click.

what i try to do all the time to make it better is what…
all the tx-out should have in summary all the ADA and tokens you hold currently in your TxHash.

and remember, if you have now 2 or more TxHash, then you have to use all of them as tx-in


@Equivertex Hi, thanks for the comment. Yes i just figured it out. Looks like there was some issue with my build transaction layout. You are correct, everything needs to be accounted for… a bit tedious by hand, but makes sense. :slight_smile:

I don’t know, why everybody is still using build-raw.

With build, you do not have to calculate a fee by hand (so, you also don’t need to download protocol parameters and don’r need to do it twice).

You give a --change-address, where everything not accounted for in --tx-outs goes. So, no calculation what that rest is is necessary.

It should even be possible to not give any --tx-out and just send all --tx-ins to the --change-address without giving any concrete amounts at all.

EDIT: Or for your concrete use case:

cardano-cli transaction build \
    --tx-in <tx_in> \
    --tx-out <destination_address>+<minUTxO>+10000\ <Tokens> \
    --change-address <your_address> \
    --out-file <outputfile.raw>

will work without calculating anything. If you give 0 for <minUTxO> on the first run, it will tell you, what it has to be.


Before I moved on to doing this all in code, I had a lot of scratch text files opened where I would cut and paste everything I did in order to try to figure all this out. Got pretty good at spotting errors like ‘ValueNotConservedUTxO’, etc. :slight_smile: I think it’s valuable to do these low level exercises because, at least for me, they translated well once I got a little higher on the abstraction chain. Glad you figured it out.

you give the TX-out, and the rest (without the fee) goes to --change-address? :slight_smile:
if yes, that is amazing.

please verify my understanding to your point, and then i send you great positive vibes for the new week :slight_smile:
thank you mate,
TTS17 operator

Yes. Works for me.

You can just compare Minting Native Assets | Cardano Developer Portal, where they use build-raw, have to download the protocol parameters, do the calculate-min-fee, balance the transaction, … and Minting NFTs | Cardano Developer Portal, where they use build and don’t do all that stuff (they still download the protocol parameters, but do not use them afterwards, and there’s a echo $fee without that variable ever being set or used).

That’s not a difference between NFTs and other native tokens. (Why should it be?) That’s the documentation not being updated for the native tokens, but for the NFTs (although very sloppily).

1 Like

perfect mate,
i never mentioned this parameter,

tomorrow i will go and test it for different cases and i will update my first script :slight_smile:
if you like to read it and give me a feedback, would be great to listen ideas for development.

thank you , and have a great day

1 Like

Hi @HeptaSean
I cannot get transaction-build to work at all, given it the --tx-outs in the correct format i always get the error “Invalid option” and it throws back at me the entire tx-out line.

or if i make a simple test

--tx-out <address>+1500000+25 d3558649b7874a1a596378515f9b80da63e73f324439ea113d34c9bb.42454147 

i get back:

Invalid option `--tx-out <address>+1500000+25 d3558649b7874a1a596378515f9b80da63e73f324439ea113d34c9bb.42454147'

what’s going on with this… it makes no sense

ok now i just get the error:

Invalid argument `d3558649b7874a1a596378515f9b80da63e73f324439ea113d34c9bb.42454147'

Okay, sorry if that was not clear, but <address> should mean that you replace it with the concrete address you want to send to.

The other error is: cardano-cli wants to get the tx-out input as two elements, the --tx-out option and addr...+2000000+10000 12345678901234567890.1234567. This contains a space. So your shell would normally split this up and then cardano-cli does not know what to do with 12345678901234567890.1234567.

That is why guides either enclose such arguments containing spaces with ", so that the shell does not split up at the space, or they “escape” the space with a backslash before it, which is what I have done in the above post.

hi @HeptaSean

correct me if im wrong, but doesn’t there need to be space between the asset <amount> and the policy

I actually think im running into a fussy bash or command line issue pipe through to cardano-cli where its not liking the ‘.’ in between 12345678901234567890.1234567, im not exactly sure what im going wrong but for example, if i write the bash script so that :

TX_OUTS="--tx-out <address>+1500000+25 d3558649b7874a1a596378515f9b80da63e73f324439ea113d34c9bb.42454147

and give cardano-cli the $TX_OUTS it throws the error.

however if it write it up like this:

# TK1_a=25
# TK1_p=d3558649b7874a1a596378515f9b80da63e73f324439ea113d34c9bb
# TK1_n=42454147
# TK1=$TK1_a" "$TK1_p.$TK1_n
TX_OUTS=("--tx-out <address>+1500000+"$TK1)

then its happy with that

Ahhh i see what you mean now, shell is splitting up the line with the ' ' that im putting in. In bash this is taken care of, but when i give bash a plain text string its not escaping it.

Thanks for that :slight_smile:

Yes, of course.

That’s why I have it in

escaped by the backslash.

If you give it to a variable, it’s sometimes a bit complicated to keep track of which space is escaped on which level.

We also had a quite similar and detailed discussion here:

awesome! thanks so much for your help on this one :slight_smile: