A Twitter bot which issues its own currency

(Update: I’ve now taken my instance of the bot down, but the code should still work if you want to run your own.)

I spent some time this weekend putting together a proof-of-concept Twitter bot which issues its own “upvote” currency. You use it by tweeting something like the following:

@stellarjob +++@thegdb cool bot!

!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');

The bot then walks the user through linking their Stellar account and extending trust for its +++ currency. Once the trust has been granted, the bot issues a +++ credit. Each subsequent upvote results in another +++ being issued.

Because the credits are issued on Stellar, they can be seen on the account viewer, or even traded on Stellar’s distributed exchange.

Code #

You can grab the code for the bot from Github. Disclaimer: this code is definitely the quickest implementation that could possibly work; please don’t judge me for it :).

Account linking #

One interesting aspect of the project is how the bot links your Stellar account. It asks the user to extend trust for a unique number of +++.

When it sees a trust line for the appropriate amount, it then asks the user to confirm that it’s in fact their Stellar account. (Initially, I was tempted to try doing this without the confirmation — I wanted to see how long it could go without someone intercepting someone else’s +++. Unfortunately, before I’d even finished initial testing, one curious observer ended up completing the linking flow on behalf of one of the test subjects.)

Stellar API calls #

The set of Stellar API calls here are as follows:

The bot just polls the Stellar API for changes in trust, though in principle it could use the WebSocket API to get streaming updates.


Now read this

#define CTO

I joined Stripe as an engineer in 2010. I began by working on the backend infrastructure: designing the server architecture, creating our credit card vault, and producing internal abstractions to make people’s jobs easier. I loved... Continue →