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 verification_status: approved and you have a transfer method associated with your identity, then you're good to go - skip to the next step.

Step 2: 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 Pubic Mint node, use the code below:

REMOTE HOST
LOCAL HOST
REMOTE HOST
const rpcURL = "https://rpc.tst.publicmint.io:8545"
LOCAL HOST
const rpcURL = "https://localhost: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:

Node.js
Solidity function
Node.js
BURNING TOKENS
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.
const web3 = new PublicMint();
// For <testNet> or chainID <2019> and http service provider see example bellow
// const web3 = new PublicMint(2019, "http")
// Add your private key
const {
wallet
} = web3.pm
// Add first account
// 0x4389Af2E0515dDFe3453B1bD748aDfD5e2598cFd
const walletAccountPrivateKey1 = "0xba6cdfcc795484a9774eb98e756983da822ef3481b37d4ba649864e2d1ab4e5e";
wallet.add(walletAccountPrivateKey1);
// 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
// Withdrawals
// withdraw 1 USD this is eq to '1000000000000000000' tokens
const tokensToWithdraw = toToken('1');
// !!! 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 withdrawType = sha256('ACH');
const receipt = await USD.withdrawWireInt(tokensToWithdraw, referenceFromApi, withdrawType).send({
from: "0x4389Af2E0515dDFe3453B1bD748aDfD5e2598cFd",
});
Solidity function

This is the withdrawal() function from the token smart contract that you must invoke:

/**
* Withdraw method of type wire transfer for US
* @dev Destroys `amount` tokens from `account` as msg.sender, reducing the
* total supply for this ERC20.
* @param amount How much to withdraw from sender balance.
* @param ref This is an reference given by api, this value need to be on
* blockchain logs just for tracking user actions.
* Emits a `Withdraw` event with the `from`, `amount`, `ref`, `feeType`.
* Emits a `Transfer` event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
* @return bool
*/
function withdrawWireUS(uint256 amount, bytes32 ref) public returns (bool) {
// feeType WireUS
emit Withdraw(
msg.sender,
amount,
ref,
0x829127e4aac99498548e3e4e797af4fd752333e432a480161e9c19f9e5fbd280
);
_burn(msg.sender, amount);
return true;
}

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. Make sure to take note of the transactionHash as you'll need to use it for the withdrawal API request.

Available withdrawls:

  • withdrawAchUS

  • withdrawWireInt

  • withdrawWireUS

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

The PublicMint api will give a correct referenceFromApi parameter to withdrawal tokens don't generate by your self, this can cause a lost of tokens.

See here more about withdrawals methods and unique costs.

Step 3: Create withdrawal via API

Use the txid output from the token burn transaction along with your verified Pubic Mint id in the withdrawal request to the API.

To do that, you should make a POST request to the withdrawals endpoint. If you haven't yet done so, you'll have to submit your documents and undergo KYC before being able to withdraw.

POST {hostname}:{port}/withdrawals
// Body
{
"amount": "10",
"currency": "USD",
"description": "dsadsdasd",
"identityId": "13039c46-2f46-45ec-884e-b58df7fe01af",
"transferMethodId": "e686ba4e-fd95-46ba-b8f7-74711745562b",
"txid": "0x51d513b7e08b412e6d3f45294490bc379f2211c14c23519620d1af57415837ef"
}

You can fetch a list of an identity's withdrawals by querying the API with a GET request to the /withdrawals endpoint. You can get a list for your own withdrawals at GET /withdrawals or for a given identityId at GET /withdrawals/identity/:id.

GET {hostname}:{port}/withdrawals/:identityId/:id
// Withdrawal
{
"id": "03e1dcd4-882d-4320-9798-1b56fd3cd737",
"app_id": "57198e8a-6b20-4936-b52b-669fca0ee72a",
"identity_id": "7c8867d7-b9b8-40de-86c7-f4a8e4ee566d",
"transfer_method_id": "ce327b6a-bc77-4770-a15c-eec976afc697",
"amount": "1.000000000000",
"blockchain_address": "0x0d7f2d24a308d99f743f3683cdf8778f049d15b5",
"description": "",
"currency": "USD",
"txid": "0x013420a73af0884c415af39473b499a45ee78712ed027ca0338e3547553f6601",
"status": "waiting",
"payment_details": null,
"transaction_number": null,
"special_type": null,
"web_hook_url": "https://enfp40vp60yhq.x.pipedream.net",
"external_id": null,
"external_system": null,
"integ_status": "waiting",
"integ_messages": null,
"created_at": "2019-11-08T12:30:50.225Z",
"updated_at": "2019-11-08T12:30:50.225Z"
}

Withdrawals may take a few days, depending on the method and banks involved.