Code Monkey home page Code Monkey logo

api's Introduction

DFX API

API for DFX.swiss crypto exchange

API Documentation

Swagger

Registration

Initial Wallet Setup (optional)

Contact support to register your wallet name. This is used to identify all users that signed up with your wallet.

Sign Up

  1. Get the sign message from sign-message endpoint (with the user's address) and sign it with the corresponding private key
  2. Register the user with the sign-up endpoint
    • Use the walletId from step initial setup
    • See below for more information on the referral program (usedRef)
  3. Now you can get your JWT access token (with address & signature) with the sign-in endpoint

Notifications

If a user wants to get notified about ongoing transactions, he can register his email address with the user endpoint

Referral Program

  • Basic information about the referral program can be found in the FAQ on our homepage
  • A referral code can only be set once during user registration (usedRef parameter)
  • Every user will receive his own referral code after the first successful transaction. It can be get from the user detail endpoint.

KYC (optional)

KYC is not required for a daily transaction volume up to 1000 EUR/CHF. To increase the transaction volume, the user needs to be verified with a KYC process, which can be done on the DFX KYC page.

  1. Get the user's KYC hash from user endpoint
  2. Open then link to the KYC page: https://payment.dfx.swiss/kyc?code=<kyc-hash>

Transactions

Buy Crypto

  1. Get all available assets with the asset endpoint
    • This endpoint will return all assets compatible with the user's address, which might be assets on multiple blockchains. The query parameter (optional) can be used to filter for specific blockchains.
    • Only assets with the buyable field set to true can be bought
  2. Get all available currencies with the fiat endpoint
    • Only fiats with the sellable field set to true can be used to buy crypto
  3. Get the payment information with the buy payment endpoint
  4. Do a bank transfer with the provided payment infos
    • Ensure compliance with minimum deposit and KYC limits
  5. The crypto asset will be sent to the user's blockchain address as soon as the bank transfer is completed

Sell Crypto

In order to perform bank transactions, DFX needs to know the name and address of the recipient. Therefore, user data must be collected once before a sale can be made. The user data can be updated with the kyc data endpoint. Required fields are mail, phone, firstname, surname, street, houseNumber, location, zip, country. For non personal accounts, organizationName, organizationStreet, organizationHouseNumber, organizationLocation, organizationZip, organizationCountry are also required.

  1. Update user data, if required (check with kycDataComplete field from user endpoint)
  2. Get all available assets with the asset endpoint
    • Only assets with the sellable field set to true can be sold
  3. Get all available currencies with the fiat endpoint
    • Only fiats with the buyable field set to true can be used to sell crypto
  4. Get the payment information with the sell payment endpoint
  5. Do a blockchain transaction to the provided deposit address
    • Ensure compliance with minimum deposit and KYC limits
  6. The fiat will be sent to the specified bank account as soon as the blockchain transaction is completed

Bank Accounts (optional)

  • All bank accounts of a user can be fetched with the bank account endpoint
  • A call to the buy or sell payment info endpoints will automatically create a bank account for the provided IBAN
  • This can be used to improve UX and show the previously used IBANs to the user
  • Bank accounts (label, preferred currency) can be updated with the update endpoint
  • Bank accounts can be created directly with the create endpoint

Integration Example

Appendix

Login Example

The following code snippet shows a way to generate login credentials for the DeFiChain blockchain.

import { MainNet, Network } from '@defichain/jellyfish-network';
import { JellyfishWallet } from '@defichain/jellyfish-wallet';
import { Bip32Options, MnemonicHdNodeProvider } from '@defichain/jellyfish-wallet-mnemonic';
import { WhaleWalletAccountProvider } from '@defichain/whale-api-wallet';
import { sign } from 'bitcoinjs-message';

export class DfxLoginHelper {
  private readonly network = MainNet;
  private readonly seed = [
    /* PUT YOUR SEED HERE */
  ]; // 24 word mnemonic seed phrase

  async generateCredentials(uniqueUserId: number): Promise<{ address: string; signature: string }> {
    const { address, privateKey } = await this.getAccount(uniqueUserId);

    const signMessage = await this.getSignMessage(address);
    const signature = this.signMessage(signMessage, privateKey);

    return { address, signature };
  }

  // --- HELPER METHODS --- //
  private async getAccount(id: number): Promise<{ address: string; privateKey: Buffer }> {
    const wallet = new JellyfishWallet(
      MnemonicHdNodeProvider.fromWords(this.seed, this.bip32OptionsBasedOn(this.network)),
      new WhaleWalletAccountProvider(undefined, this.network),
      JellyfishWallet.COIN_TYPE_DFI,
      JellyfishWallet.PURPOSE_LIGHT_WALLET,
    );

    return {
      address: await wallet.get(id).getAddress(),
      privateKey: await wallet.get(id).privateKey(),
    };
  }

  private bip32OptionsBasedOn(network: Network): Bip32Options {
    return {
      bip32: {
        public: network.bip32.publicPrefix,
        private: network.bip32.privatePrefix,
      },
      wif: network.wifPrefix,
    };
  }

  private async getSignMessage(address: string): Promise<string> {
    // GET DFX SIGN MESSAGE WITH API CALL
    return 'TODO';
  }

  private signMessage(message: string, privateKey: Buffer): string {
    return sign(message, privateKey, true, this.network.messagePrefix).toString('base64');
  }
}

api's People

Contributors

davidleomay avatar kolibri1990 avatar yannick1712 avatar tonysemikin avatar krysh90 avatar sandrich avatar phil-schoe avatar defi-portfoliomanagement avatar oliviera1994 avatar dfxadmin avatar bt-felix avatar danielzirkel avatar pitrestein avatar robintorque avatar lem-helbling avatar torte-art avatar jaedile avatar topaccina avatar

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.