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
- HASH: 32-byte hash (e.g., for hash preimages)
- RETURN: 32-byte hash for return payments
Tags
Table of Contents
Constants
- MEMO_TYPE_HASH = 3
- MEMO_TYPE_ID = 2
- MEMO_TYPE_NONE = 0
- MEMO_TYPE_RETURN = 4
- MEMO_TYPE_TEXT = 1
Methods
- __construct() : mixed
- Memo constructor
- fromXdr() : Memo
- Creates a Memo from XDR format
- 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
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
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
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
Return values
Memo —A memo of type HASH
id()
Creates an ID memo
public
static id(int $id) : Memo
Parameters
- $id : int
-
The unsigned 64-bit integer value
Tags
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
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
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
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 string representation of the int value. If the memo typ is 'none', it returns null.