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 --inclusion-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 --inclusion-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:
📄️ Asset Management
Issue a Stellar Asset, deploy it's contract, and mint, burn, freeze, and clawback.
📄️ Add meta data to contract WASM on build
Include meta data in the contract WASM byte code on build
📄️ Contract Lifecycle
Manage the lifecycle of a Stellar smart contract using the CLI
📄️ Deploy a contract from uploaded Wasm bytecode
Deploy an instance of a compiled contract that has already been uploaded on the network
📄️ Deploy the Stellar Asset Contract for a Stellar asset
Deploy an SAC for a Stellar asset so that it can interact with smart contracts
📄️ Extend a deployed contract instance's TTL
Use the CLI to extend the time to live (TTL) of a contract instance
📄️ Extend a deployed contract's storage entry TTL
Use the CLI to extend the time to live (TTL) of a contract's persistent storage entry
📄️ Extend a deployed contract's Wasm code TTL
Use Stellar CLI to extend contract's Wasm bytecode TTL, with or without local binary
📄️ Payments and Assets
Send XLM, stellar classic, or a soroban asset using the Stellar CLI
📄️ Restore an archived contract using the Stellar CLI
Restore an archived contract instance using the Stellar CLI
📄️ Restore archived contract data using the Stellar CLI
Restore archived contract storage entries using Stellar CLI
📄️ Stellar Keys
Manage stellar keys
📄️ Create Claimable Balance
Create claimable balances with various claim predicates using the Stellar CLI
📄️ tx Commands
Create stellar transactions using the Stellar CLI
📄️ tx op add
Create stellar transactions using the Stellar CLI
📄️ tx sign and tx send
Create stellar transactions using the Stellar CLI
📄️ Upload and deploy a smart contract
Combine the upload and deploy commands in the Stellar CLI to accomplish both tasks
📄️ Upload Wasm bytecode
Use the Stellar CLI to upload a compiled smart contract on the ledger