Search…
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: Create withdrawal via API (ACH, Wire and International Wire)

To create a withdrawal request, 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.
1
POST {hostname}:{port}/withdrawals
2
3
// Body
4
5
{
6
"blockchainAddress": "0x8ba13aB181E9F30e543C6376Cd408192E95bCD1C",
7
"currency": "USD",
8
"identityId": "e65dde2c-4379-42c7-a665-3f476cebb691",
9
"transferInformation": {
10
"transferType": "wire",
11
"bankAccountName": "Jonh do bank",
12
"bankAccountNumber": "1321312312321312",
13
"routingNumber": "123456789"
14
}
15
}
Copied!
This endpoint will return a response like the one below. The transactionReference is needed in the next step, when burning the USD in the blockchain.
Response
1
{
2
"id": "2642dedd-4fa0-40bf-8b15-7c0513bcdb38",
3
"identityId": "e65dde2c-4379-42c7-a665-3f476cebb691",
4
"transactionReference": "0xf6cce2d20d2714fa7be8e1bb8b8cf0abbb12ca3d34d000073742a4da954c1be5",
5
"blockchainAddress": "0x8ba13aB181E9F30e543C6376Cd408192E95bCD1C",
6
"amount": null,
7
"currency": "USD",
8
"transactionHash": null,
9
"transferInformation": {
10
"transferType": "wire",
11
"bankAccountName": "Jonh do bank",
12
"bankAccountNumber": "1321312312321312",
13
"routingNumber": "123456789"
14
},
15
"status": "prepared",
16
"createdAt": "2020-02-19T11:43:04.553Z",
17
"updatedAt": "2020-02-19T11:43:04.553Z"
18
}
Copied!
Also, 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.
1
GET {hostname}:{port}/withdrawals/:identityId/:id
2
3
// Withdrawal
4
{
5
"id": "03e1dcd4-882d-4320-9798-1b56fd3cd737",
6
"app_id": "57198e8a-6b20-4936-b52b-669fca0ee72a",
7
"identity_id": "7c8867d7-b9b8-40de-86c7-f4a8e4ee566d",
8
"transfer_method_id": "ce327b6a-bc77-4770-a15c-eec976afc697",
9
"amount": "1.000000000000",
10
"blockchain_address": "0x0d7f2d24a308d99f743f3683cdf8778f049d15b5",
11
"description": "",
12
"currency": "USD",
13
"txid": "0x013420a73af0884c415af39473b499a45ee78712ed027ca0338e3547553f6601",
14
"status": "waiting",
15
"payment_details": null,
16
"transaction_number": null,
17
"special_type": null,
18
"web_hook_url": "https://enfp40vp60yhq.x.pipedream.net",
19
"external_id": null,
20
"external_system": null,
21
"integ_status": "waiting",
22
"integ_messages": null,
23
"created_at": "2019-11-08T12:30:50.225Z",
24
"updated_at": "2019-11-08T12:30:50.225Z"
25
}
Copied!

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:
REMOTE HOST
LOCAL HOST
1
const rpcURL = "https://rpc.tst.publicmint.io:8545"
Copied!
1
const rpcURL = "https://localhost:8545"
Copied!
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
BURNING TOKENS
1
import PublicMint from '@publicmint/publicmint-web3';
2
3
// Create web3 umbrella class with PublicMint namespace `pm`
4
// By default is "ws" and <2020> - <mainNet>, only 'ws' provider it's possible listen events.
5
const web3 = new PublicMint();
6
7
// For <testNet> or chainID <2019> and http service provider see example bellow
8
// const web3 = new PublicMint(2019, "http")
9
10
// Add your private key
11
12
const {
13
wallet
14
} = web3.pm
15
16
17
// Add first account
18
19
// 0x4389Af2E0515dDFe3453B1bD748aDfD5e2598cFd
20
const walletAccountPrivateKey1 = "0xba6cdfcc795484a9774eb98e756983da822ef3481b37d4ba649864e2d1ab4e5e";
21
wallet.add(walletAccountPrivateKey1);
22
23
// Utils for hashing and convert dollar amount to small token unit "wei"
24
const {
25
toToken, sha256
26
} = web3.pm.utils;
27
28
// USD is the interface for ERC20 smart contract.
29
const {
30
USD
31
} = web3.pm.contracts.token
32
33
34
// Withdrawals
35
36
// withdraw 1 USD this is eq to '1000000000000000000' tokens
37
const tokensToWithdraw = toToken('1');
38
39
// !!! SEE BELLOW MORE INFO ABOUT THIS API REFERENCE !!!
40
// API from Public Mint will provide a reference for each withdraw for your account
41
const referenceFromApi = sha256('REF FROM API');
42
const withdrawType = sha256('ACH');
43
44
const receipt = await USD.withdrawWireInt(tokensToWithdraw, referenceFromApi, withdrawType).send({
45
from: "0x4389Af2E0515dDFe3453B1bD748aDfD5e2598cFd",
46
});
47
48
49
50
Copied!
This is the withdrawal() function from the token smart contract that you must invoke:
1
2
/**
3
* Withdraw method of type wire transfer for US
4
* @dev Destroys `amount` tokens from `account` as msg.sender, reducing the
5
* total supply for this ERC20.
6
* @param amount How much to withdraw from sender balance.
7
* @param ref This is an reference given by api, this value need to be on
8
* blockchain logs just for tracking user actions.
9
* Emits a `Withdraw` event with the `from`, `amount`, `ref`, `feeType`.
10
* Emits a `Transfer` event with `to` set to the zero address.
11
*
12
* Requirements
13
*
14
* - `account` cannot be the zero address.
15
* - `account` must have at least `amount` tokens.
16
* @return bool
17
*/
18
function withdrawWireUS(uint256 amount, bytes32 ref) public returns (bool) {
19
// feeType WireUS
20
emit Withdraw(
21
msg.sender,
22
amount,
23
ref,
24
0x829127e4aac99498548e3e4e797af4fd752333e432a480161e9c19f9e5fbd280
25
);
26
_burn(msg.sender, amount);
27
return true;
28
}
29
Copied!
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 withdrawals:
    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 4: Submit 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.
1
POST {hostname}:{port}/withdrawals/e65dde2c-4379-42c7-a665-3f476cebb691/submit
2
3
// Body
4
5
{
6
"transactionReference": "0x8722597478bb2ab2964576b9509941269642c2d960ac7bc452cd8cd5f9e64f2e",
7
}
Copied!
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.
1
GET {hostname}:{port}/withdrawals/:identityId/:id
2
3
// Withdrawal
4
{
5
"id": "03e1dcd4-882d-4320-9798-1b56fd3cd737",
6
"app_id": "57198e8a-6b20-4936-b52b-669fca0ee72a",
7
"identity_id": "7c8867d7-b9b8-40de-86c7-f4a8e4ee566d",
8
"transfer_method_id": "ce327b6a-bc77-4770-a15c-eec976afc697",
9
"amount": "1.000000000000",
10
"blockchain_address": "0x0d7f2d24a308d99f743f3683cdf8778f049d15b5",
11
"description": "",
12
"currency": "USD",
13
"txid": "0x013420a73af0884c415af39473b499a45ee78712ed027ca0338e3547553f6601",
14
"status": "waiting",
15
"payment_details": null,
16
"transaction_number": null,
17
"special_type": null,
18
"web_hook_url": "https://enfp40vp60yhq.x.pipedream.net",
19
"external_id": null,
20
"external_system": null,
21
"integ_status": "waiting",
22
"integ_messages": null,
23
"created_at": "2019-11-08T12:30:50.225Z",
24
"updated_at": "2019-11-08T12:30:50.225Z"
25
}
Copied!
Withdrawals may take a few days, depending on the method and banks involved.

USDC Withdrawals

The USDC withdrawals are processed with a different flow than the other withdrawal types. In this case, the withdrawal process is started by the BURN operation. This can me done using the script in the Step 3, changing the contract method to withdrawToUSDC
1
await USD.withdrawToUSDC(tokensToWithdraw, targetAddress, 1).send({
2
from: "<Wallet address here>",
3
});
Copied!
This operation will initiate the withdraw flow in the core services without the need to call API endpoints.
Last modified 4mo ago