NAV Navbar
javascript java shell

Introduction

Swipe API is a solution for managing Digital Assets, Accounts and transfers, designed for creating financial applications quickly or optimizing existent solutions.

Compared to traditional systems, the solution offers advantages such as:

This solution has a simple design that fits all kinds of fintech apps, being able to support many different use cases.

Need any help? Contact us.

Run in Postman

Examples of use cases

Since this solution focuses on providing the building blocks of any financial app – accounts, balances, and assets –, there is a wide range of use cases. Some examples:

DLT Networks

Swipe API works by connecting with distributed networks (DLT), also called in some cases Blockchain networks.

We operate with 3 networks, each oriented for specific use cases. All concepts work equally in all networks, and the average confirmation time for each Action is 6 seconds.

Currently, we offer the following options:

Swipe Network

Recommended for most use cases, Swipe Network is a permissioned network – meaning that access is restricted to authorized users – that secures the access to information, safeguarding data privacy.

Stellar Network

Stellar is an open network recommended for global applications. This network is especially suitable for projects involving international remmittances or fundraising (such as ICOs or STOs) because of its large user base and marketplace integration, which is facilitated by a native exchange built directly on the network.

Dedicated Network

In cases of high demands for scalability, as is the case in corporate environments, we recommend using a network with fully exclusive infrastructure. To explore the creation of a dedicated network for your company, contact us.

Concepts

Assets

Assets represent physical or digital forms of value that can be transferred between people or companies. Some examples:

Accounts

An Account holds balances of one or more Assets. Accounts are represented by an unique identifier.

In most applications, Accounts usually represent individual users.

Organizations

An Organization is a particular type of Account that can issue Assets, create children Accounts and transfer Assets held by those accounts. Organizations have one or more credential pairs (API Key and Secret).

Organizations usually represent the company that provides the application for users.

Actions

There are four kinds of Actions:

All actions are performed in a DLT network, causing every change in the data to be automatically registered. Accordingly, every Action generates a Receipt that proves its inclusion in the network.

Create a new Account

Creates a new child Account of your Organization, specifying which Assets it will support.

Destroy an Account

Removes an Account, rendering its ID unusable. This Action requires the Account to hold empty balances of all its Assets. Destroyed Accounts cannot be recovered.

Issue an Asset

Creates a new Asset. The maximum issuing amount can be limited, making the Asset scarce.

Transfer Assets

Performs a transfer of an Asset between Accounts or between an Organization and an Account. If the transferred Asset is not supported by the receiving Account, it will start to support it automatically.

Action Batch

Some Actions can be sent and processed in a batch, in such a way that all Actions are processed simultaneously. That way, if any Action fails for any reason, every other Action will also fail.

There can be more than a single type of Action in the same batch.

Batchable Actions:

Memo

Every Action Batch supports a optional Memo field that can be used to add any kind of information related to a Batch. A few examples are to include a receipt from a external bank transaction, or add important information about the involved parties.

Integration

There are official Node.js v0.9.1 and Java/Kotlin v0.9.1 SDKs which we keep up-to-date. We also develop SDKs for other languages according to our customers' needs.

We strongly recommend using an SDK, because they do away with a great deal of complexity involved in integration, such as authentication, error handling and support to new versions.

Since our API is REST-based, it is also possible to use it directly.

While reading this section, use the tab on the right to follow integration examples using SDKs or via our REST API.

SDK Integration

Select the tabs on the right to view basic examples of how to use the SDKs.

Installation and Start-up

/*
Via npm:

`npm i @swp/swipe-sdk`

Via yarn:

`yarn add @swp/swipe-sdk`
*/
// ES2015 or TypeScript
import * as Swipe from '@swp/swipe-sdk'
// CommonJS
const Swipe = require('@swp/swipe-sdk')
/*

Gradle

//Step 1. Add it in your root build.gradle at the end of repositories:

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
} 

//Step 2. Add the dependency

dependencies {
    implementation 'com.github.swipetech:swp-java-sdk:0.9.1'
}


Maven

//Step 1. Add the JitPack repository to your build file 

<repositories>
  <repository>
      <id>jitpack.io</id>
      <url>https://jitpack.io</url>
  </repository>
</repositories> 


//Step 2. Add the dependency

<dependency>
    <groupId>com.github.swipetech</groupId>
    <artifactId>swp-java-sdk</artifactId>
    <version>0.9.1</version>
</dependency>

 */

Start-up

// Starts on the Production environment
const swp = Swipe.init({
  apiKey: "your api key",
  secret: "your secret key",
  language: Swipe.languages.EN_US,
})
// Starts on the Sandbox environment
const swp = Swipe.init({
  apiKey: "your api key",
  secret: "your secret key",
  sandbox: true,
  language: Swipe.languages.EN_US,
})
// Inicia no ambiente de Produção
 Swipe swp = new SwpBuilder()
                 .setApiKey("your api key")
                 .setSecret("your secret key")
                 .setLang(AcceptLanguage.PT_BR)
                 .build();
