Stellar PHP SDK API Documentation

Memo
in package

Represents a transaction memo in the Stellar network

Memos are optional messages attached to transactions. They can be used to attach additional information such as payment references, invoice numbers, or other application-specific data.

Supported memo types:

  • NONE: No memo (default)
  • TEXT: UTF-8 text string up to 28 bytes
  • ID: Unsigned 64-bit integer (values above PHP_INT_MAX are represented as decimal strings)
  • HASH: 32-byte hash (e.g., for hash preimages)
  • RETURN: 32-byte hash for return payments
Tags
see
https://developers.stellar.org

Stellar developer docs Documentation on memos

Table of Contents

Constants

MEMO_TYPE_HASH  : mixed = 3
MEMO_TYPE_ID  : mixed = 2
MEMO_TYPE_NONE  : mixed = 0
MEMO_TYPE_RETURN  : mixed = 4
MEMO_TYPE_TEXT  : mixed = 1

Methods

__construct()  : mixed
Memo constructor
fromXdr()  : Memo
Creates a Memo from XDR format
getIdAsString()  : string|null
Gets the id memo value as an unsigned decimal string
getType()  : int
Gets the memo type
getValue()  : mixed
Gets the memo value
hash()  : Memo
Creates a hash memo
id()  : Memo
Creates an ID memo
none()  : Memo
Creates a memo with no value
return()  : Memo
Creates a return hash memo
text()  : Memo
Creates a text memo
toXdr()  : XdrMemo
Converts this memo to XDR format
typeAsString()  : string
Returns the type of this memo as a string.
validate()  : void
Validates the memo value against its type constraints
valueAsString()  : string|null
Returns the value of this memo as a string. It this memo has no value it returns null.

Constants

MEMO_TYPE_HASH

public mixed MEMO_TYPE_HASH = 3

MEMO_TYPE_ID

public mixed MEMO_TYPE_ID = 2

MEMO_TYPE_NONE

public mixed MEMO_TYPE_NONE = 0

MEMO_TYPE_RETURN

public mixed MEMO_TYPE_RETURN = 4

MEMO_TYPE_TEXT

public mixed MEMO_TYPE_TEXT = 1

Methods

__construct()

Memo constructor

public __construct(int $type[, mixed|null $value = null ]) : mixed
Parameters
$type : int

The memo type (use MEMO_TYPE_* constants)

$value : mixed|null = null

The memo value (type depends on memo type)

Tags
throws
InvalidArgumentException

If the value is invalid for the specified type

fromXdr()

Creates a Memo from XDR format

public static fromXdr(XdrMemo $xdr) : Memo
Parameters
$xdr : XdrMemo

The XDR encoded memo

Return values
Memo

The decoded memo object

getIdAsString()

Gets the id memo value as an unsigned decimal string

public getIdAsString() : string|null
Return values
string|null

The id as a decimal string, or null if this memo is not of type ID

getType()

Gets the memo type

public getType() : int
Return values
int

The memo type (one of MEMO_TYPE_* constants)

getValue()

Gets the memo value

public getValue() : mixed

For id memos the value is an int, or an unsigned decimal string when the id is above PHP_INT_MAX. Use getIdAsString() for a uniform representation.

Return values
mixed

The memo value (type depends on memo type)

hash()

Creates a hash memo

public static hash(string $hash) : Memo
Parameters
$hash : string

The 32-byte hash value

Tags
throws
InvalidArgumentException

If hash is not exactly 32 bytes

Return values
Memo

A memo of type HASH

id()

Creates an ID memo

public static id(int|string $id) : Memo

The id is an unsigned 64-bit integer. Values above PHP_INT_MAX must be passed as a decimal string.

Parameters
$id : int|string

The id as a non-negative int or unsigned decimal string

Tags
throws
InvalidArgumentException

If the id is negative, not a decimal string, or exceeds 2^64-1

Return values
Memo

A memo of type ID

none()

Creates a memo with no value

public static none() : Memo
Return values
Memo

A memo of type NONE

return()

Creates a return hash memo

public static return(string $hash) : Memo
Parameters
$hash : string

The 32-byte hash value for return payments

Tags
throws
InvalidArgumentException

If hash is not exactly 32 bytes

Return values
Memo

A memo of type RETURN

text()

Creates a text memo

public static text(string $text) : Memo
Parameters
$text : string

The text value (maximum 28 bytes UTF-8)

Tags
throws
InvalidArgumentException

If text exceeds 28 bytes

Return values
Memo

A memo of type TEXT

toXdr()

Converts this memo to XDR format

public toXdr() : XdrMemo
Return values
XdrMemo

The XDR representation of this memo

typeAsString()

Returns the type of this memo as a string.

public typeAsString() : string

Possible values are 'id', 'text', 'hash', 'none' and 'return'.

Return values
string

type of this memo as a string.

validate()

Validates the memo value against its type constraints

public validate() : void
Tags
throws
InvalidArgumentException

If the value is invalid for the memo type

valueAsString()

Returns the value of this memo as a string. It this memo has no value it returns null.

public valueAsString() : string|null
Return values
string|null

the value of this memo as a string if any. If the memo type is 'return' or 'hash' it returns a base 64 encoded string of the memo value. If the memo type is 'text' it just returns the value. If the memo type is 'id' it returns the unsigned decimal string representation of the id. If the memo type is 'none', it returns null.

On this page

Search results