Git Product home page Git Product logo

zabo-sdk-js's Introduction

What is Zabo? A unified cryptocurrency API.

CircleCI Discord Discourse

Zabo is an API for connecting with cryptocurrency exchanges, wallets and protocols like Bitcoin. Instead of manually integrating with Coinbase API, Binance API, Bitcoin APIs or the hundreds of other cryptocurrency APIs - you can simply use Zabo for them all.

We believe teams and developers should focus on building great products, not worry about the fragmented landscape of exchange APIs and blockchain protocols.

For our updated list of integrations, check out our Zabo integrations.

Zabo API Javascript (JS) SDK

The Zabo SDK for JS provides convenient access to the Zabo API from applications written in browser and server-side JavaScript.

Please keep in mind that you must register and receive a team id to use in your client application, or if you are using the server side functions, generate an API keypair from your dashboard.

Documentation

See the Zabo API docs.

Installation

For a standard browser application, add the script tag to your html file:

<script src="https://cdn.zabo.com/develop/latest/zabo.js">

As a package:

npm install zabo-sdk-js --save

Usage

The first step is always to allow a user to connect from your front-end:

<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
  <meta charset="utf-8">
  <title>My Website</title>

  <link rel="stylesheet" href="example.css" type="text/css" />
</head>

<body>
  <section>
    <header>
      <h2>My Zabo Application</h2>
    </header>

    <button id="connect" type="button">Connect</button>

    <div>
      <h4>Other SDK methods</h4>
      <button id="getBalance" type="button">Crypto Balances</button>
      <button id="getHistory" type="button">Account History</button>
      <button id="getExchangeRates" type="button">Exchange Rates</button>
    </div>

  </section>

  <!--Add this script to your html file-->
  <script src="https://cdn.zabo.com/latest/zabo.js"></script>

  <script type="text/javascript">
    // Wait for document to fully load
    document.onreadystatechange = async () => {
      if (document.readyState !== 'complete') { return }

      const output = document.querySelector('#output')

      // Initiate Zabo SDK, replace the `clientId` field with your team client id.
      const zabo = await Zabo.init({
        clientId: 'YourClientIDFromTheZaboDotComDashboard',
        env: 'sandbox'
      })
      // Bind "connect" button
      document.querySelector('#connect').addEventListener('click', ev => {
        // Call connect when pressed and provide default .connect() window.
        zabo.connect().onConnection(account => {
          console.log('account connected:', account)
          bindOtherMethods()
        }).onError(error => {
          console.error('account connection error:', error.message)
        })
      })

      // Bind buttons for the other SDK example methods [Requires a successful zabo.connect() first]
      function bindOtherMethods () {
        document.querySelector('#getBalance').addEventListener('click', ev => {
          // Get ETH balance
          zabo.accounts.getBalances({ tickers: ["ETH"] }).then(balances => {
            console.log(balances)
          }).catch(error => {
            /* User has not yet connected or doesn't have an ether wallet */
            console.error(error)
          })
        })

        document.querySelector('#getHistory').addEventListener('click', ev => {
          // Get account transactions history
          zabo.transactions.getList({ ticker: 'ETH' }).then(history => {
            console.log(history)
          }).catch(error => {
            /* User has not yet connected */
            console.error(error)
          })
        })

        document.querySelector('#getExchangeRates').addEventListener('click', ev => {
          // Get crypto USD exchange rates
          zabo.currencies.getExchangeRates().then(rates => {
            console.log(rates)
          }).catch(error => {
            console.error(error)
          })
        })
      }
    }
  </script>
</body>

</html>

Or importing as a package:

const Zabo = require('zabo-sdk-js')

const zabo = await Zabo.init({
  clientId: 'YourClientIDFromTheZaboDotComDashboard',
  env: 'sandbox'
})

zabo.connect().onConnection(account => {
  console.log('account connected:', account)
}).onError(error => {
  console.error('account connection error:', error.message)
})

Or using ES6 modules:

import Zabo from 'zabo-sdk-js'

After connecting

After a user connects, the client SDK can continued to be used for the connected wallet:

zabo.transactions.getList({ ticker: 'ETH' }).then(history => {
  console.log(history)
}).catch(error => {
  /* User has not yet connected */
  console.error(error)
})

Or you can send the account to your server for the server-side SDK to create a unique user:

zabo.connect().onConnection(account => {
  sendToYourServer(account)
}).onError(error => {
  console.error('account connection error:', error.message)
})

// Then in your server
const Zabo = require('zabo-sdk-js')
let account = accountReceivedFromTheClient