// Inicia no ambiente de Sandbox
 Swipe swp = new SwpBuilder()
                 .setApiKey("your api key")
                 .setSecret("your secret key")
                 .setLang(AcceptLanguage.PT_BR)
                 .setEnvAsSandbox()
                 .build();

After installation, the first step is to start up the SDK with a valid API Key, Secret and Language.

For testing purposes, we provide a Sandbox environment. See an example on the right tab.

REST API Integration

Select the shell tab on the right to view basic examples of integration via API using curl.

Environments

Use the following domains for your requests.

Authentication

Note that it is only necessary to do anything regarding request authentication if you choose to integrate directly to our API. Integration via SDK streamlines that process completely.

Headers

curl -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <API_KEY>" \
  -H "X-Swp-Signature: <SIGNATURE>" \
  https://api.swipetech.io/organizations

We use a model based on an API Key and a Secret to authenticate requests. All requests must include the following headers:

Signature (X-Swp-Signature)

const Crypto = require("crypto-js")
const Base64 = require("crypto-js/enc-base64")
const requestPath = "/accounts"
const bodyString = ""
const secret = "71ad81f98fbbab22c9d74948d2899a65027208197291d11e2065c3a9c62fe1f0"
const timestamp = Math.floor(Date.now() / 1000) // "1540920260"
const method = "GET"

const stringToSign = method + timestamp + requestPath + bodyString
const hmac = Crypto.HmacSHA256(stringToSign, secret)
const signature = Base64.stringify(hmac)

console.log(signature)
// /h02U+jDJWOG1npOvL1pH79hgGWT7mWymzxISP5IphA=

To generate a request signature, follow the guide below while viewing the javascript tab.

Example of a signature:

Field Value
Path /accounts
Method GET
Body
Secret 71ad81f98fbbab22c9d74948d2899a65027208197291d11e2065c3a9c62fe1f0
Timestamp 1540920260
Signature /h02U+jDJWOG1npOvL1pH79hgGWT7mWymzxISP5IphA=

Language

curl -H "Content-Type: application/json" \
  -H "Accept-Language: en-US" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  https://api.swipetech.io/organizations

To set the language for API responses, use the following header on requests:

Formatting Asset values

There are some formatting rules for asset values that have to be observed.

Querying information

This section lists the endpoints used to query details on an Organization, Accounts or Assets.

Pagination for GET requests

curl -X GET \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  https://api.swipetech.io/accounts?limit=10&starting_after=10003
swp.getAllAccounts({limit: "10"})
  .then(({data, pagination}) => {
    data.forEach(({ receipt, value }) => {
      console.log(receipt.id)
      console.log(value.id)
    })

    // load the second page
    return swp.getAllAccounts({ limit: "10", starting_after: pagination.cursor})
  })
  .then(({data}) =>
    data.forEach(({ receipt, value }) => {
      console.log(receipt.id)
      console.log(value.id)
    })
  )

    SuccessResponse<List<DataDTOReceipt<AccountDTO>>> resp =
    swp.getAllAccounts(
        new PaginationParams(null, "3"), null
    );

    PaginationResponse pagination = resp.getPagination();

    resp.getData().forEach(it -> {
       System.out.println(it.getReceipt().getId());
       System.out.println(it.getValue().getId());
    });

    // Buscar próxima página
    swp.getAllAccounts(
        new PaginationParams(String.valueOf(pagination.getCursor()), "3"), null
    ).getData()
     .forEach(it -> {
        System.out.println(it.getReceipt().getId());
        System.out.println(it.getValue().getId());
    });

We use a cursor-based pagination model. The following endpoints support it:

To use pagination, there are two optional parameters that are sent via query parameters on the request URL:

1. Organization

curl -X GET \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  https://api.swipetech.io/organizations
swp.getOrganization()
  .then(({data}) => console.log(data.value.name))
  .catch(error =>
    console.log(error)
  )
  OrgDTO org = swp.getOrganization().getData().getValue()

Query information on your Organization.

GET /organizations

Return

2. All Accounts

curl -X GET \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  https://api.swipetech.io/accounts?limit=10
swp.getAllAccounts({limit: "10"})
  .then(({data, pagination}) => {
    data.forEach(({ receipt, value }) => {
      console.log(receipt.id)
      console.log(value.id)
    })

    // loading the second page
    return swp.getAllAccounts({ limit: "10", starting_after: pagination.cursor})
  })
  .then(({data}) =>
    data.forEach(({ receipt, value }) => {
      console.log(receipt.id)
      console.log(value.id)
    })
  )
  .catch(error =>
    console.log(error)
  )

    SuccessResponse<List<DataDTOReceipt<AccountDTO>>> resp =
    swp.getAllAccounts(
        new PaginationParams(null, "3"), null
    );

    PaginationResponse pagination = resp.getPagination();

    resp.getData().forEach(it -> {
       System.out.println(it.getReceipt().getId());
       System.out.println(it.getValue().getId());
    });

    // Buscar próxima página
    swp.getAllAccounts(
        new PaginationParams(String.valueOf(pagination.getCursor()), "3"), null
    ).getData()
     .forEach(it -> {
        System.out.println(it.getReceipt().getId());
        System.out.println(it.getValue().getId());
    });

