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:
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.
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.
constrpcURL="https://rpc.tst.publicmint.io:8545"
constrpcURL="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.
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")constweb3=newPublicMint();// 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).constwalletAccountPrivateKey1="0xba6cdfcc795484a9774eb98e756983da822ef3481b37d4ba649864e2d1ab4e5e"; // Add your private key.wallet.add(walletAccountPrivateKey1);// Withdrawals// Withdraw 1 USD this is eq to '1000000000000000000' tokens.consttokensToWithdraw=toToken('1');constwithdrawType=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.constreferenceFromApi=sha256('REF FROM API');constreceipt=awaitUSD.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.constreferenceFromApi='8471e769-5bc3-4531-a320-bdcab1ceea50';constreceipt=awaitUSD.withdrawWireInt(tokensToWithdraw, referenceFromApi, withdrawType).send({ from:"0x4389Af2E0515dDFe3453B1bD748aDfD5e2598cFd",});
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 */functionwithdrawWireUS(uint256 amount, string memory ref)publicreturns (bool) {_burn(msg.sender, amount);// feeType WireUS emit Withdraw(msg.sender, amount, ref, feeTypeWireUS);returntrue; }/** * Withdraw method of type wire transfer for international * @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 */functionwithdrawWireInt(uint256 amount, string memory ref)publicreturns (bool) {_burn(msg.sender, amount);// feeType WireInt emit Withdraw(msg.sender, amount, ref, feeTypeWireInt);returntrue; }/** * Withdraw method of type ACH 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 */functionwithdrawAchUS(uint256 amount, string memory ref)publicreturns (bool) {_burn(msg.sender, amount);// feeType AchUS emit Withdraw(msg.sender, amount, ref, feeTypeAchUS);returntrue; }
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.