Zabo.init({
  apiKey: 'YourPublicAPIKeyGeneratedInYourZaboDotComDashboard',
  secretKey: 'YourSecretAPIKey',
  env: 'sandbox'
}).then(zabo => {
  zabo.users.create(account)
}).catch(e => {
  console.log(e.message)
})

Zabo.init() Configuration

While instantiating your new Zabo SDK instance, you have a few configuration options that can be changed to best suit your needs. Please note that some options are available only when running the SDK from the browser while others are available when running the SDK on your node.js code.

Key Description Platform
clientId App Key acquired when registering a team in Zabo Dashboard. Browser
env Zabo API environment the SDK is connecting with. Could be either sandbox or live. Only sandbox is available unless a live connection is approved. Both
apiKey API Key generated via the Developer Settings section at Zabo Dashboard. Node
secretKey Secret Key generated via the Developer Settings section at Zabo Dashboard. Node
autoConnect Optional boolean useful if you wish to stop the SDK from fetching the team data during Zabo.init(). Defaults to true. Both
apiVersion Optional parameter to specify the Zabo API version. Could be either v0 or v1. Defaults to v1. Both

Server vs Client

The SDK can be used in either the client or server environment after a user connects their wallet, however, they have different functions available to them and utilize different authentication methods. See the Zabo API docs for more information.

Using Promises

Every method returns a chainable promise which can be used:

zabo.getTeam().then(a => {
  console.log(a)
}).catch(e => {
  console.log(e.message)
})

Or with async/await:

let exchangeRates = await zabo.currencies.exchangeRates()
console.log(exchangeRates)

Help and Further Information

Please read our docs and reach out to us in any or all of the following forums for questions:

Issues

If you notice any issues with our docs, this README, or the SDK, feel free to open an issue and/or a PR. We welcome community contributions!

zabo-sdk-js's People

Contributors

bdsmoura avatar dependabot[bot] avatar diaswrd avatar dreinke avatar marcelodesouza avatar xeo-skr avatar zaneh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zabo-sdk-js's Issues

Zabo SDK build error

What SDK version are you using?

0.6.4

What technology and versions are you using that is causing issues with the SDK?

We are using React.js, and Node 8.13.0, npm version 6.4.1