Query information on all Accounts ever created by your Organization.

GET /accounts?tag=<tag>&limit=<limit>&starting_after=<starting_after>

Query parameters

Parameter Description
tag (optional) Tags for filtering
limit (optional) Limit of items per page
starting_after (optional) Item ID from which the page should begin

Return

3. A specific Account

curl -X GET \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  https://api.swipetech.io/accounts/44d351a02f2307153be74984a59675f2733ad5deb1fa9fb08b0a36fe3d15fd6d
swp.getAccount("44d351a02f2307153be74984a59675f2733ad5deb1fa9fb08b0a36fe3d15fd6d")
  .then(({data}) =>
    console.log(data.receipt.id, data.value.id)
  )
  .catch(error =>
    console.log(error)
  )

   String ACC_ID = "3394abe6b49b3d718f572829adf2d7f186520d35be9e746e8d3d9366145b2fe1";

   AccountDTO acc = swp.getAccount(ACC_ID)
                       .getData()
                       .getValue();

Query information on a specific Account created by your Organization.

GET /accounts/:id

URL parameters

Parameter Description
id Account ID

Return

4. All Assets

curl -X GET \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  https://api.swipetech.io/assets?limit=10
swp.getAllAssets({limit: "10"})
  .then(({ data, pagination }) => {
    data.forEach(({ receipt, value }) => {
      console.log(receipt.id)
      console.log(value.code)
    })

    // loading the second page
    return swp.getAllAssets({ limit: "10", starting_after: pagination.cursor })
  })
  .then(({data}) =>
    data.forEach(({ receipt, value }) => {
      console.log(receipt.id)
      console.log(value.code)
    })
  )
  .catch(error =>
    console.log(error)
  )

 SuccessResponse<List<DataDTOReceipt<AssetDTO>>> resp =
              swp.getAllAssets(
                new PaginationParams(null, "3"), null
            );

  PaginationResponse pagination = resp.getPagination();

  resp.getData().forEach(it -> {
     System.out.println(it.getValue().getId());
  });

  // Buscar próxima página
  swp.getAllAssets(
      new PaginationParams(String.valueOf(pagination.getCursor()), "3"), null
  ).getData()
   .forEach(it -> {
      System.out.println(it.getReceipt().getId());
      System.out.println(it.getValue().getId());
  });

Query all Assets issued by your Organization.

GET /assets?tag=<tag>&limit=<limit>&starting_after=<starting_after>

Query parameters

Parameters Description
tag (optional) Tags for filtering
limit (optional) Limit of items per page
starting_after (optional) Item ID from which the page should begin

Return

5. All Transfers relative to an Account

curl -X GET \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  https://api.swipetech.io/accounts/44d351a02f2307153be74984a59675f2733ad5deb1fa9fb08b0a36fe3d15fd6d/transfers?limit=10
const accountId = "44d351a02f2307153be74984a59675f2733ad5deb1fa9fb08b0a36fe3d15fd6d"

swp.getAllTransfers(accountId, {limit: "10"})
  .then(({ data, pagination }) => {
    data.forEach(({ receipt, value }) => {
      console.log(receipt.id)
      console.log(value.amount)
    })

    // loading the second page
    return swp.getAllTransfers(accountId, { limit: "10", starting_after: pagination.cursor })
  })
  .then(({data}) =>
    data.forEach(({ receipt, value }) => {
      console.log(receipt.id)
      console.log(value.amount)
    })
  )
  .catch(error =>
    console.log(error)
  )
  String ACC_ID = "3394abe6b49b3d718f572829adf2d7f186520d35be9e746e8d3d9366145b2fe1";

  //get first page
  SuccessResponse<List<DataDTOReceipt<TransferDTO>>> resp =
      swp.getAllTransfers(ACC_ID, new PaginationParams(null, "3"));

  PaginationResponse pagination = resp.getPagination();

  resp.getData().forEach(it -> System.out.println(it.getValue().getId()));

  // Buscar próxima página
  swp.getAllTransfers(ACC_ID, new PaginationParams(String.valueOf(pagination.getCursor()), "3"))
     .getData()
     .forEach(it -> {
          System.out.println(it.getReceipt().getId());
          System.out.println(it.getValue().getId());
     });

Query all Transfers related to your Organization or child Account, including both sent and received Transfers.

GET /accounts/:id/transfers?limit=<limit>&starting_after=<starting_after>

URL parameters

Parameter Description
id ID da Conta ou da Organização

Query parameters

Parameter Description
limit (optional) Limit of items per page
starting_after (optional) Item ID from which the page should begin

Return

6. A specific Transfer Batch

curl -X GET \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  https://api.swipetech.io/transfers/44d351a02f2307153be74984a59675f2733ad5deb1fa9fb08b0a36fe3d15fd6d
swp.getTransfer("44d351a02f2307153be74984a59675f2733ad5deb1fa9fb08b0a36fe3d15fd6d")
  .then(({data}) =>
    data.value.actions.forEach(tf =>
      console.log(tf.amount)
    )
  )
  .catch(error =>
    console.log(error)
  )
  String TRANSFER_ID = "3394abe6b49b3d718f572829adf2d7f186520d35be9e746e8d3d9366145b2fe1";
  TransferBatchDTO batchDTO = swp.getTransfer(TRANSFER_ID).getData().getValue();
  TransferDTO transfer = batchDTO.getActions().get(0);

Query information on a Transfer batch related to your Organization or child Account.

GET /transfers/:id

URL parameters

Parameter Description
id Transfer batch ID

Return

Perform Actions

1. Create a new Account

curl -X POST \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  https://api.swipetech.io/accounts
swp.createAccount({
  // This field is optional. By default, all children Accounts support all of the Organization's Assets and have a starting balance of zero.
  starting_balances: [
    {
      asset_id: '07773f06becd47385d1e8d1e9bad3bd588ccd880fe746819257a6246e33551d3',
      balance: '1.99'
    }
  ]
})
.then(({data}) =>
  console.log(data.value.id)
)
.catch(error =>
  console.log(error)
)

   String ASSET_ID = "07773f06becd47385d1e8d1e9bad3bd588ccd880fe746819257a6246e33551d3";

   String STARTING_BALANCE = "1.99";

   AccountDTO accDTO = swp.createAccount(
           new CreateAccountBuilder()
           .addStartingBalance(ASSET_ID, STARTING_BALANCE)
           .addTag("tag10")
           .build()
   ).getData()
   .getValue();

POST /accounts

Body

NewAccount

Return

2. Issue an Asset

curl -X POST \
  https://api.swipetech.io/assets \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  -d '{"code": "TOKEN", "limit": "10000000"}'
swp.issueAsset({
  code: "TOKEN",
  limit: "10000000"
})
  .then(({data}) =>
    console.log(data.value.id)
  )
  .catch(error =>
    console.log(error)
  )
    String CODE = "TOKEN";
    String LIMIT = "100";
    List<String> TAGS = new ArrayList();

    AssetDTO assetDTO = swp.issueAsset(
            new NewAssetDTO(CODE, LIMIT, TAGS)
    ).getData().getValue();

POST /assets

Body

NewAsset

Return

3. Make batch Transfers

curl --request POST \
  -L https://api-sandbox.swipetech.io/transfers \
  -H 'accept: application/json' \
  -H 'accept-language: en-US' \
  -H 'content-type: application/json' \
  -H 'x-swp-api-key: <your api key>' \
  -H 'x-swp-signature: <request signature>' \
  -d '{"actions":[{"from":"269de13d714b253b88fdf18620c3194078f7932d48855efc6e4d6dc57528c84c","to":"b0ea341bd255aa27eb38ef136aebfcaaffbc87103d872a4a218df7b434f5a6ad","amount":"121.22","asset":"b6039b3fb9c3e30945644cc394e6b1accb0a6c2844514aad0819a89d64b0184c"}],"memo":"01234567"}'
import { memoHash, sha256 } from "@swp/swipe-sdk"

const memo = memoHash(sha256("1234567"))

// Note that this is a list, even though there may be only one Transfer
swp.makeTransfers({
  actions: [
    {
      from: "44d351a02f2307153be74984a59675f2733ad5deb1fa9fb08b0a36fe3d15fd6d",
      to: "55c86a9027f2ff8c5d6ed1e2dbda01886b8b33f461341533d7391c14abe7aa40",
      asset: "07773f06becd47385d1e8d1e9bad3bd588ccd880fe746819257a6246e33551d3",
      amount: "1000",
    }
  ],
  memo
})
  .then(({data}) => {
    data.value.actions.forEach(tf => {
      console.log(tf.amount)
    })
  })
  .catch(error => {
    console.log(error)

    // show index and error code of failed Transfers
    error.sub_errors
      .forEach((se, i) => {
        // it is possible to check which Transfer failed by its `index` field
        console.log(i, se.code, se.index)
      })
  })

String FROM = "44d351a02f2307153be74984a59675f2733ad5deb1fa9fb08b0a36fe3d15fd6d";
String TO = "55c86a9027f2ff8c5d6ed1e2dbda01886b8b33f461341533d7391c14abe7aa40";
String ASSET = "07773f06becd47385d1e8d1e9bad3bd588ccd880fe746819257a6246e33551d3";
String AMOUNT = "1000";

swp.makeTransfers(
        new NewTransferBatchDTO(
                Arrays.asList(
                        new NewTransferDTO(FROM, TO, ASSET, AMOUNT)
                ),
                new Memo(MemoType.TEXT.name(), "1234")
        )
);

Performs a list of Transfers atomically, which is to say, if one fails, all will fail.

Obs.: The optional memo field can be used for saving information on the network.

POST /transfers

Body

TransferBatch

Return

4. Destroy an Account

curl -X DELETE \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  https://api.swipetech.io/accounts/44d351a02f2307153be74984a59675f2733ad5deb1fa9fb08b0a36fe3d15fd6d
swp.destroyAccount(accountID)
  .then(({data}) =>
    console.log(data.value.id)
  )
  .catch(error =>
    console.log(error)
  )
String ACC_ID = "44d351a02f2307153be74984a59675f2733ad5deb1fa9fb08b0a36fe3d15fd6d";
SuccessResponse<DataDTOReceipt<AccountDTO>> resp = swp.destroyAccount(ACC_ID);

Destroys an Account. That Account must hold a balance of zero for all its Assets.

DELETE /accounts/:id

URL parameters

Parameter Description
id Account ID

Return

5. Action Batch

curl -X POST \
  https://api.swipetech.io/actions \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  -d '{"actions": [{"type": "CREATE_ACC"}, {"type": "ISSUE_ASSET", "code": "TOKEN", "limit": "10000"}, {"type": "TRANSFER", "from": "269de13d714b253b88fdf18620c3194078f7932d48855efc6e4d6dc57528c84c", "to": "b0ea341bd255aa27eb38ef136aebfcaaffbc87103d872a4a218df7b434f5a6ad", "asset": "b6039b3fb9c3e30945644cc394e6b1accb0a6c2844514aad0819a89d64b0184c", "amount": "100"}], "memo": "Memo"}'
swp.makeActionBatch({
  actions: [
    {
      type: "CREATE_ACC"
    },
    {
      type: "ISSUE_ASSET",
      code: "TOKEN",
      limit: "10000"
    },
    {
      type: "TRANSFER",
      from: "269de13d714b253b88fdf18620c3194078f7932d48855efc6e4d6dc57528c84c",
      to: "b0ea341bd255aa27eb38ef136aebfcaaffbc87103d872a4a218df7b434f5a6ad",
      asset: "b6039b3fb9c3e30945644cc394e6b1accb0a6c2844514aad0819a89d64b0184c",
      amount: "100"
    }
  ],
  memo: {
    type: "TEXT",
    value: "1234567"
  }
})


// It is also possible to build Actions using auxiliary functions
import { createAccountAction, issueAssetAction, transferAction, memoText } from "@swp/swipe-sdk"

const memo = memoText("1234567")

swp.makeActionBatch({
  actions: [
    createAccountAction(),
    issueAssetAction({
      code: "TOKEN",
      limit: "10000"
    }),
    transferAction({
      from: "269de13d714b253b88fdf18620c3194078f7932d48855efc6e4d6dc57528c84c",
      to: "b0ea341bd255aa27eb38ef136aebfcaaffbc87103d872a4a218df7b434f5a6ad",
      asset: "b6039b3fb9c3e30945644cc394e6b1accb0a6c2844514aad0819a89d64b0184c",
      amount: "100"
    })
  ],
  memo
})
String ASSET = "07773f06becd47385d1e8d1e9bad3bd588ccd880fe746819257a6246e33551d3";

String ISSUE_ASSET_CODE = "TOKEN";
String ISSUE_ASSET_LIMIT = "100";
List<String> ISSUE_ASSET_TAGS = null;

String TRANSFER_FROM = "44d351a02f2307153be74984a59675f2733ad5deb1fa9fb08b0a36fe3d15fd6d";
String TRANSFER_TO = "55c86a9027f2ff8c5d6ed1e2dbda01886b8b33f461341533d7391c14abe7aa40";

String TRANSFER_AMOUNT = "1000";

String CREATE_ACC_STARTING_BALANCE = "10";

ActionBatchDTO result = swp.makeActionBatch(
        new ActionBatchBuilder()
                .addIssueAsset(ISSUE_ASSET_CODE, ISSUE_ASSET_LIMIT, ISSUE_ASSET_TAGS)
                .addTransfer(TRANSFER_FROM, TRANSFER_TO, ASSET, TRANSFER_AMOUNT)
                .addCreateAccount(
                        new CreateAccountBuilder()
                            .addStartingBalance(ASSET, CREATE_ACC_STARTING_BALANCE)
                            .build()
                )
                .build()
).getData()
 .getValue();

Performs an Action Batch

Obs.: The optional memo field can be used for saving information on the network.

POST /actions

Body

ActionBatch

Return

Batch with Memo

import { createAccountAction, sha256 } from "@swp/swipe-sdk"

const memo1 = {
  type: "TEXT",
  value: "memo content"
}

const memo2 = {
  type: "HASH",
  value: sha256("memo content")
}

