CelsiusNetwork / celsius-js-sdk

Celsius JavaScript SDK provides an easy and secure way to communicate with the Celsius API.
https://developers.celsius.network
Apache License 2.0
24 stars 22 forks source link

Can a simple user consume your API? #58

Open guldil opened 3 years ago

guldil commented 3 years ago

Hello

I'm an user of Celcius, i just want to consume API to export my balance wallet every day.

Is it possible ?

Thanks

Guldil

victorbutler commented 3 years ago

Same here, so I will share what I did.

Here is where I went: https://developers.celsius.network/

  1. You need to request a Partner API key. Email link is at the bottom of the page.

After you get a key from the Business Development team

  1. Authenticate in the SDK using API_KEY and follow the calls in the test script - that worked for me.
  Celsius({
    authMethod: AUTH_METHODS.API_KEY,
    partnerKey: partnerKey, // Requested from https://developers.celsius.network/
    environment: ENVIRONMENT.PRODUCTION,
  })
    .then((celsius) => {
      celsius
        .getBalanceSummary(userApiKey)
        .then((balanceSummary) => {
          console.log(balanceSummary);
        })
        .catch((error) => {
          console.log("Error", error);
        });
    })
    .catch((e) => {
      console.error("Error", e);
    });

Example response balanceSummary

{
  balance: {
    eth: '0',
    btc: '0',
    dash: '0',
    bch: '0',
    bsv: '0',
    ltc: '0',
    zec: '0',
    btg: '0',
    xrp: '0',
    xlm: '0',
    omg: '0',
    tusd: '0',
    gusd: '0',
    pax: '0',
    paxg: '0',
    usdc: '0',
    dai: '0',
    mcdai: '0',
    cel: '0',
    zrx: '0',
    orbs: '0',
    'usdt erc20': '0',
    tgbp: '0',
    taud: '0',
    thkd: '0',
    tcad: '0',
    eos: '0',
    sga: '0',
    sgr: '0',
    xaut: '0',
    etc: '0',
    bat: '0',
    busd: '0',
    knc: '0',
    link: '0',
    lpt: '0',
    matic: '0',
    snx: '0',
    uma: '0',
    uni: '0',
    mana: '0',
    comp: '0',
    spark: '0',
    steth: '0',
    aave: '0',
    bnt: '0'
  }
}
  1. Where you see userSecret or apiKey parameters in the documentation/code, that's the Celsius user generated API key (Celsius App, go to Profile > API Key > Generate API Key)

References

Good luck!

andpi314 commented 3 years ago

Hi, I have yet to understand why it doesn't work, but in my case after having received a proper partnerKey (a partner one, securely transmitted by Celsius via email) and set the sdk to work with partnerKey (partner) and userSecret (created through the app) I received these errors:

This is shown in a normal browser:


Unhandled Rejection (Error): No signature was provided for verification.

while this appears if I run chrome in dev mode (--disable-web-security)


Unhandled Rejection (Error): wrong public key type

For your reference, my init code is as follows:

const initCelsius = async () => {
    const celsius = await Celsius({
      authMethod: AUTH_METHODS.API_KEY,
      partnerKey: "****",
      environment: ENVIRONMENT.PRODUCTION,
    })
    const rates = celsius.getInterestRates(
      "****"
    )
    console.log(rates)
  }

I also tried the combinations of auth keys in Postman, and I've successfully been able to get a response, so the problems is somewhere else.

Could the problem be due to the fact that I'm using the sdk on the frontend side (react)?