This is a pure PHP SDK for working with Minter blockchain
composer require minter/minter-php-sdk
You can get all valid responses and full documentation at Minter Node Api
Create MinterAPI instance
use Minter\MinterAPI;
$nodeUrl = 'https://minter-node-1.testnet.minter.network:8841'; // example of a node url
$api = new MinterAPI($nodeUrl);
Returns coins list, balance and transaction count (for nonce) of an address.
getBalance(string $minterAddress, ?int $height = null): \stdClass
$api->getBalance('Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee99')
// {"jsonrpc": "2.0", "id": "", "result": { "balance": { ... }, "transaction_count": "0"}}
Returns next transaction number (nonce) of an address.
getNonce(string $minterAddress): int
$api->getNonce('Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee99')
Returns the result of sending signed tx.
send(string $tx): \stdClass
$api->send('f873010101aae98a4d4e540000000000000094fe60014a6e9ac91618f5d1cab3fd58cded61ee99880de0b6b3a764000080801ca0ae0ee912484b9bf3bee785f4cbac118793799450e0de754667e2c18faa510301a04f1e4ed5fad4b489a1065dc1f5255b356ab9a2ce4b24dde35bcb9dc43aba019c')
Returns node status info.
getStatus(): \stdClass
Returns list of active validators.
getValidators(?int $height = null): \stdClass
Return estimate of buy coin transaction.
estimateCoinBuy(string $coinToSell, string $valueToBuy, string $coinToBuy, ?int $height = null): \stdClass
Return estimate of sell coin transaction.
estimateCoinSell(string $coinToSell, string $valueToSell, string $coinToBuy, ?int $height = null): \stdClass
Returns information about coin. Note: this method does not return information about base coins (MNT and BIP).
getCoinInfo(string $coin, ?int $height = null): \stdClass
Returns block data at given height.
getBlock(int $height): \stdClass
Returns events at given height.
getEvents(int $height): \stdClass
Returns transaction info.
getTransaction(string $hash): \stdClass
Returns candidate’s info by provided public_key. It will respond with 404 code if candidate is not found.
getCandidate(string $publicKey, ?int $height = null): \stdClass
Returns list of candidates.
$height is optional parameter.
getCandidates(?int $height = null, ?bool $includeStakes = false): \stdClass
Return estimate of transaction.
estimateTxCommission(string $tx): \stdClass
Return transactions by query.
getTransactions(string $query, ?int $page = null, ?int $perPage = null): \stdClass
Returns unconfirmed transactions.
getUnconfirmedTxs(?int $limit = null): \stdClass
Returns current max gas price.
getMaxGasPrice(?int $height = null): \stdClass
Returns current min gas price.
getMinGasPrice(): \stdClass
Returns missed blocks by validator public key.
getMissedBlocks(string $pubKey, ?int $height = null): \stdClass
Example of how you can handle errors and get the response body.
use Minter\MinterAPI;
use GuzzleHttp\Exception\RequestException;
// create instance
$api = new MinterAPI('node url here');
try {
// success response
$response = $api->send('signed tx here');
} catch(RequestException $exception) {
// short exception message
$message = $exception->getMessage();
// error response in json
$content = $exception->getResponse()
->getBody()
->getContents();
// error response as array
$error = json_decode($content, true);
}
Returns a signed tx.
- Sign the SendCoin transaction
use Minter\SDK\MinterTx;
use Minter\SDK\MinterCoins\MinterSendCoinTx;
$tx = new MinterTx([
'nonce' => $nonce,
'chainId' => MinterTx::MAINNET_CHAIN_ID, // or MinterTx::TESTNET_CHAIN_ID
'gasPrice' => 1,
'gasCoin' => 'MNT',
'type' => MinterSendCoinTx::TYPE,
'data' => [
'coin' => 'MNT',
'to' => 'Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee99',
'value' => '10'
],
'payload' => '',
'serviceData' => '',
'signatureType' => MinterTx::SIGNATURE_SINGLE_TYPE // or SIGNATURE_MULTI_TYPE
]);
$tx->sign('your private key')
- Sign the SellCoin transaction
use Minter\SDK\MinterTx;
use Minter\SDK\MinterCoins\MinterSellCoinTx;
$tx = new MinterTx([
'nonce' => $nonce,
'chainId' => MinterTx::MAINNET_CHAIN_ID, // or MinterTx::TESTNET_CHAIN_ID
'gasPrice' => 1,
'gasCoin' => 'MNT',
'type' => MinterSellCoinTx::TYPE,
'data' => [
'coinToSell' => 'MNT',
'valueToSell' => '1',
'coinToBuy' => 'TEST',
'minimumValueToBuy' => 1
],
'payload' => '',
'serviceData' => '',
'signatureType' => MinterTx::SIGNATURE_SINGLE_TYPE // or SIGNATURE_MULTI_TYPE
]);
$tx->sign('your private key')
- Sign the SellAllCoin transaction
use Minter\SDK\MinterTx;
use Minter\SDK\MinterCoins\MinterSellAllCoinTx;
$tx = new MinterTx([
'nonce' => $nonce,
'chainId' => MinterTx::MAINNET_CHAIN_ID, // or MinterTx::TESTNET_CHAIN_ID
'gasPrice' => 1,
'gasCoin' => 'MNT',
'type' => MinterSellAllCoinTx::TYPE,
'data' => [
'coinToSell' => 'TEST',
'coinToBuy' => 'MNT',
'minimumValueToBuy' => 1
],
'payload' => '',
'serviceData' => '',
'signatureType' => MinterTx::SIGNATURE_SINGLE_TYPE // or SIGNATURE_MULTI_TYPE
]);
$tx->sign('your private key')
- Sign the BuyCoin transaction
use Minter\SDK\MinterTx;
use Minter\SDK\MinterCoins\MinterBuyCoinTx;
$tx = new MinterTx([
'nonce' => $nonce,
'chainId' => MinterTx::MAINNET_CHAIN_ID, // or MinterTx::TESTNET_CHAIN_ID
'gasPrice' => 1,
'gasCoin' => 'MNT',
'type' => MinterBuyCoinTx::TYPE,
'data' => [
'coinToBuy' => 'MNT',
'valueToBuy' => '1',
'coinToSell' => 'TEST',
'maximumValueToSell' => 1
],
'payload' => '',
'serviceData' => '',
'signatureType' => MinterTx::SIGNATURE_SINGLE_TYPE // or SIGNATURE_MULTI_TYPE
]);
$tx->sign('your private key')
- Sign the CreateCoin transaction
use Minter\SDK\MinterTx;
use Minter\SDK\MinterCoins\MinterCreateCoinTx;
$tx = new MinterTx([
'nonce' => $nonce,
'chainId' => MinterTx::MAINNET_CHAIN_ID, // or MinterTx::TESTNET_CHAIN_ID
'gasPrice' => 1,
'gasCoin' => 'MNT',
'type' => MinterCreateCoinTx::TYPE,
'data' => [
'name' => 'TEST COIN',
'symbol' => 'TEST',
'initialAmount' => '100',
'initialReserve' => '10',
'crr' => 10
],
'payload' => '',
'serviceData' => '',
'signatureType' => MinterTx::SIGNATURE_SINGLE_TYPE // or SIGNATURE_MULTI_TYPE
]);
$tx->sign('your private key')
- Sign the DeclareCandidacy transaction
use Minter\SDK\MinterTx;
use Minter\SDK\MinterCoins\MinterDeclareCandidacyTx;
$tx = new MinterTx([
'nonce' => $nonce,
'chainId' => MinterTx::MAINNET_CHAIN_ID, // or MinterTx::TESTNET_CHAIN_ID
'gasPrice' => 1,
'gasCoin' => 'MNT',
'type' => MinterDeclareCandidacyTx::TYPE,
'data' => [
'address' => 'Mxa7bc33954f1ce855ed1a8c768fdd32ed927def47',
'pubkey' => 'Mp023853f15fc1b1073ad7a1a0d4490a3b1fadfac00f36039b6651bc4c7f52ba9c02',
'commission' => 10,
'coin' => 'MNT',
'stake' => '5'
],
'payload' => '',
'serviceData' => '',
'signatureType' => MinterTx::SIGNATURE_SINGLE_TYPE // or SIGNATURE_MULTI_TYPE
]);
$tx->sign('your private key')
- Sign the Delegate transaction
use Minter\SDK\MinterTx;
use Minter\SDK\MinterCoins\MinterDelegateTx;
$tx = new MinterTx([
'nonce' => $nonce,
'chainId' => MinterTx::MAINNET_CHAIN_ID, // or MinterTx::TESTNET_CHAIN_ID
'gasPrice' => 1,
'gasCoin' => 'MNT',
'type' => MinterDelegateTx::TYPE,
'data' => [
'pubkey' => 'Mp0eb98ea04ae466d8d38f490db3c99b3996a90e24243952ce9822c6dc1e2c1a43',
'coin' => 'MNT',
'stake' => '5'
],
'payload' => '',
'serviceData' => '',
'signatureType' => MinterTx::SIGNATURE_SINGLE_TYPE // or SIGNATURE_MULTI_TYPE
]);
$tx->sign('your private key')
- Sign the SetCandidateOn transaction
use Minter\SDK\MinterTx;
use Minter\SDK\MinterCoins\MinterSetCandidateOnTx;
$tx = new MinterTx([
'nonce' => $nonce,
'chainId' => MinterTx::MAINNET_CHAIN_ID, // or MinterTx::TESTNET_CHAIN_ID
'gasPrice' => 1,
'gasCoin' => 'MNT',
'type' => MinterSetCandidateOnTx::TYPE,
'data' => [
'pubkey' => 'Mp0eb98ea04ae466d8d38f490db3c99b3996a90e24243952ce9822c6dc1e2c1a43'
],
'payload' => '',
'serviceData' => '',
'signatureType' => MinterTx::SIGNATURE_SINGLE_TYPE // or SIGNATURE_MULTI_TYPE
]);
$tx->sign('your private key')
- Sign the SetCandidateOff transaction
use Minter\SDK\MinterTx;
use Minter\SDK\MinterCoins\MinterSetCandidateOffTx;
$tx = new MinterTx([
'nonce' => $nonce,
'chainId' => MinterTx::MAINNET_CHAIN_ID, // or MinterTx::TESTNET_CHAIN_ID
'gasPrice' => 1,
'gasCoin' => 'MNT',
'type' => MinterSetCandidateOffTx::TYPE,
'data' => [
'pubkey' => 'Mp0eb98ea04ae466d8d38f490db3c99b3996a90e24243952ce9822c6dc1e2c1a43'
],
'payload' => '',
'serviceData' => '',
'signatureType' => MinterTx::SIGNATURE_SINGLE_TYPE // or SIGNATURE_MULTI_TYPE
]);
$tx->sign('your private key')
- Sign the RedeemCheck transaction
use Minter\SDK\MinterTx;
use Minter\SDK\MinterCoins\MinterRedeemCheckTx;
$tx = new MinterTx([
'nonce' => $nonce,
'chainId' => MinterTx::MAINNET_CHAIN_ID, // or MinterTx::TESTNET_CHAIN_ID
'gasPrice' => 1,
'gasCoin' => 'MNT',
'type' => MinterRedeemCheckTx::TYPE,
'data' => [
'check' => 'your check',
'proof' => 'created by MinterCheck proof'
],
'payload' => '',
'serviceData' => '',
'signatureType' => MinterTx::SIGNATURE_SINGLE_TYPE // or SIGNATURE_MULTI_TYPE
]);
$tx->sign('your private key')
- Sign the Unbond transaction
use Minter\SDK\MinterTx;
use Minter\SDK\MinterCoins\MinterUnbondTx;
$tx = new MinterTx([
'nonce' => $nonce,
'chainId' => MinterTx::MAINNET_CHAIN_ID, // or MinterTx::TESTNET_CHAIN_ID
'gasPrice' => 1,
'gasCoin' => 'MNT',
'type' => MinterUnbondTx::TYPE,
'data' => [
'pubkey' => 'Mp....',
'coin' => 'MNT',
'value' => '1'
],
'payload' => '',
'serviceData' => '',
'signatureType' => MinterTx::SIGNATURE_SINGLE_TYPE // or SIGNATURE_MULTI_TYPE
]);
$tx->sign('your private key')
- Sign the MultiSend transaction
use Minter\SDK\MinterTx;
use Minter\SDK\MinterCoins\MinterMultiSendTx;
$tx = new MinterTx([
'nonce' => $nonce,
'chainId' => MinterTx::MAINNET_CHAIN_ID, // or MinterTx::TESTNET_CHAIN_ID
'gasPrice' => 1,
'gasCoin' => 'MNT',
'type' => MinterMultiSendTx::TYPE,
'data' => [
'list' => [
[
'coin' => 'MNT',
'to' => 'Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee99',
'value' => '10'
], [
'coin' => 'MNT',
'to' => 'Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee92',
'value' => '15'
]
]
],
'payload' => '',
'serviceData' => '',
'signatureType' => MinterTx::SIGNATURE_SINGLE_TYPE // or SIGNATURE_MULTI_TYPE
]);
$tx->sign('your private key')
- Sign the EditCandidate transaction
use Minter\SDK\MinterTx;
use Minter\SDK\MinterCoins\MinterEditCandidateTx;
$tx = new MinterTx([
'nonce' => $nonce,
'chainId' => MinterTx::MAINNET_CHAIN_ID, // or MinterTx::TESTNET_CHAIN_ID
'gasPrice' => 1,
'gasCoin' => 'MNT',
'type' => MinterEditCandidateTx::TYPE,
'data' => [
'pubkey' => 'candidate public key',
'reward_address' => 'Minter address for rewards',
'owner_address' => 'Minter address of owner'
],
'payload' => '',
'serviceData' => '',
'signatureType' => MinterTx::SIGNATURE_SINGLE_TYPE // or SIGNATURE_MULTI_TYPE
]);
$tx->sign('your private key')
- Calculate fee of transaction. You can get fee AFTER signing or decoding transaction.
use Minter\SDK\MinterTx;
$tx = new MinterTx([....]);
$sign = $tx->sign('your private key');
$tx->getFee();
- Get hash of encoded transaction
use Minter\SDK\MinterTx;
$tx = new MinterTx([....]);
$sign = $tx->sign('your private key');
$hash = $tx->getHash();
- Get hash of decoded transaction
use Minter\SDK\MinterTx;
$tx = new MinterTx('Mx....');
$hash = $tx->getHash();
Returns an array with transaction data.
- Decode transaction
use Minter\SDK\MinterTx;
$tx = new MinterTx('string tx');
// $tx->from, $tx->data, $tx->nonce ...
- Create check
use Minter\SDK\MinterCheck;
$check = new MinterCheck([
'nonce' => $nonce,
'chainId' => MinterTx::MAINNET_CHAIN_ID, // or MinterTx::TESTNET_CHAIN_ID
'dueBlock' => 999999,
'coin' => 'MNT',
'value' => '10'
], 'your pass phrase');
echo $check->sign('your private key here');
// Mc.......
- Create proof
use Minter\SDK\MinterCheck;
$check = new MinterCheck('your Minter address here', 'your pass phrase');
echo $check->createProof();
- Decode check
use Minter\SDK\MinterCheck;
$check = new MinterCheck('your Minter check here');
$check->getBody(); // check body
$check->getOwnerAddress(); // check owner address
- Create wallet. This method returns generated seed, private key, public key, mnemonic and Minter address.
use Minter\SDK\MinterWallet;
$wallet = MinterWallet::create();
- Generate mnemonic.
use Minter\SDK\MinterWallet;
$mnemonic = MinterWallet::generateMnemonic();
- Get seed from mnemonic.
use Minter\SDK\MinterWallet;
$seed = MinterWallet::mnemonicToSeed($mnemonic);
- Get private key from seed.
use Minter\SDK\MinterWallet;
$privateKey = MinterWallet::seedToPrivateKey($seed);
- Get public key from private key.
use Minter\SDK\MinterWallet;
$publicKey = MinterWallet::privateToPublic($privateKey);
- Get Minter address from public key.
use Minter\SDK\MinterWallet;
$address = MinterWallet::getAddressFromPublicKey($publicKey);
- Create Minter deep link.
- You can pass data of any Minter transaction to the constructor.
- Payload is required.
use Minter\SDK\MinterDeepLink;
use Minter\SDK\MinterCoins\MinterSendCoinTx;
$txData = new MinterSendCoinTx([
'coin' => 'BIP',
'to' => 'Mx18467bbb64a8edf890201d526c35957d82be3d95',
'value' => '1.23456789'
]);
$link = new MinterDeepLink($txData);
$link->setPayload('Hello World');
$link->encode(); // returns encoded link as string
- You can define optional fields such as nonce, gas price, gas coin.
use Minter\SDK\MinterDeepLink;
use Minter\SDK\MinterCoins\MinterSendCoinTx;
$txData = new MinterSendCoinTx([
'coin' => 'BIP',
'to' => 'Mx18467bbb64a8edf890201d526c35957d82be3d95',
'value' => '1.23456789'
]);
$link = new MinterDeepLink($txData);
$link->setPayload('Hello World');
$link->setNonce($nonce);
$link->setGasPrice($gasPrice);
$link->setGasCoin($gasCoin);
$link->encode(); // returns encoded link as string
To run unit tests:
vendor/bin/phpunit tests