swp.makeActionBatch({
  actions: [
    createAccountAction(),
  ],
  memo: memo1 // -> tipo TEXT
  // memo: memo2 -> tipo HASH
})

// It's also possible to use a auxiliary functions
import { createAccountAction, memoText, memoHash, sha256 } from "@swp/swipe-sdk"

const memo1 = memoText("memo content")
const memo2 = memoHash(sha256("memo content"))

swp.makeActionBatch({
  actions: [
    createAccountAction(),
  ],
  memo: memo1 // -> tipo TEXT
  // memo: memo2 -> tipo HASH
})

// Use this function to check or generate a hash
const hash = sha256("memo content")
String ASSET = "07773f06becd47385d1e8d1e9bad3bd588ccd880fe746819257a6246e33551d3";

String TRANSFER_FROM = "44d351a02f2307153be74984a59675f2733ad5deb1fa9fb08b0a36fe3d15fd6d";
String TRANSFER_TO = "55c86a9027f2ff8c5d6ed1e2dbda01886b8b33f461341533d7391c14abe7aa40";

String TRANSFER_AMOUNT = "1000";

ActionBatchDTO result = swp.makeActionBatch(
        new ActionBatchBuilder()
                .addTransfer(TRANSFER_FROM, TRANSFER_TO, ASSET, TRANSFER_AMOUNT)
                .addMemo(new Memo(MemoType.TEXT.name(), "hello world!"))
                .build()
).getData()
 .getValue();

Every Action Batch may include a Memo field with additional information.

There are two types of Memo:

The API will return a validation error for a invalid value

Tags and filters

Accounts and Assets can have one or more tags, adding information for data organization purposes.

1. Specifying tags when creating Accounts or Assets

curl -X POST \
  -L https://api.swipetech.io/accounts \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  -d '{"tags":["supplier"]}'

curl -X POST \
  -L https://api.swipetech.io/assets \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  -d '{"code": "TOKEN", "tags":["supplier"]}'
swp.createAccount({tags: ["supplier"]})
  .then(({data}) =>
    console.log(data.value.tags)
  )
  .catch(error =>
    console.log(error)
  )

swp.issueAsset({
  code: "TOKEN",
  tags: ["supplier"]
})
  .then(({data}) =>
    console.log(data.value.tags)
  )
  .catch(error =>
    console.log(error)
  )

AccountDTO accDTO = swp.createAccount(
        new CreateAccountBuilder().addTag("supplier").build()
).getData().getValue();

String CODE = "TOKEN";
String LIMIT = "100";
AssetDTO assetDTO = swp.issueAsset(
        new NewAssetDTO(CODE, LIMIT, Arrays.asList("supplier"))
).getData().getValue();

The Actions for creating Accounts and issuing Assets have an optional parameter called tags. If specified, a tags string is applied to the created Accounts or Assets, which can be used to separate them into categories.

Each Account or Asset can hold a max of 10 tags.

Each tag has a limit ranging from 2 to 200 characters. Valid characters:

2. Change tags

curl -X PUT \
  -L https://api.swipetech.io/tags/44d351a02f2307153be74984a59675f2733ad5deb1fa9fb08b0a36fe3d15fd6d \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  -d '{"tags":["customer"]}'
const id = '44d351a02f2307153be74984a59675f2733ad5deb1fa9fb08b0a36fe3d15fd6d'

swp.updateTags(id, ["customer"])
  .then(({data}) =>
    console.log(data.value.tags)
  )
  .catch(error =>
    console.log(error)
  )
   String ACC_ID = "44d351a02f2307153be74984a59675f2733ad5deb1fa9fb08b0a36fe3d15fd6d";
   TagsDTO tags = swp.updateTags(ACC_ID, Arrays.asList("client")).getData().getValue();

PUT /tags/:id

Removes tags from an Account or Asset an replaces them by a new set of tags.

URL parameters

Parameter Description
id Account ID or Asset ID

Body

NewTags

Return

3. Filter Accounts by tag

# Filtering Accounts by tag
curl -X GET \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  https://api.swipetech.io/accounts?tag=supplier
// Filtering Accounts by tag
swp.getAllAccounts({ tag: "supplier" })
  .then(({data}) =>
    data.forEach(({value, receipt}) => {
      console.log(value.id)
      console.log(receipt.id)
    })
  )
  .catch(error =>
    console.log(error)
  )
  List<DataDTOReceipt<AccountDTO>> resp = 
      swp.getAllAccounts(null, new FilterDTO("supplier")).getData();

Filters Accounts that have a specific tag.

GET /accounts?tag=<tag>

URL parameters

Parameter Description
tag Tag to be filtered

Return

4. Filter Assets by tag

curl -X GET \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  https://api.swipetech.io/assets?tag=supplier
swp.getAllAssets({ tag: "crypto" })
  .then(({data}) =>
    data.forEach(({value, receipt}) => {
      console.log(value.id)
      console.log(receipt.id)
    })
  )
  .catch(error =>
    console.log(error)
  )
     List<DataDTOReceipt<AssetDTO>> resp = 
          swp.getAllAssets(null, new FilterDTO("supplier")).getData();

Filters Assets that have a specific tag.

GET /assets?tag=<tag>

URL parameters

Parameter Description
tag Tag to be filtered

Return

Others

1. Reset Organization (available only on the sandbox environment)

curl -X DELETE \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  https://api.swipetech.io/organizations
swp.resetOrganization()
  .then(() =>
    console.log("Done!")
  )
  .catch(error =>
    console.log(error)
  )
  swp.resetOrganization();

This function returns the Organization to its initial state, which means:

DELETE /organizations

2. Revoke a credential pair

Revokes a credential pair, making them invalid and disabling access to the application.

# Searches for the revocation token
curl -X GET \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  https://api.swipetech.io/organizations/revoke

# Performs the revoking  
curl -X POST \
  -H "Content-Type: application/json" \
  -H "X-Swp-Api-Key: <your api key>" \
  -H "X-Swp-Signature: <request signature>" \
  https://api.swipetech.io/organizations/revoke/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJUeXBlIjoiUkVWT0tFIENSRURFTlRJQUxTIiwiZXhwIjoxNTUwODYyNjY2LCJUaW1lc3RhbXAiOjE1NTA4NjIzNjZ9.s9UbrJmWQXVpIeXAb9gjWwRe19iWV1gYIaoxXOQ0_1A
swp.getToken()
  .then(({data}) => {
      console.log(data.value.token)
      // eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJUeXBlIjoiUkVWT0tFIENSRURFTlRJQUxTIiwiZXhwIjoxNTUwODYyNjY2LCJUaW1lc3RhbXAiOjE1NTA4NjIzNjZ9.s9UbrJmWQXVpIeXAb9gjWwRe19iWV1gYIaoxXOQ0_1A

      return swp.revokeCredentials(data.value.token)
  })
  .then(() => console.log("Revoking successful"))
  .catch(error =>
    console.log(error)
  )
     ResponseToken respToken = swp.getToken().getData().getValue();
     swp.revokeCredentials(respToken.getToken()).getData();

This function happens in 2 steps. First, a revocation token (valid for 5 minutes) is searched:

GET /organizations/revoke

Return

Then, the obtained token is used to act out the revoking:

POST /organizations/revoke/:token

URL parameters

Parameter Description
token Revocation token

Return

Error handling

An error has fields that help finding the cause of the problem.

code

The code field shows the error group. Most groups have a sub_errors field with more specific details. The groups are the following:

msg

This field has a human-readable message about the cause of the problem.

sub_errors

sub_errors has a list of sub-errors with specific details on the cause of the problem. Similarly to errors, it carries the fields code, msg (and field in case of a validation error):

not_found

validation_error

transfer_error

unauthorized

Supported languages

const en_us = Swipe.languages.EN_US
const pt_br = Swipe.languages.PT_BR

The language is used to set the API response messages. Currently we support:

Entities

SuccessResponse<T>

interface SuccessResponse<T> {
  data?: T
  pagination?: Pagination
  error: Error
}
Field Type Description
data T (optional) Response information
pagination Pagination (optional) Pagination information
error Error

Pagination

interface Pagination {
  cursor: string
}
Field Type Description
cursor Value that can be used to look up the next page

Data<T>

interface Data<T> {
  receipt: Receipt
  value: T
}
Field Type Description
receipt Receipt Receipt of the Action
value T Generic type that depends on context

Receipt

interface Receipt {
  id: string
  created_at: string
  type: ActionType
}
Field Type Description
id string Receipt ID
created_at string Receipt creation date
type ActionType Action type

ActionType

swp.actionTypes.Transfer             // "transfer"
swp.actionTypes.CreateAccount        // "create_account"
swp.actionTypes.CreateOrganization   // "create_organization"
swp.actionTypes.IssueAsset           // "issue_asset"
swp.actionTypes.DestroyAccount       // "destroy_account"
Constant Description
transfer Transfer
create_account Creation of a new Account
destroy_account Destruction of an Account
create_organization Creation of an Organization
issue_asset Issuing of an Asset

Organization

interface Organization extends Account {
  name: string
}
Field Type Description
id string Organization ID
name string Name
balances Balance[] List of balances held by the Organization for all its Assets

Account

interface Account {
  id: string
  type?: string
  balances: Balance[]
  tags?: string[]
  fields: {[key: string]: string}
}
Field Type Description
id string Account ID
type string String with value CREATE_ACC, used for identifying the Action type at serialization/deserialization
balances Balance[] List of balances for all Assets supported by the Account
tags string[] List of tags
fields {[key: string]: string} Key-value fields used for storing information about the Account

NewAccount

interface NewAccount {
  type?: string
  starting_balances?: StartingBalance[]
  tags?: string[]
  fields: {[key: string]: string}
}
Field Type Description
type string String with value CREATE_ACC, used for identifying the Action type at serialization/deserialization
starting_balances StartingBalance[] List of Assets to be supported by the new Account with its respective starting balances
tags string[] List of tags
fields {[key: string]: string} Key-value fields used for storing information about the Account

Asset

interface Asset {
  id: string
  code: string
  limit: string
  tags: string[]
  type?: string
}
Field Type Description
id string Asset ID
code string Text between 4 and 12 characters, used for representing the Asset
limit string Max amount of the Asset to be issued
tags string[] List of tags related to the Asset
type string String with value ISSUE_ASSET, used for identifying the Action type at serialization/deserialization

NewAsset

interface NewAsset {
  code: string
  limit: string
  tags?: string[]
  type?: string
}
Field Type Description
code string Text between 4 and 12 characters, used for representing the Asset
limit string Max amount of the Asset to be issued
tags string[] List of tags to be related to the Asset
type string String with value ISSUE_ASSET, used for identifying the Action type at serialization/deserialization

TransferBatch

interface TransferBatch {
  id: string
  actions: Transfer[]
  memo?: MemoValue
}
Field Type Description
id string Transfer ID
actions Transfer[] List of Transfers included in the transaction
memo MemoValue Batch memo

MemoValue

interface MemoValue {
  type: "TEXT" | "HASH"
  value: string
}
Field Type Description
type string Memo type
value string Memo value

Transfer

interface Transfer {
  id: string
  from: string
  to: string
  asset: string
  amount: string
  op_code: OperationCode
  type?: string
}
Field Type Description
id string Transfer ID for queries
from string Sender ID
to string Receiver ID
amount string Value to be transferred
asset string Operation Asset ID
action_code ActionCode Action response code
type string (optional) String with value TRANSFER, used for identifying the Action type at serialization/deserialization

NewTransfer

interface NewTransfer {
  from: string
  to: string
  amount: string
  asset: string
  type?: string
}
Field Type Description
from string Sender ID
to string Receiver ID
amount string Value to be transferred
asset string Operation Asset ID
type string String with value TRANSFER, used for identifying the Action type at serialization/deserialization

ActionCode

swp.actionCodes.Ok            // "action_ok"
swp.actionCodes.Success       // "action_success"
swp.actionCodes.Underfunded   // "action_underfunded"
swp.actionCodes.NotProcessed  // "action_not_processed"
Constant Description
op_ok Valid operation
op_success Operation fulfilled successfully
op_underfunded Insufficient balance
op_not_processed Invalid operation

StartingBalance

interface StartingBalance {
  balance: string
  asset_id: string
}
Field Type Description
asset_id string Asset ID
balance string Current Asset balance

Balance

interface Balance {
  balance: string
  asset_code: string
  asset_id: string
}
Field Type Description
asset_code string Asset code
asset_id string Asset ID
balance string Current Asset balance

NewTags

interface NewTags {
  tags: string[]
}
Field Type Description
tags string[] Tags array

Tags

interface Tags {
  id: string
  tags: string[]
}
Field Type Description
id string ID of the entity that holds tags
tags string[] Tags array

Error

interface Error {
  code: string
  msg: string
  sub_errors: SubError[]
}
Field Type Description
code string Code that identifies the cause of the problem
msg string Translated message
sub_errors SubError[] List of sub-errors. Each sub-error has more detailed information about the cause of the problem

SubError

interface Error {
  code: string
  msg: string
  field: string
  index: number
}
Field Type Description
code string Code that identifies the cause of the problem
msg string Translated message
field string Field related to the error (only in case of validation_error)
index number Field that identifies which operation failed in the Transfer (only in case of transfer_failed)

ActionBatch

interface ActionBatch {
  id?: string
  actions: Array<NewAccount | NewAsset | NewTransfer>
  memo?: MemoValue
}
Field Type Description
id string Batch ID for queries
actions Array<NewAccount | NewAsset | NewTransfer> List with Actions to be performed
memo MemoValue Batch Memo

ResponseToken

interface ResponseToken {
  token: string
}
Field Type Description
token string Token value

Changelog

Follow code changes on the javascript tab on the right.

v0.9.0

Novas funcionalidades

Breaking changes

API

v0.8.0

New features

Bugfixes

Breaking changes

API

SDK for Node.js

  interface NewTransferBatch {
    actions: NewTransfer[]
    memo?: string
  }

  interface NewTransfer {
    from: string
    to: string
    asset: string
    amount: string
  }
interface Response<T> {
  data: T
  error: Error
}

interface DataReceipt<T> {
  value: T
  receipt: Receipt
}
interface ResponseList<T> {
  data: DataReceipt<T>[]
  pagination: PaginationResponse
  error: Error
}

interface PaginationResponse {
  cursor: number
}

Contact

Do you have any questions, suggestions, or would you like to test our solution? Contact us on the following channels: