ChangeTrustOperation class

Creates, updates, or removes a trustline for an asset.

The ChangeTrust operation establishes a trustline between an account and an asset issuer, allowing the account to hold and transact with non-native assets. This is a fundamental operation for working with custom assets on the Stellar network.

Trustline Operations:

  • Create Trustline: Set limit to maximum value or specific amount
  • Update Trustline: Change the trust limit to a new value
  • Remove Trustline: Set limit to "0" (only works if balance is 0)

Trust Limit Behavior:

  • Maximum limit: "922337203685.4775807" (available as MAX_LIMIT constant)
  • Specific limit: Any positive decimal value (e.g., "1000.00")
  • Zero limit: "0" removes the trustline (requires zero balance)
  • Limit defines maximum asset amount the account can hold

Use Cases:

  • Enable account to receive custom assets
  • Establish trust relationship with asset issuer
  • Limit exposure to specific assets
  • Remove unwanted trustlines
  • Prepare account for asset trades

Example - Create Trustline with Maximum Limit:

// Create trustline for USD asset with maximum limit
var usdAsset = AssetTypeCreditAlphaNum4('USD', issuerAccountId);
var trustOp = ChangeTrustOperationBuilder(
  usdAsset,
  ChangeTrustOperationBuilder.MAX_LIMIT
).build();

var transaction = TransactionBuilder(sourceAccount)
  .addOperation(trustOp)
  .build();

Example - Create Trustline with Specific Limit:

// Create trustline with specific limit of 5000 USD
var trustOp = ChangeTrustOperationBuilder(
  usdAsset,
  '5000.00'
).build();

Example - Remove Trustline:

// Remove trustline (balance must be 0)
var removeTrustOp = ChangeTrustOperationBuilder(
  usdAsset,
  '0'
).build();

Example - Update Trust Limit:

// Increase trust limit to 10000 USD
var updateTrustOp = ChangeTrustOperationBuilder(
  usdAsset,
  '10000.00'
).build();

Important Considerations:

  • Account must have sufficient XLM balance for base reserve
  • Cannot remove trustline with non-zero balance
  • Issuer must have authorization flags properly configured
  • Trustlines for pool shares use liquidity pool IDs
  • Source account is the one creating the trustline

Authorization Requirements:

  • If issuer requires authorization (AUTH_REQUIRED), issuer must authorize trustline
  • Use SetTrustLineFlagsOperation for issuer to authorize trustlines
  • Unauthorized trustlines cannot receive assets

See also:

Represents ChangeTrust operation. See: Stellar developer docs

Inheritance

Constructors

ChangeTrustOperation(Asset _asset, String _limit)
Creates a ChangeTrustOperation.

Properties

asset Asset
The asset of the trustline.
no setter
hashCode int
The hash code for this object.
no setterinherited
limit String
The limit of the trustline.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sourceAccount MuxedAccount?
Optional source account for this operation.
getter/setter pairinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toOperationBody() XdrOperationBody
Converts this operation to its XDR OperationBody representation.
override
toString() String
A string representation of this object.
inherited
toXdr() XdrOperation
Converts this operation to its XDR representation.
inherited
toXdrBase64() String
Returns base64-encoded Operation XDR object from this operation.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

builder(XdrChangeTrustOp op) ChangeTrustOperationBuilder
Builds ChangeTrust operation from XDR operation.