shapeshift.io
A JavaScript component for the crypto currency buying and selling ShapeShift.io service.
You can use ShapeShift.io to instantly exchange Bitcoin for Litecoin and other crypto currencies with no signup/account needed. Use Exodus to manage your crypto currency portfolios and easily exchange currencies with ShapeShift.
Works in both Node.js and the browser. API documentation here: https://shapeshift.io/api.html
Usage
Browserify Installation
Node.js /npm i --save shapeshift.io
Browser
You can use this module in the browser. Just grab the file here: https://github.com/jprichardson/shapeshift.io/tree/master/dist/shapeshift.js and drop it in a script tag on your page like this:
The shapeshift
object is global.
ShapeShift API
First, a note about the REST API provided by ShapeShift. Be aware that there are some inconsistencies that will no doubt be fixed in later versions. The following lists these consistencies:
In returned data, curIn
, curOut
, incomingType
, outgoingType
, inputCurrency
, outputCurrency
all
mean the same thing (obviously not input/output), namely a currency abbreviation. Just take note that
cur
, type
, and currency
usually mean the same thing.
Methods
- coins()
- depositLimit()
- emailReceipt()
- exchangeRate()
- isDown()
- marketInfo()
- recent()
- shift()
- status()
- transactions()
coins()
Get a map of supported coins.
Reference: https://shapeshift.io/api.html#getcoins
Example:
var shapeshift = shapeshift
depositLimit()
Get the deposit limit before you purchase.
Reference: https://shapeshift.io/api.html#deposit-limit
Example:
var shapeshift = var pair = 'btc_ltc'shapeshift
emailReceipt()
Email receipt for a transaction. Use the transaction id of the withdrawal not the transaction id of the transaction.
Reference: https://shapeshift.io/api.html#email-receipt
Method: emailReceipt(emailAddress, txId, callback)
Example:
var shapeshift = var depositAddress = 'YOUR_DEPOSIT_ADDRESS'shapeshift
exchangeRate()
Get the exchange rate. Note, the rate
is returned as a type of
string
; this is to ensure precision matches the API exactly.
Reference: https://shapeshift.io/api.html#rate
Example:
var shapeshift = var pair = 'btc_ltc'shapeshift
isDown()
Check if ShapeShift is down or in maintenance.
Example:
var shapeshift = shapeshift
marketInfo()
Get the market information.
Reference: https://shapeshift.io/api#api-103
Example:
var shapeshift = var pair = 'btc_ltc' // pair is optionalshapeshift
Note: When pair
is not passed, the field in the info changes from minimum
to min
.
recent()
Get a list of recent transactions / purchases.
Reference: https://shapeshift.io/api.html#recent-list
Example:
var shapeshift = shapeshift
shift()
Shift the coins. i.e. notify the API of the pair that you want to shift and the address that you want to receive the new coins at. Can also shift a fixed amount.
References: https://shapeshift.io/api.html#shift-conduit, https://shapeshift.io/api.html#sendamount
Method: shift(withdrawalAddress, pair, options, callback)
Example (normal shift):
// example: converting BTC to LTC in any amount var shapeshift = var withdrawalAddress = 'YOUR_LTC_ADDRESS'var pair = 'btc_ltc' // if something failsvar options = returnAddress: 'YOUR_BTC_RETURN_ADDRESS' shapeshift
Example (fixed amount):
// example: converting BTC to a Fixed Amount of LTC var shapeshift = var withdrawalAddress = 'YOUR_LTC_ADDRESS'var pair = 'btc_ltc'var amount = '0.1' // LTC amount that you want to receive to your LTC address // if something failsvar options = returnAddress: 'YOUR_BTC_RETURN_ADDRESS' amount: amount // <---- must set amount here shapeshift
Entire integration tests found here: https://github.com/jprichardson/shapeshift.js/blob/master/test/integration/basic-shift.test.js and https://github.com/jprichardson/shapeshift.js/blob/master/test/integration/basic-shift-fixed.test.js
status()
Get the status of most recent deposit transaction to the address.
Reference: https://shapeshift.io/api.html#status-deposit
Method: status(depositAddress, callback)
Example:
var shapeshift = // you get this from the result of shift()var address = 'DEPOSIT_ADDRESS'shapeshiftstatusaddress { consoledirdata // => /* { status : "complete", address: <address>, withdraw: <withdrawal address>, incomingCoin: <amount deposited>, incomingType: <coin type of deposit>, outgoingCoin: <amount sent to withdrawal address>, outgoingType: <coin type of withdrawal>, transaction: <transaction id of coin sent to withdrawal address> } */}
transactions()
List all of the transactions associated with an API key. Optionally pass the withdrawal address so that you can see all of the transactions associated with an address.
API keys are generated by ShapeShift. You must request them here: https://shapeshift.io/affiliate.html
References: https://shapeshift.io/api.html#txbyapikey, https://shapeshift.io/api.html#txbyaddress
Method: transactions(apiKey, [address], callback)
Example:
var somePrivKey = 'YOUR_PRIVATE_KEY'shapeshift
__version
Get the version number of this module. Useful in <script/>
tag browser development.
Intercept HTTP
You can intercept/modify http methods. This may be useful if you want to use an alternative http library.
http.get
Example:
var shapeshift = var oldGet = shapeshifthttpgetshapeshifthttp { // log urls? // use another http library?}
http.post
Example:
var shapeshift = var oldPost = shapeshifthttppostshapeshifthttp { // use another http library?}
CORS
ShapeShift supports CORS so that you can do cross-domain requests in the browser. See https://shapeshift.io/api.html#cors for more details.
Example:
var shapeshift = shapeshiftcors = true
Promises
Prefer a promise based API? No problem, Bluebird has you covered.
Just use promisifyAll()
:
var Promise = var shapeshift = Promise
That simple.
Wanna Hack on shapeshift.io package?
Awesome. First, this package uses JavaScript Standard Style.
You'll want to setup two private keys (WIF) so that you can actually test the shifting. Set these as environment variables. Make one for Bitcoin (BTC) and the other for Litecoin (LTC). You'll be using real funds. But don't worry, it's small amounts (a few pennies).
# shapeshift API testing
export SS_BTC_WIF=K....
export SS_LTC_WIF=T....
Then run the tests:
npm test
License
MIT
Copyright (c) 2015 JP Richardson