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:
ποΈ Contract Lifecycle
Manage the lifecycle of a Stellar smart contract using the CLI
ποΈ Deploy a contract from installed Wasm bytecode
Deploy an instance of a compiled contract that is already installed 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
ποΈ Install and deploy a smart contract
Combine the install and deploy commands in the Stellar CLI to accomplish both tasks
ποΈ Install Wasm bytecode
Use the Stellar CLI to install a compiled smart contract on the ledger
ποΈ 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
ποΈ 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