Skip to main content

tx op add

As seen before you can use pipes to pass a transaction envelope between commands. Before we have only been looking at transactions with one operation, however, as mentioned there can be up to 100 operations in a single transaction.

To add an operation to a transaction you can use the tx op add command. This command takes the transaction envolope from the previous command and adds an operation to it.

Let's consider a more complicated example. Consider issuing an asset, here USDC with the requirement that only the issuer can transfer funds to the distrubtor.


stellar keys generate --fund issuer
stellar keys generate --fund distributor

ISSUER_PK=$(stellar keys address issuer)

ASSET="USDC:$ISSUER_PK"

# Issue the asset by setting its options, establishing a trustline, and
# transferring the smallest amount possible to the distributor. Then
# deauthorize the distributor so that people can only send Claimable Balances,
# rather than transferring assets directly.

# first the issuer sets the options for being able to clawback and revoke the asset
stellar tx new set-options --fee 1000 --source issuer --set-clawback-enabled --set-revocable --build-only \
# next the distributor establishes a trustline with the asset. Note that here the distributor the source account for the operation, not the issuer
| stellar tx op add change-trust --op-source distributor --line $ASSET \
# then the issuer sends the smallest amount possible to the distributor
| stellar tx op add payment --destination distributor --asset $ASSET --amount 1 \
# finally the issuer deauthorizes the distributor from being able to send the asset
| stellar tx op add set-trustline-flags --asset $ASSET --trustor distributor --clear-authorize \
# Then both accounts need to sign the transaction
| stellar tx sign --sign-with-key issuer \
| stellar tx sign --sign-with-key distributor \
| stellar tx send

# Next is an example of sandwiching an operation. That is giving permission in one operation, preforming the operation, and then removing the permission in a third operation.
# Here is an example of minting new assets to the distributor with a sandwich transaction
# First authorize the distributor to receive the asset
stellar tx new set-trustline-flags --fee 1000 --build-only --source issuer --asset $ASSET --trustor $distributor_PK --set-authorize \
# Then mint the asset to the distributor
| stellar tx op add payment --destination distributor --asset $ASSET --amount 1_000_000_000_000 \
# Finally remove the authorization
| stellar tx op add set-trustline-flags --asset $ASSET --trustor distributor --clear-authorize \
| stellar tx sign --sign-with-key issuer \
| stellar tx send

Guides in this category: