Last active
August 29, 2015 14:05
-
-
Save akhavr/f8a83289443dee97edbb to your computer and use it in GitHub Desktop.
Doing ripple transactions via ripple_api.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This is short instruction how to start doing ripple transactions with python. | |
I'm using https://github.com/42cc/ripple_api/ , developed by 42 Coffee Cups, my company. | |
1. Install the package into your virtual environment | |
(.env) $ pip install -e git://github.com/42cc/ripple_api.git#egg=django-ripple_api | |
Obtaining django-ripple-api from git+git://github.com/42cc/ripple_api.git#egg=django-ripple_api | |
Cloning git://github.com/42cc/ripple_api.git to ./.env/src/django-ripple-api | |
Running setup.py egg_info for package django-ripple-api | |
Downloading/unpacking requests<2.3.0 (from django-ripple-api) | |
Downloading requests-2.2.1.tar.gz (421Kb): 421Kb downloaded | |
Running setup.py egg_info for package requests | |
Downloading/unpacking django-model-utils<1.4.0 (from django-ripple-api) | |
Downloading django-model-utils-1.3.1.tar.gz | |
Running setup.py egg_info for package django-model-utils | |
Installing collected packages: django-ripple-api, requests, django-model-utils | |
Running setup.py develop for django-ripple-api | |
Creating /home/akhavr/src/test/.env/lib/python2.7/site-packages/django-ripple-api.egg-link (link to .) | |
Adding django-ripple-api 0.0.13 to easy-install.pth file | |
Installed /home/akhavr/src/test/.env/src/django-ripple-api | |
Found existing installation: requests 2.3.0 | |
Uninstalling requests: | |
Successfully uninstalled requests | |
Running setup.py install for requests | |
Running setup.py install for django-model-utils | |
Successfully installed django-ripple-api requests django-model-utils | |
Cleaning up... | |
2. Make sure you've imported the package | |
""" | |
>>> from ripple_api import ripple_api | |
""" | |
3. Set the your parameters | |
""" | |
>>> source = 'rKSZq....' | |
>>> secret = 'shqgq....' | |
>>> ripple_server = 'http://r.ripple.com:51234' | |
>>> amount = 0.001 | |
>>> tag = 123 | |
>>> dest = 'rBeTo....' | |
""" | |
4. For the purpose of this tutorial, I assume that both source and dest have a trust line in USD to the same gateway. Code should work also for direct trust and for more complex setups. | |
""" | |
# Specify what destination would receive | |
>>> IOU_receive = { 'currency': 'USD', | |
'issuer': dest, | |
'value': unicode(amount), | |
} | |
# Specify what we would like to send | |
>>> IOU_send = [ { 'currency': 'USD', 'issuer': source, } | |
# you can have more than one option | |
] | |
# Find the paths | |
>>> paths = ripple_api.path_find(source, dest, IOU_receive, IOU_send, server_url = ripple_server) | |
# Now, if `paths['alternatives']` you've got path to pay | |
""" | |
5. Sign your transaction using computed path | |
""" | |
>>> request = ripple_api.sign(source, secret, dest, IOU_receive, destination_tag=tag, | |
... paths = paths['alternatives'][0]['paths_computed'], | |
... server_url = ripple_server) | |
""" | |
6. Submit transaction | |
""" | |
>>> res = ripple_api.submit(request['tx_blob'], fail_hard = True, server_url = ripple_server) | |
>>> res['engine_result'] | |
'tesSUCCESS' | |
""" | |
That's it! | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment