Skip to content

Instantly share code, notes, and snippets.

@gdb
Last active August 29, 2015 14:04
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdb/853c333748bbe51f5bd4 to your computer and use it in GitHub Desktop.
Save gdb/853c333748bbe51f5bd4 to your computer and use it in GitHub Desktop.
Issuing your own "currency" using Stellar's distributed exchange

One interesting thing you can do with Stellar is issue your own custom "currency". Here's a simple example of doing so. This route involves making an offer on the distributed exchange, and then waiting for someone to make an overlapping counteroffer.

I've created an offer giving out minutes of my help on a project of your choice (represented by the currency GDB), at a rate of 1,000 stellar per minute. You can see this offer in the graphical account viewer: https://www.stellar.org/viewer/#/gdb.

(This credit is redeemable for things like architecture advice, conversations about cryptocurrencies, debugging help, or the like. Once you hold the credit, you can redeem it by contacting me, and we'll arrange a Hangout or in-person meeting, depending on what makes sense.)

Did you just claim the currency GDB?!

Not quite. Stellar works a bit off the principle "Is the blue you see, the same blue I see?" If someone trusts a bunch of gateways for USD, if effectively means that they personally consider those issuers' USD all interchangeable. Another person might only want one of those gateways' USD, in which case they don't need to trust the other gateways. Another might have a completely separate concept of what "USD" means, and trust none of those gateways, but be none-the-worse for it.

So really I've just claimed the currency GDB for people who choose to trust me directly.

Seeing the offer in the API

My Stellar account is gpFfX9931eSbjUhtu3ujb6Tu7Z48u53uiL. First, you can check the status of my offer like so:

$ curl -X POST https://live.stellar.org:9002 -d '{"method":"account_offers", "params": [{"account": "gpFfX9931eSbjUhtu3ujb6Tu7Z48u53uiL"}]}'
{
   "result" : {
      "account" : "gpFfX9931eSbjUhtu3ujb6Tu7Z48u53uiL",
      "offers" : [
         {
            "flags" : 0,
            "seq" : 14,
            "taker_gets" : {
               "currency" : "GDB",
               "issuer" : "gpFfX9931eSbjUhtu3ujb6Tu7Z48u53uiL",
               "value" : "30"
            },
            "taker_pays" : "30000000000"
         }
      ],
      "status" : "success"
   }
}

This represents an offer for 30 GDBs, issued by my account, in exchange for 30,000,000,000 microstellar.

Executing the trade

You can execute the trade by making your own matching counteroffer. You don't have to accept the entire offer — it's fine to partially fulfill it. The trade below purchases 1 minute of time for 1,000 stellar.

Note you have to fill in your account credentials to the command below:

  • You must use your account ID, rather than your username/federated address. (You can turn your username into an account ID either by using the account viewer or going into the Stellar client under the "Receive" -> "Show your Stellar Address".)

  • You can find your secret in the client in the client's settings window: https://launch.stellar.org/#/settings.

$ curl -X POST https://live.stellar.org:9002  -d '
    "method": "submit",
    "params": [
        {
            "secret": "<YOUR_SECRET>",
            "tx_json": {
                "Account": "<YOUR_ACCOUNT>",
                "TakerPays": {
                    "currency": "GDB",
                    "issuer": "gpFfX9931eSbjUhtu3ujb6Tu7Z48u53uiL",
                    "value": 1
                },
                "TakerGets": "1000000000",
                "TransactionType": "OfferCreate"
            }
        }
    ]
}'

Checking that it worked

You can check the updated balance in your account with the account_lines API call:

$ curl -X POST https://live.stellar.org:9002 -d '{"method":"account_lines", "params": [{"account": "gpFfX9931eSbjUhtu3ujb6Tu7Z48u53uiL"}]}'

You should see the credit reflected when you use your account ID there as well.

Alternatively, you can see it in the account viewer: https://www.stellar.org/viewer/#/gdb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment