Skip to main content

Transactions

Transactions are atomic ledger updates that issue, transfer, and/or retire tokens in the ledger. A transaction is comprised of one or more actions.

All actions in a transaction occur simultaneously. Each action operates on tokens of a single flavor, but you can use multiple actions in a single transaction to atomically operate on multiple flavors.

  • Issue – The issue action issues new tokens into an account. It accepts a flavor id, an amount, and a destination account id. The transaction must be signed with the flavor's key(s).
  • Transfer – The transfer action transfers tokens from one account to another. It accepts a flavor id, an amount, a source account id, a destination account id, and an optional filter. The transaction must be signed with the source account's key(s).
  • Retire – The retire action retires tokens from an account. It accepts a flavor id, an amount, a source account id, and an optional filter. The transaction must be signed with the source account's key(s).

Data Structure

Field Descriptions

FieldTypeDescription
idstringCryptographic, globally unique identifier of the transaction.
timestampstringTime (in RFC3339 format) that the transaction was committed to the ledger.
sequence numberintegerAbsolute position in the ledger.
actionsarrayA sequential list of actions affecting the ledger in the transaction.
tagsJSON objectUser-specified key-value data about the transaction.

Example object

{
id: "",
sequenceNumber: 1,
timestamp: "",
actions: [
{
type: "issue",
flavorId: "",
amount: 1,
destinationAccountId: "",
tags: {}
},
{
type: "transfer",
flavorId: "",
amount: 1,
sourceAccountId: "",
sourceAccountTags: {},
destinationAccountId: "",
destinationAccountTags: {},
tags: {}
},
{
type: "retire",
flavorId: "",
amount: 1,
sourceAccountId: "",
sourceAccountTags: {},
tags: {}
}
],
tags: {}
}

Examples

Issue

Issue USD to Alice.

Transaction tx = new Transaction.Builder()
.addAction(new Transaction.Builder.Action.Issue()
.setFlavorId("usd")
.setAmount(100)
.setDestinationAccountId("alice")
).transact(ledger);

Transfer

Transfer USD from Alice to Bob.

Transaction tx = new Transaction.Builder()
.addAction(new Transaction.Builder.Action.Transfer()
.setFlavorId("usd")
.setAmount(10)
.setSourceAccountId("alice")
.setDestinationAccountId("bob")
).transact(ledger);

Retire

Retire USD from Bob.

Transaction tx = new Transaction.Builder()
.addAction(new Transaction.Builder.Action.Retire()
.setFlavorId("usd")
.setAmount(5)
.setSourceAccountId("bob")
).transact(ledger);

Multi-asset transfer

Transfer USD and EUR from Alice to Bob.

Transaction tx = new Transaction.Builder()
.addAction(new Transaction.Builder.Action.Transfer()
.setFlavorId("usd")
.setAmount(10)
.setSourceAccountId("alice")
.setDestinationAccountId("bob")
).addAction(new Transaction.Builder.Action.Transfer()
.setFlavorId("eur")
.setAmount(20)
.setSourceAccountId("alice")
.setDestinationAccountId("bob")
).transact(ledger);

Multi-account transfer

Transfer USD from Alice to Bob and transfer EUR from Bob to Carol.

Transaction tx = new Transaction.Builder()
.addAction(new Transaction.Builder.Action.Transfer()
.setFlavorId("usd")
.setAmount(10)
.setSourceAccountId("alice")
.setDestinationAccountId("bob")
).addAction(new Transaction.Builder.Action.Transfer()
.setFlavorId("eur")
.setAmount(20)
.setSourceAccountId("bob")
.setDestinationAccountId("carol")
).transact(ledger);

Add action tags

Add action tags to the issue action to denote the source of the deposit.

Transaction tx = new Transaction.Builder()
.addAction(new Transaction.Builder.Action.Issue()
.setFlavorId("usd")
.setAmount(100)
.setDestinationAccountId("alice")
.addActionTagsField("source", "wire")
).transact(ledger);

Add transaction tags

Add transaction tags to record store location and invoice number.

Transaction tx = new Transaction.Builder()
.addAction(new Transaction.Builder.Action.Transfer()
.setFlavorId("usd")
.setAmount(10)
.setSourceAccountId("alice")
.setDestinationAccountId("merchant")
)
.addAction(new Transaction.Builder.Action.Issue()
.setFlavorId("merchantpoints")
.setAmount(10)
.setDestinationAccountId("alice")
)
.addTransactionTagsField("invoice", "123")
.addTransactionTagsField("storeId", "456")
.transact(ledger);

Querying Examples

By flavor

Query all transactions that transferred USD.

Transaction.ItemIterable txs = new Transaction.ListBuilder()
.setFilter("actions(type=$1 AND flavorId=$2)")
.addFilterParameter("transfer")
.addFilterParameter("usd")
.getIterable(ledger);
for (Transaction tx : txs) {
System.out.println("transaction id: " + tx.id);
}

By account

Query all transactions where Alice transferred any tokens to Bob

Transaction.ItemIterable txs = new Transaction.ListBuilder()
.setFilter("actions(sourceAccountId=$1 AND destinationAccountId=$2)")
.addFilterParameter("alice")
.addFilterParameter("bob")
.getIterable(ledger);
for (Transaction tx : txs) {
System.out.println("transaction id: " + tx.id);
}

By action tags

Query all issuances where deposit source was wire transfer.

Transaction.ItemIterable txs = new Transaction.ListBuilder()
.setFilter("actions(type=$1 AND tags.source=$2)")
.addFilterParameter("issue")
.addFilterParameter("wire")
.getIterable(ledger);
for (Transaction tx : txs) {
System.out.println("transaction id: " + tx.id);
}

By flavor tag

Query all transactions where any type of currency was issued.

Transaction.ItemIterable txs = new Transaction.ListBuilder()
.setFilter("actions(type=$1 AND snapshot.flavorTags.type=$2)")
.addFilterParameter("issue")
.addFilterParameter("currency")
.getIterable(ledger);
for (Transaction tx : txs) {
System.out.println("transaction id: " + tx.id);
}

By transaction tags

Query all transactions for a store.

Transaction.ItemIterable txs = new Transaction.ListBuilder()
.setFilter("actions(snapshot.transactionTags.storeId=$1)")
.addFilterParameter("456")
.getIterable(ledger);
for (Transaction tx : txs) {
System.out.println(tx.tags);
System.out.println(tx.actions.get(0).snapshot.transactionTags);
}