Skip to main content


Now, all the pieces of our cryptocurrency are in place. We have created a cryptocurrency with the following features:

  1. Balances can never be negative.
  2. A user may only withdraw from their own account.
  3. A user may only add to another user's account.
  4. When withdrawing or adding, the amount withdraw has to equal the amount added.

If you have been following along with this lesson in your own ledger, you can try transacting, and see whether the transactions do what we expect.

In a transaction, you can specify the new and old transactions for a given user by including a number.

[  {    "_id": ["wallet/name", "cryptoMan"],    "balance": 195  },  {    "_id": ["wallet/name", "cryptWoman"],    "balance": 205  },  {    "_id": "_tx",    "auth": ["_auth/id", "cryptoMan"]  }]

Or, you can use the ?pO function, which gives access to the previous object of the predicate.

[  {    "_id": ["wallet/name", "cryptoMan"],    "balance": "#(+ (?pO) 10)"  },  {    "_id": ["wallet/name", "cryptWoman"],    "balance": "#(- (?pO) 10)"  },  {    "_id": "_tx",    "auth": ["_auth/id", "cryptoWoman"]  }]

Note that that the parts of the transactions above that include _tx are effectively signing the transaction as the identity specified in the _auth. If you don't have fdb-api-open set to true (the default in the downloadable version), then these transactions won't work.