Here is package.json
{
"private": true,
"version": "1.2.0",
"main": "",
"scripts": {
"clean": "rimraf dist/*",
"copy": "copyfiles -f ./src/index.html ./dist && copyfiles -u 1 "./src/static/**" ./dist",
"build": "npm run clean && npm run copy && webpack --progress --bail --env dist -p",
"lint": "eslint ./src",
"posttest": "npm run lint",
"serve:dev": "webpack-dev-server --open --env dev",
"serve:dist": "webpack-dev-server --open --env dist -p --progress",
"start": "npm run serve:dev"
},
"devDependencies": {
"babel-core": "^6.23.1",
"babel-eslint": "^7.2.1",
"babel-loader": "^6.4.1",
"babel-plugin-istanbul": "^4.1.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-polyfill": "^6.23.0",
"babel-preset-airbnb": "^2.0.0",
"babel-preset-es2015-native-modules": "^6.6.0",
"babel-preset-react": "^6.23.0",
"babel-preset-stage-0": "^6.5.0",
"babel-preset-stage-1": "^6.5.0",
"babel-preset-stage-2": "^6.5.0",
"bootstrap": "~4.0.0-alpha.6",
"browser-sync": "^2.18.8",
"copy-webpack-plugin": "^4.0.1",
"copyfiles": "^1.2.0",
"css-loader": "^0.28.0",
"del": "^2.2.0",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-loader": "^1.7.1",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.3",
"file-loader": "^0.11.1",
"glob": "^7.0.0",
"gulp": "^3.9.1",
"gulp-load-plugins": "^1.2.2",
"gulp-plumber": "^1.1.0",
"gulp-pug": "^3.3.0",
"gulp-util": "^3.0.7",
"node-sass": "^4.5.2",
"null-loader": "^0.1.1",
"open": "0.0.5",
"phantomjs-prebuilt": "^2.1.7",
"rimraf": "^2.6.1",
"sass-loader": "^6.0.2",
"style-loader": "^0.16.1",
"url-loader": "^0.5.8",
"webpack": "^2.3.2",
"webpack-dev-server": "^2.4.1",
"yargs": "^7.0.1"
},
"dependencies": {
"axios": "latest",
"classnames": "~2.2.5",
"core-js": "~2.4.0",
"echarts": "^3.5.1",
"element-resize-event": "^2.0.9",
"font-awesome": "~4.7.0",
"jquery": "^3.2.1",
"jquery-slimscroll": "~1.3.8",
"material-ui": "~0.17.0",
"prop-types": "latest",
"rc-queue-anim": "^0.13.3",
"react": "~15.4.2",
"react-bootstrap-sweetalert": "^4.4.1",
"react-dom": "~15.4.2",
"react-hot-loader": "^3.0.0-beta.6",
"react-redux": "^5.0.3",
"react-router": "^3.0.2",
"react-router-redux": "^4.0.8",
"react-tap-event-plugin": "^2.0.1",
"react-toastify": "^1.2.0",
"redux": "~3.6.0",
"redux-thunk": "^2.3.0",
"zabo-sdk-js": "^0.6.4"
},
"engines": {
"node": ">=6.5.0",
"npm": ">= 3"
}
}

What did you do?

npm i
npm run build

What did you expect to see?

The build should be successful.

What did you see instead?

We are getting error from zabo sdk.
image

SDK checks both `isNode` and `isBrowser` in a single instantiation

Just wanted to say first off that this SDK has been great thus far, it was really straightforward to implement!

What SDK version are you using?

1.0.2

What technology and versions are you using that is causing issues with the SDK?

Express application, node v12.16.0, express v4.16.4

What did you do?

  • Instantiated an instance of the api client using our api key and secret:
await Zabo.init({{
      apiKey: PUBLIC,
      secretKey: SECRET,
      env: 'sandbox',
});

I then ran a spec (via jest) that called the client instantiation. I did this to inspect the shape of the client interface โ€” I needed to determine what properties were necessary to define in our .ts files. Ordinarily I would mock this object out in specs, but I wanted an initial look at the instantiated client.

What did you expect to see?

A successful connection by the client

What did you see instead?

An error telling me to add a valid clientId to the initialize options.

This error is thrown because the code at src/sdk, on line 38, is checking if the current env is node. The same file then checks on line 66 to see if the current env is the browser.

Although the specific instance in which I encountered this error is definitely an edge case, I think this check should probably be an if / else; we can safely assume we are not operating in the browser if the isNode check evaluates as true.

The main caveat to making this change would probably be if a user is executing the library in a node env, but wants to simulate a browser? For example, I'm unsure if a headless browser env running on e.g. puppeteer will have both global and window defined.

Either way, wanted to flag this in case others have experienced it. Thanks!

unauthorized issue.

What SDK version are you using?

"zabo-sdk-js": "^0.6.2"

What technology and versions are you using that is causing issues with the SDK?

Unauthorized error.
Reactjs, node back-end.

What did you do?

I have connected to zabo service using zabo.init(), connect(), onConnection()...
And I added new account using metamask,
but, I can see unauthorized error in backend(node js) now.

What did you expect to see?

I guess it depends on any exception in sdk authorization logic.
For instance, such as old credential..

What did you see instead?

I tried as other account or pc.
but I am getting the same error..

Documentation questions

Hi friends at Zabo,

Thank you so much for the Zabo API! I'm very excited about it. :-)

I'm not experiencing an error or a problem, really. I'm just confused about the documentation and so am hoping for some clarification.

I have a server-side Zabo app ("zabo-sdk-js": "^1.1.0") using Node.

I've read https://zabo.com/docs/#pagination and https://zabo.com/docs/#get-transaction-history, which has said for a while:

"We are working on a fully-featured WebSocket implementation of this call for our next release which will provide a much-improved experience."

Do you know when that will be available?

I'm also wondering if you could please clarify this section:

This function returns a transaction history list for the current account. Many accounts have large transaction histories and require a lengthy period of time to retrieve a full dataset. This means that most accounts will not return any transactions on the first call, but will return an empty array with a delay value and last_updated_at will be 0. The delay is an estimated number of seconds before the transaction history will be available, or, if there are transactions, the number of seconds it will take for the transaction history to update. The estimate is our best guess based on known factors, however the time could take much longer if the account has more transactions than anticipated. Make sure you are considering this delay before calling the transaction history again both via SDK or HTTP request. When making subsequent calls, the last_updated_at field will let you know if the full history has been retrieved. You may start seeing transactions in the list, however, if last_updated_at is still 0, then we are still retrieving the history. When last_updated_at updates to a particularly useful timestamp, that will be the latest time at which a full history was accounted for. All transactions will be included if no currency is specified.

It wasn't obvious that "Optional ID of the resource to start from" meant the transaction ID, but that seems to be the case.

In my attempts to fetch all transactions for a given account ID, it's still not clear to me how to do it. (If you could provide a working example, that would be so helpful.)

I set the limit to 50, I omit ticker, and I call the endpoint multiple times (after waiting the delay), but it doesn't seem to update with more records.

Am I supposed to look for the ID of the last item in the array and then pass that as a cursor and then keep doing that until fewer than 50 results are returned?

How are the records sorted, and is there a way to pass a sort field and direction as a parameter?

Thank you so much! :-D

Uncaught TypeError

What SDK version are you using?

1.0

What technology and versions are you using that is causing issues with the SDK?

I'm using the html script for client side

What did you do?

I copied the zabo script into my html file. I can connect to my Metamask wallet just fine. When I click the crypto balances button I get results as expected. When I click on the Account History button I get this error - "Uncaught TypeError: Cannot read property 'getList' of undefined at HTMLButtonElement." Did I leave something out? Not a professional, just trying to learn. Thanks in advance. Here is the script I used -

<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
    <meta charset="utf-8">
    <title>My Website</title>

    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
        integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
        integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>

<body>
    <section>
        <header>
            <h2 class="text-center">Tammy's Zabo Application</h2>
        </header>
        <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <!-- Include all compiled plugins (below), or include individual files as needed -->
        <script src="js/bootstrap.min.js"></script>

        <div class="container-fluid">
            <br>
            <div class="row">
                <div class="col-md-12 bg-light text-right">
                    <button id="connect" type="button" class="btn btn-success">Connect Wallet</button>
                </div>
            </div>
        </div>
        <br>
        <br>
        <div class="container-fluid">
            <h4>What Have I Been Up To?</h4>
            <button id="getBalance" type="button" class="btn btn-primary">Crypto Balances</button>
            <button id="getHistory" type="button" class="btn btn-warning">Account History</button>
        </div>

    </section>

    <!--Add this script to your html file-->
    <script src="https://cdn.zabo.com/latest/zabo.js"></script>

    <script type="module">
        // Wait for document to fully load
        document.onreadystatechange = async () => {
            if (document.readyState !== 'complete') { return }

            const output = document.querySelector('#output')

            // Initiate Zabo SDK, replace the `clientId` field with your team client id.
            const zabo = await Zabo.init({
                clientId: 'e0Tubz6cMC3qSAS8Zh5mkinQZ6G3FLlrIyAM44Vk0PWB854e2Xmxf5PP7TxEC73B',
                env: 'sandbox'
            })
            // Bind "connect" button
            document.querySelector('#connect').addEventListener('click', ev => {
                // Call connect when pressed and provide default .connect() window.
                zabo.connect().onConnection(account => {
                    console.log('account connected:', account)
                    bindOtherMethods()
                }).onError(error => {
                    console.error('account connection error:', error.message)
                })
            })

            // Bind buttons for the other SDK example methods [Requires a successful zabo.connect() first]
            function bindOtherMethods() {
                document.querySelector('#getBalance').addEventListener('click', ev => {
                    // Get ETH balance
                    zabo.accounts.getBalances({ tickers: [""] }).then(balances => {
                        console.log(balances)
                    }).catch(error => {
                        /* User has not yet connected or doesn't have an ether wallet */
                        console.error(error)
                    })
                })

                document.querySelector('#getHistory').addEventListener('click', ev => {
                    // Get account transactions history
                    zabo.transactions.getList({
                        ticker: '',
                        limit: 50
                    }).then(function (history) {
                        console.log(history.data)
                        /* 
                          `history` is the json object outlined below. NOTE: list_cursor is 
                          not exposed in the JS SDK. Simply call `next()` on the response
                          to paginate
                        */
                        history.next().then(moreHistory => {
                            console.log(moreHistory.data)
                        })
                    })
                        .catch(function (error) {
                            console.log(error)
                            /* See errors section for more information */
                        })
                })
            }
        }
    </script>
</body>
</html>

What did you expect to see?

What did you see instead?

Create user returning Cannot read property 'users' of undefined

` zabo.connect().onConnection(async account => {

.then(zabo => {
console.log(account)
zabo.users.create(account)
}).catch(e => {
console.log(e.message)
})
zabo.user.create(account).then(function(user) {
console.log(user)
/* user is the object outlined below /
})
.catch(function(error) {
console.log(error)
/
See errors section for more information */
})

}).onError(async error => {
console.log('Failed')
console.error('account connection error:', error.message)
})`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.