GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add `stellar token burn` command by fnando · Pull Request #2744 · stellar/stellar-cli

Add stellar token burn command #2744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
fnando merged 1 commit into main from token-burn
Sep 23, 2026
+359 −0
Merged

Add stellar token burn command #2744

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
e19ee6a
Add `stellar token burn` command.
fnando Sep 22, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

40 changes: 40 additions & 0 deletions 40 FULL_HELP_DOCS.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,7 @@ Interact with SEP-41 tokens and Stellar Asset Contracts

- `transfer` — Transfer tokens from one account to another
- `transfer-from` — Transfer tokens on an owner's behalf using a granted allowance
- `burn` — Burn tokens from an account, destroying them
- `balance` — Read the token balance of an account or contract
- `name` — Read the token's name (SEP-41 metadata)
- `symbol` — Read the token's symbol (SEP-41 metadata)
Expand Down Expand Up @@ -2035,6 +2036,45 @@ Transfer tokens on an owner's behalf using a granted allowance
- `--sign-with-ledger` — Sign with a ledger wallet
- `--auto-sign` — Sign without prompting for approval. Only applies to signatures that require user approval, like non-root Soroban auth entries

## `stellar token burn`

Burn tokens from an account, destroying them

**Usage:** `stellar token burn [OPTIONS] --id <ID> --from <FROM> --amount <AMOUNT>`

###### **Global Options:**

- `--config-dir <CONFIG_DIR>` — Location of config directory. By default, it uses `$XDG_CONFIG_HOME/stellar` if set, falling back to `~/.config/stellar` otherwise. Contains configuration files, aliases, and other persistent settings

###### **Options:**

- `--id <ID>` — The token to burn: a contract id or alias, `native`, or a classic asset as `CODE:ISSUER`
- `--from <FROM>` — Account whose tokens are destroyed. Signs and authorizes the burn, so it must be an identity or secret key you control
- `--amount <AMOUNT>` — Amount to burn, in the token's smallest unit (stroops for a Stellar Asset Contract)
- `--output <OUTPUT>` — Format of the output

Default value: `text`

Possible values:
- `text`: Human-readable text
- `json`: Compact, single-line JSON output
- `json-formatted`: Formatted (multiline) JSON output

###### **RPC Options:**

- `--rpc-url <RPC_URL>` — RPC server endpoint
- `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider, example: "X-API-Key: abc123". Multiple headers can be added by passing the option multiple times
- `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
- `-n`, `--network <NETWORK>` — Name of network to use from config

###### **Signing Options:**

