Withdrawing

Request a fiat withdrawal from a blockchain address.

The same requirements for depositing also apply to withdrawing fiat. Here's what you need:

Step 1: Verify user KYC status & add transfer method

In case you haven't yet done so, start by submitting your documents as explained here. If you haven't passed KYC, or if you're initiating a withdrawal on behalf of a user but are unsure about their verification status, follow these steps to verify the identity's KYC status now.

If the response returns identityConfirmed: true you can go ahead with the flow.

Step 2: Activate required operations

In order to use the transfer methods you will need to activate the operations. The available operations are:

'deposit:wire',
'deposit:stablecoin',
'withdrawal:wire',
'withdrawal:stablecoin'
POST <hostname>/operations/activate

{
    "identityId": "{{identityId}}",
    "code": ["withdrawal:wire"]
}

Step 3: Create a transfer method

To be able to execute a withdrawal you need to indicate what is the transfer method that is to be used for the transaction. As the execution is done directly on the blockchain, we require that all the destination details are previously supplied to be able to process them.

To create a new transfer method, you should make a POST request to the transfer method endpoint.

POST <hostname>/v2/transfer-methods

{
  "bankAccountName": "foobar",
  "bankAccountNumber": "GB94BARC10201530093459",
  "bankName": "Royal bank",
  "identityId": "87e5d63a-c92a-4f2f-a869-bb7119d0f0a0",
  "swiftCode": "BKBKESMMXXX" ,
  "type": "internationalWire"
}

This endpoint will return a response like the one below. The id is needed in the next step, when burning the USD in the blockchain.

{
  "data": {
    "appId": "e86755c5-f997-443e-992c-67f2866278aa",
    "createdAt": "2022-06-09T18:08:27.604Z",
    "deletedAt": null,
    "externalReference": "76559632-442a-4a78-89e3-b4960cf0cd73",
    "id": "8471e769-5bc3-4531-a320-bdcab1ceea50",
    "identityId": "87e5d63a-c92a-4f2f-a869-bb7119d0f0a0",
    "metadata": {
      "bankName": "Royal bank",
      "swiftCode": "BKBKESMMXXX",
      "bankAccountName": "foobar",
      "bankAccountNumber": "GB94BARC10201530093459"
    },
    "type": "internationalWire",
    "updatedAt": "2022-06-09T18:08:29.211Z"
  }
}

Step 3: Call withdrawal function on token contract

For this step, start by making a call to the tokenized fiat contract requesting the burning of the tokens you want to withdraw. To do that, follow the instructions for integrating with the blockchain as explained in the blockchain section.

This guide assumes you have Node.js installed, using npm package manager to install the publicmint-web3.js as detailed in the corresponding section. To instantiate a connection with Public Mint node, use the code below.

Note: In November 1st, the previous withdrawal flow that used the API reference will be deprecated. To use the new flow with the Public Mint NPM, you will need to upgrade to the version 3.0.0.

const rpcURL = "https://rpc.tst.publicmint.io:8545"

Once you've set up a web3 connection to Public Mint's blockchain, run this code on your server to trigger the burning of tokens on-chain at Public Mint's token contract.

The referenceFromApi in the example below is the ID of the transfer method created on the previous step. Note that you only need to create the transfer method once and use it as many times as you want.

BURNING TOKENS
// Import Public Mint web3 interface.
import PublicMint from '@publicmint/publicmint-web3';

// Create web3 umbrella class with PublicMint namespace `pm`.
// By default is "ws" and <2020> - <mainNet>, only 'ws' provider it's possible listen events.
// For <testNet> or chainID <2019> and http service provider see example bellow.
// const web3 = new PublicMint(2019, "http")
const web3 = new PublicMint();

// Blockchain wallet operations.
const { wallet } = web3.pm

// Utils for hashing and convert dollar amount to small token unit "wei".
const { toToken, sha256 } =  web3.pm.utils;

// USD is the interface for ERC20 smart contract.
const { USD } = web3.pm.contracts.token

// Add blockchain account ('0x4389Af2E0515dDFe3453B1bD748aDfD5e2598cFd' as example).
const walletAccountPrivateKey1 = "0xba6cdfcc795484a9774eb98e756983da822ef3481b37d4ba649864e2d1ab4e5e"; // Add your private key.
wallet.add(walletAccountPrivateKey1);

// Withdrawals
// Withdraw 1 USD this is eq to '1000000000000000000' tokens.
const tokensToWithdraw = toToken('1');
const withdrawType = sha256('ACH');

// DEPRECATED - pmint npm < 3.0.0
// !!! SEE BELLOW MORE INFO ABOUT THIS API REFERENCE !!!
// API from Public Mint will provide a reference for each withdraw for your account.
const referenceFromApi = sha256('REF FROM API');
const receipt = await USD.withdrawWireInt(tokensToWithdraw, referenceFromApi, withdrawType).send({
    from: "0x4389Af2E0515dDFe3453B1bD748aDfD5e2598cFd",
});

// NEW FLOW - pmint npm >= 3.0.0
// The new API reference will be the UUID of the created transfer method.
const referenceFromApi = '8471e769-5bc3-4531-a320-bdcab1ceea50';
const receipt = await USD.withdrawWireInt(tokensToWithdraw, referenceFromApi, withdrawType).send({
    from: "0x4389Af2E0515dDFe3453B1bD748aDfD5e2598cFd",
});

 

If successful, the function will emit an event, which is then captured by Public Mint's event listener.

After that, the tokens will be burned (destroyed) by the token contract.

Available withdrawals:

  • withdrawAchUS

  • withdrawWireInt

  • withdrawWireUS

The interface is equal for all withdraw methods has the same parameters as example above.

See here more about withdrawals methods and unique costs.

Last updated