Payout Service

Step-by-step example of how to setup and use Public Mint for Payouts

In this example we'll show how to use our APIs to easily implement a payout service based on Public Mint's services and blockchain.

Before you start

Public Mint's service APIs offer a series of methods that can be used to integrate with Public Mint services and blockchain. Before you start, it's recommended that you review the full documentation available online on developers.publicmint.io.

Become a Partner

To use Public Mint's services, you need to be registered as partner and have the API Key to access the APIs. Please contact support@publicmint.com to apply.

Environments

Public Mint has two publicly available environments that can be used by anyone: production and sandbox

Production

The Production environment is Public Mint's main environment for partners and users. It's connected to real banks and KYC verification systems.

Sandbox

The Sandbox environment is targeted for integration development by Partners and others that want to use Public Mint's services and blockchain. It's not connected to KYC verification systems or actual banking rails.

Creating an Address

In order to execute payouts on the blockchain, the first step is to create and prepare an address from which the transfer will be executed. Please check out our tutorial on how to Create a Blockchain Address.

For this example, we'll also set up an address to be the liquidity pool from where payouts will be executed, and which will be replenished as funds come in via FIAT. This allows for payouts that are effectively independent from the actual deposit of funds (within the limits of the funds preloaded into the pool).

Account Identity

On Public Mint, all fiat transactions must be associated with a previously KYC-verified identity. There are three ways to obtain such an identity:

  • As a Partner, you'll have an identity automatically created during registration, which you can use in conjunction with your API Key. Seeing as funds in the liquidity pool address are your own, you can use your own identity when loading funds;

  • If you are using the Public Mint Widget, you can skip this section, as the widget will handle the identity generation automatically.

  • If you prefer to have users provide their personal identification details to you, you can create an Identity for each of your users by forwarding that data to our API, therefore allowing your customers to deposit funds directly into an address. Please check our tutorial on how to create identities via our API.

Making the First Deposit

With an address assigned to our liquidity pool and an identity for deposits, you can now make a fiat deposit so that you have an initial amount available for the payout.

In this example, we'll use a bank wire transfer for the deposit. Read about other transfer methods here.

Example

Request
curl -X POST \
  [ENVIRONMENT HOSTNAME]/deposits \
  -H 'Content-Type: application/json' \
  -H 'apikey: {INSERT API KEY HERE}' \
  -d '{
	"amount": "12",
	"currency": "USD",
	"identityId": "4da8aa4f-4a01-4bf6-a72d-a8bac268c304",
	"blockchainAddress": "0xA4597E696a55fD76430945e0940DA17c72337ccC",
	"transferInformation": {
		"transferType": "wire"
	}
}'
Response
{
    "id": "cd132ff7-1f19-4144-9d92-e30fa65df2a2",
    "identity_id": "4da8aa4f-4a01-4bf6-a72d-a8bac268c304",
    "status": "waiting",
    "reference": "CUSFGRA",
    "transfer_type": "wire",
    ...
}

At the moment the deposit is created, the reference field is initially set to null.

As this is an async operation, the response will be returned via POST request to the partner's webhook URL. Alternatively, you can make a GET request to the /deposits/:id endpoint, where :id is the id returned from the deposit POST call. Read more about it here.

The reference should then be used for making the wire transfer to Public Mint's bank account.

Make sure to include the reference on the transfer description, and that the origin account is held by the same identity you used to create the deposit.

Sandbox

In the sandbox environment, you can bypass the deposit settlement process with a manual settlement. To do that, you need to make a POST request to the /deposits/:id/sandbox-settle-depositendpoint. Note that this is only possible in the sandbox environment.

Example

Request
curl -X POST \
  https://api.sandbox.publicmint.io/deposits/cd132ff7-1f19-4144-9d92-e30fa65df2a2/sandbox-settle-deposit \
  -H 'Content-Type: application/json' \
  -H 'apiKey: [MY_API_KEY]' \
  -d '{
	"amount": "50000",
	"status": "settled"
}'
Response
{
    "message": "Deposit settled"
}

Requesting a Payout

Now that the liquidity pool address has funds, you can request payouts from the blockchain. Doing so is as simple as making a transfer between your blockchain account and the destination account.

Example

// Initialising Web3

const Web3 = require('web3');
const provider = 'https://public.tst.publicmint.io:8545'; // Public Mint TestNet Blockchain
const opts = {
    defaultBlock: 'latest',
    transactionConfirmationBlocks: 1,
}
const web3 = new Web3(provider, null, opts);

// Blockchain account address.
const address = '0xFF206CeBAC998aEC817E7fc456fc3451eEEaA860';

// Blockchain account private key.
const accountPK = '0x93bdf0a31e3069243bb7ccf65056d2d0c526deaf5f4d3d3bc78c7a163c9136e4';
const destAddress = '0xEa3F2eb61dD221344834eA6a3fd2128dF6641D4E';

// Building transaction
(async function () {
 const contract = new web3.eth.Contract(contractABI, ERC20_USDP_ADDR, {
   from: address
 });
   const account = web3.eth.accounts.privateKeyToAccount(accountPK);
   const entropy = '54674321§3456764321§345674321§3453647544±±±§±±±!!!43534534534534';
   const wallet = web3.eth.accounts.wallet.create(1, entropy);

   wallet.add(account);
   const amountToSend = web3.utils.toHex(web3.utils.toWei('10.00', 'ether'));
   const result = await contract.methods.transfer(destAddress,amountToSend).send({
     from: address
   });
   console.log(result)
})();

When the pool gets low on funds, all you need is to make a new deposit and you're set.

Last updated