- `--sign-with-key <SIGN_WITH_KEY>` — Sign with a local key or key saved in OS secure storage. Can be an identity (--sign-with-key alice), a secret key (--sign-with-key SC36…), or a seed phrase (--sign-with-key "kite urban…"). If using seed phrase, `--hd-path` defaults to the `0` path
- `--hd-path <HD_PATH>` — If using a seed phrase to sign, sets which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0`
- `--sign-with-lab` — Sign with https://lab.stellar.org
- `--sign-with-ledger` — Sign with a ledger wallet
- `--auto-sign` — Sign without prompting for approval. Only applies to signatures that require user approval, like non-root Soroban auth entries

## `stellar token balance`

Read the token balance of an account or contract
Expand Down
112 changes: 112 additions & 0 deletions 112 cmd/crates/soroban-test/tests/it/integration/token/burn.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
use serde_json::Value;
use soroban_test::{AssertExt, TestEnv};

use crate::integration::{
token::{add_trustline, deploy_sac, issuer_pays, sac_balance, sac_id},
util::{new_account, test_address},
};

#[tokio::test]
async fn burn_destroys_funds() {
let sandbox = &TestEnv::new();
let test = test_address(sandbox);
let issuer = new_account(sandbox, "issuer");
let asset = format!("USDC:{issuer}");

// Burn is invalid on the native asset, so use an issued asset: the holder
// (`test`) needs a trustline and a balance from the issuer to have something
// to destroy.
add_trustline(sandbox, "test", &asset);
issuer_pays(sandbox, "issuer", &test, &asset, 1_000);
deploy_sac(sandbox, &asset, "issuer");
let contract_id = sac_id(sandbox, &asset);

let amount: i128 = 400;
let before = sac_balance(sandbox, &contract_id, &test);

// `test` signs, destroying its own tokens.
let stdout = sandbox
.new_assert_cmd("token")
.args([
"burn",
"--id",
&asset,
"--from",
"test",
"--amount",
&amount.to_string(),
"--output",
"json",
])
.assert()
.success()
.stdout_as_str();
let receipt: Value = serde_json::from_str(&stdout).unwrap();
assert!(
receipt["tx_hash"].as_str().is_some_and(|h| !h.is_empty()),
"expected a non-empty tx_hash, got: {receipt}"
);

let after = sac_balance(sandbox, &contract_id, &test);
assert_eq!(after, before - amount, "balance should decrease by amount");
}

#[tokio::test]
async fn burn_fails_when_sac_not_deployed() {
let sandbox = &TestEnv::new();
let issuer = new_account(sandbox, "issuer");
let asset = format!("USDC:{issuer}");

// No SAC deployed → structured deploy-pointer error with a typed discriminator.
let stdout = sandbox
.new_assert_cmd("token")
.args([
"burn", "--id", &asset, "--from", &issuer, "--amount", "1", "--output", "json",
])
.assert()
.failure()
.stdout_as_str();
let value: Value = serde_json::from_str(&stdout).unwrap();
assert_eq!(
value["error"]["type"], "sac_not_deployed",
"expected a typed error, got: {stdout}"
);
}

#[tokio::test]
async fn burn_rejects_muxed_from_with_clear_error() {
let sandbox = &TestEnv::new();

// Muxed (M…) source accounts aren't supported by the invoke pipeline yet
// (see #2645). The signer here is `--from`, so the guard must name it.
let muxed = "MA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAAAAAAAAAPCICBKU";
sandbox
.new_assert_cmd("token")
.args(["burn", "--id", "native", "--from", muxed, "--amount", "1"])
.assert()
.failure()
.stderr(predicates::str::contains(
"muxed (M…) source accounts are not yet supported",
));
}

#[tokio::test]
async fn burn_rejects_negative_amount_before_any_rpc() {
let sandbox = &TestEnv::new();

// A negative amount is rejected at the clap layer, before any network call.
sandbox
.new_assert_cmd("token")
.args([
"burn",
"--id",
"native",
"--from",
"test",
// `=` form so clap reads `-1` as the value, not an unknown flag.
"--amount=-1",
])
.assert()
.failure()
.stderr(predicates::str::contains("amount must not be negative"));
}
1 change: 1 addition & 0 deletions 1 cmd/crates/soroban-test/tests/it/integration/token/mod.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod allowance;
pub mod approve;
pub mod balance;
pub mod burn;
pub mod decimals;
pub mod name;
pub mod renamed;
Expand Down
1 change: 1 addition & 0 deletions 1 cmd/soroban-cli/src/cli.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ fn json_error_format(cmd: &commands::Cmd) -> Option<crate::output::Format> {
commands::Cmd::Network(network::Cmd::Settings(cmd)) => cmd.output.into(),
commands::Cmd::Token(token::Cmd::Transfer(cmd)) => cmd.output.into(),
commands::Cmd::Token(token::Cmd::TransferFrom(cmd)) => cmd.output.into(),
commands::Cmd::Token(token::Cmd::Burn(cmd)) => cmd.output.into(),
commands::Cmd::Token(token::Cmd::Balance(cmd)) => cmd.output.into(),
commands::Cmd::Token(token::Cmd::Name(cmd)) => cmd.output.into(),
commands::Cmd::Token(token::Cmd::Symbol(cmd)) => cmd.output.into(),
Expand Down
197 changes: 197 additions & 0 deletions 197 cmd/soroban-cli/src/commands/token/burn.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
use clap::Parser;

use crate::{
commands::{
contract::invoke,
global,
token::args::{self, OutputFormat},
},
config::{self, locator, network, sign_with, token::UnresolvedToken, UnresolvedMuxedAccount},
output::Output,
};

#[derive(Debug, Parser, Clone)]
#[group(skip)]
pub struct Cmd {
/// The token to burn: a contract id or alias, `native`, or a classic asset
/// as `CODE:ISSUER`.
#[arg(long = "id")]
pub id: UnresolvedToken,

/// Account whose tokens are destroyed. Signs and authorizes the burn, so it
/// must be an identity or secret key you control.
#[arg(long)]
pub from: UnresolvedMuxedAccount,

/// Amount to burn, in the token's smallest unit (stroops for a Stellar Asset
/// Contract).
#[arg(long, value_parser = parse_nonneg_i128)]
pub amount: i128,

/// Format of the output.
#[arg(long, default_value = "text")]
pub output: OutputFormat,

#[command(flatten)]
pub network: network::Args,

#[command(flatten)]
pub locator: locator::Args,

#[command(flatten)]
pub sign_with: sign_with::Args,
}

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Config(#[from] config::Error),
#[error(transparent)]
Network(#[from] network::Error),
#[error(transparent)]
Args(#[from] args::Error),
#[error(transparent)]
Token(#[from] config::token::Error),
#[error(transparent)]
Invoke(#[from] invoke::Error),
#[error(transparent)]
Serde(#[from] serde_json::Error),

#[error(
"muxed (M…) source accounts are not yet supported for `token burn`; \
use the underlying G… account as `--from` instead"
)]
MuxedSourceNotSupported,
}

/// Parse `--amount` as a non-negative `i128`. A negative burn amount is always
/// invalid, so reject it at the clap layer instead of letting it reach the
/// contract and fail as an opaque `HostError` deep in simulation.
fn parse_nonneg_i128(value: &str) -> Result<i128, String> {
let amount: i128 = value
.parse()
.map_err(|_| format!("invalid amount: {value}"))?;
if amount < 0 {
return Err(format!("amount must not be negative: {value}"));
}
Ok(amount)
}

impl Error {
/// Machine-readable discriminator for the JSON error envelope's `type` field.
#[must_use]
pub fn error_type(&self) -> &'static str {
match self {
Error::Config(_) => "config",
Error::Network(_) => "network",
Error::Args(e) => e.error_type(),
Error::Token(e) => e.error_type(),
Error::Invoke(_) => "invoke",
Error::Serde(_) => "internal",
Error::MuxedSourceNotSupported => "unsupported",
}
}
}

/// The machine-readable result of a token burn.
#[derive(Debug, serde::Serialize)]
struct BurnResult {
/// Hex-encoded hash of the submitted transaction.
tx_hash: Option<String>,
/// The decoded contract return value (`null` for SEP-41 `burn`, which
/// returns nothing).
result: serde_json::Value,
}

impl Cmd {
/// Assemble a full [`config::Args`] for the underlying invocation, using
/// `--from` as the source account that signs and authorizes the burn. Fees
/// are left unset so the pipeline applies its default inclusion fee — this
/// command intentionally exposes no fee or sequence knobs.
fn config(&self) -> config::Args {
config::Args {
network: self.network.clone(),
source_account: self.from.clone(),
locator: self.locator.clone(),
sign_with: self.sign_with.clone(),
fee: None,
inclusion_fee: None,
}
}

pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
let output = Output::new(self.output.into(), global_args.quiet);
// In JSON mode the underlying invoke pipeline's human-readable status
// logging (which writes to stderr) would still fire; run it quietly so
// machine consumers get clean output without needing `--quiet`.
let quiet = global_args.quiet || output.is_json();
let config = self.config();
let network = config.get_network()?;

let token = self
.id
.resolve(&config.locator, &network.network_passphrase)?;

// SEP-41 `burn(from, amount)`: `from` is the source account (which also
// signs and authorizes), whose tokens are destroyed.
//
// The invoke pipeline can't source a transaction from a muxed account
// yet (see #2645), and a muxed strkey in the `burn` arg is rejected
// mid-simulation with an opaque host error; reject it up front with a
// clear message instead.
let source_account = config.source_account()?;
if matches!(source_account, crate::xdr::MuxedAccount::MuxedEd25519(_)) {
return Err(Error::MuxedSourceNotSupported);
}
let from = source_account.to_string();
let amount = self.amount.to_string();

// SEP-41 `burn(from, amount)` — supply the values in that order and let
// the contract's parameters be matched by position, so a token that
// names them anything still works. A burn always intends to submit, so
// force `Send::Yes`: a token whose `burn` records no writes/events/auth
// can't be classified read-only and silently exit 0 without ever
// destroying funds.
let invoke_result = args::invoke_by_position(
&config,
quiet,
global_args.no_cache,
&token,
"burn",
vec![from, amount],
invoke::Send::Yes,
)
.await
.map_err(|e| args::not_deployed_error(&token, &e).map_or(Error::Invoke(e), Error::Args))?
.into_result();

// `burn` always writes, so the invocation is submitted rather than
// resolved as a build-only transaction; a missing result would mean
// `--build-only`, which this command never sets.
let Some(invoke_result) = invoke_result else {
return Ok(());
};

let result = if invoke_result.output.is_empty() {
serde_json::Value::Null
} else {
serde_json::from_str(&invoke_result.output)
.unwrap_or(serde_json::Value::String(invoke_result.output.clone()))
};

// The pipeline already logs submission status and the explorer link to
// stderr; echo the hash to stdout so readable output is scriptable too.
if !output.is_json() {
if let Some(tx_hash) = &invoke_result.tx_hash {
println!("{tx_hash}");
}
}

output.json_value(&BurnResult {
tx_hash: invoke_result.tx_hash,
result,
})?;

Ok(())
}
}
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.