minter / minter-php-sdk
Requires
- php: ^7.1.3|^8.0
- ext-bcmath: *
- ext-gmp: *
- ext-json: *
- bitwasp/bitcoin-lib: ^1.0
- guzzlehttp/guzzle: ^6.3|^7.3
- kornrunner/keccak: ^1.0
- minter/minter-php-bip-44: ^1.2
- minter/php-rlp: ^1.0.0
- simplito/elliptic-php: ^1.0
Requires (Dev)
- phpunit/phpunit: ^7|^9.5
- dev-master
- v3.7.0
- v3.6.0
- v3.5.0
- v3.4.1
- v3.4.0
- v3.3.1
- v3.3.0
- v3.2.1
- v3.2.0
- v3.1.1
- v3.1.0
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.0
- v1.8.0
- v1.7.0
- v1.6.0
- v1.5.0
- v1.4.1
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.1
- v1.1.0
- v1.0.0
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- v0.0.10
- v0.0.9
- v0.0.8
- v0.0.7
- v0.0.6
- 0.0.5
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
- dev-toronet
- dev-taconet
- dev-dev
This package is auto-updated.
Last update: 2024-09-18 12:18:54 UTC
README
关于
这是一个用于与 Minter 区块链交互的纯PHP SDK。
-
- 方法
- getBalance
- getNonce
- send
- getAddresses
- getStatus
- getValidators
- estimateCoinBuy
- estimateCoinSell
- estimateCoinSellAll
- getCoinInfo
- getBlock
- getEvents
- getTransaction
- getCandidate
- getCandidates
- estimateTxCommission
- getTransactions
- getUnconfirmedTxs
- getMaxGasPrice
- getMinGasPrice
- getMissedBlocks
- getWaitlist
- getPriceCommissions
- getPriceVotes
- getSwapPool
- getSwapPoolProvider
- getLimitOrder
- getLimitOrders
- getLimitOrdersByCoins
- 错误处理
- 方法
安装
composer require minter/minter-php-sdk
使用 MinterAPI
您可以在 Minter 节点 Api 获取所有有效响应和完整文档。
创建 MinterAPI 实例
use Minter\MinterAPI; $nodeUrl = 'https://minter-node-1.testnet.minter.network:8843/v2/'; // example of a node url $api = new MinterAPI($nodeUrl);
getBalance
返回地址的硬币列表、余额和交易计数(对于nonce)。
getBalance(string $minterAddress, ?int $height = null): \stdClass
示例
$api->getBalance('Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee99') // {"jsonrpc": "2.0", "id": "", "result": { "balance": { ... }, "transaction_count": "0"}}
getNonce
返回地址的下一个交易号码(nonce)。
getNonce(string $minterAddress): int
示例
$api->getNonce('Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee99')
send
返回发送 已签名 交易的結果。
⚠️ 为确保交易已成功提交到区块链,您需要通过哈希找到交易并确保状态码等于0。
send(string $tx): \stdClass
示例
$api->send('f873010101aae98a4d4e540000000000000094fe60014a6e9ac91618f5d1cab3fd58cded61ee99880de0b6b3a764000080801ca0ae0ee912484b9bf3bee785f4cbac118793799450e0de754667e2c18faa510301a04f1e4ed5fad4b489a1065dc1f5255b356ab9a2ce4b24dde35bcb9dc43aba019c')
getAddresses
返回地址余额。
getAddresses(array $addresses, ?int $height = null): \stdClass
getStatus
返回节点状态信息。
getStatus(): \stdClass
getValidators
返回活动验证者列表。
getValidators(?int $height = null, ?int $page = 1, ?int $perPage = null): \stdClass
estimateCoinBuy
返回购买硬币交易的估算。
estimateCoinBuy(string $coinToSell, string $valueToBuy, string $coinToBuy, ?int $height = null, string $swapFrom): \stdClass
estimateCoinSell
返回出售硬币交易的估算。
estimateCoinSell(string $coinToSell, string $valueToSell, string $coinToBuy, ?int $height = null, string $swapFrom): \stdClass
estimateCoinSellAll
返回出售所有硬币交易的估算。
estimateCoinSellAll(string $coinToSell, string $valueToSell, string $coinToBuy, ?int $height = null, string $swapFrom): \stdClass
getCoinInfo
返回有关硬币的信息。注意:此方法不返回有关基础硬币(MNT和BIP)的信息。
getCoinInfo(string $coin, ?int $height = null): \stdClass
getBlock
返回给定高度的区块数据。
getBlock(int $height): \stdClass
getEvents
返回指定高度的的事件。
getEvents(int $height): \stdClass
getTransaction
返回交易信息。
getTransaction(string $hash): \stdClass
getCandidate
根据提供的公钥返回候选人的信息。如果找不到候选人,将返回404错误码。
getCandidate(string $publicKey, ?int $height = null): \stdClass
getCandidates
返回候选人的列表。
$height是可选参数。
getCandidates(?int $height = null, ?bool $includeStakes = false): \stdClass
estimateTxCommission
返回交易估算。
estimateTxCommission(string $tx, ?int $height = null): \stdClass
getTransactions
根据查询返回交易。
getTransactions(string $query, ?int $page = null, ?int $perPage = null): \stdClass
getUnconfirmedTxs
返回未确认的交易。
getUnconfirmedTxs(?int $limit = null): \stdClass
getMaxGasPrice
返回当前的最大燃气价格。
getMaxGasPrice(?int $height = null): \stdClass
getMinGasPrice
返回当前的最低燃气价格。
getMinGasPrice(): \stdClass
getMissedBlocks
根据验证器的公钥返回丢失的区块。
getMissedBlocks(string $pubKey, ?int $height = null): \stdClass
getGenesis
返回网络创世信息。
getGenesis(): \stdClass
getNetworkInfo
返回节点网络信息。
getNetworkInfo(): \stdClass
getWaitlist
返回按地址返回的排队权益。
getWaitlist(string $address, ?string $publicKey = null, ?int $height = null): \stdClass
getWaitlist
返回按地址返回的排队权益。
getWaitlist(string $address, ?string $publicKey = null, ?int $height = null): \stdClass
getPriceCommissions
返回Minter网络上设置的佣金列表。
getPriceCommissions(?int $height = null): \stdClass
getPriceVotes
返回网络更改佣金的验证器投票列表。
getPriceVotes(int $height): \stdClass
getSwapPool
返回交换池的整个流动性体积。
getSwapPool(string $coin0, string $coin1, ?int $height = null): \stdClass
getSwapPoolProvider
返回由指定地址提供的交换池的流动性体积。
getSwapPoolProvider(string $coin0, string $coin1, string $provider, ?int $height = null): \stdClass
getLimitOrders
返回按ID返回的限价订单列表。
getLimitOrders(array $ids, ?int $height = null): \stdClass
getLimitOrder
返回按ID返回的限价订单详情。
getLimitOrder(int $limitOrderId, ?int $height = null): \stdClass
getLimitOrdersByCoins
返回与买卖硬币相关的限价订单。
getLimitOrdersByCoins(string $sellCoin, string $buyCoin, int $limit = null, ?int $height = null): \stdClass
错误处理
处理错误和获取响应体的示例。
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); }
使用MinterSDK
签名交易
返回已签名的交易。
示例
- 签名的SendCoin交易
- 构造函数:
MinterSendCoinTx($coin, $to, $value)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterSendCoinTx; $data = new MinterSendCoinTx($coinID, 'Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee99', '10'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
在所有类型的交易中,您也可以设置可选字段:燃气价格、燃气币、有效载荷、服务数据、链ID
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterSendCoinTx; $data = new MinterSendCoinTx($coinID, 'Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee99', '10'); $tx = (new MinterTx($nonce, $data)) ->setChainID(MinterTx::TESTNET_CHAIN_ID) ->setGasPrice(1) ->setGasCoin(MinterTx::BASE_COIN_ID) ->setPayload('some payload') ->setServiceData('some data'); $tx->sign('your private key');
示例
- 签名的SellCoin交易
- 构造函数:
MinterSellCoinTx($coinToSell, $valueToSell, $coinToBuy, $minimumValueToBuy)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterSellCoinTx; $data = new MinterSellCoinTx(123, '1', 321, '1'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名的SellAllCoin交易
- 构造函数:
MinterSellAllCoinTx($coinToSell, $coinToBuy, $minimumValueToBuy)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterSellAllCoinTx; $data = new MinterSellAllCoinTx(123, 321, '1'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名的BuyCoin交易
- 构造函数:
MinterBuyCoinTx($coinToBuy, $valueToBuy, $coinToSell, $maximumValueToSell)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterBuyCoinTx; $data = new MinterBuyCoinTx(123, '1', 321, '1'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名的CreateCoin交易
- 构造函数:
MinterCreateCoinTx($name, $symbol, $amount, $reserve, $crr, $maxSupply)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterCreateCoinTx; $data = new MinterCreateCoinTx('TEST COIN', 'TEST', '10000', '10', 10, '10000'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名的DeclareCandidacy交易
- 构造函数:
MinterDeclareCandidacyTx($address, $publicKey, $commission, $coin, $stake)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterDeclareCandidacyTx; $data = new MinterDeclareCandidacyTx( 'Mxa7bc33954f1ce855ed1a8c768fdd32ed927def47', 'Mp023853f15fc1b1073ad7a1a0d4490a3b1fadfac00f36039b6651bc4c7f52ba9c02', 10, 0, '10000' ); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名的Delegate交易
- 构造函数:
MinterDelegateTx($publicKey, $coin, $stake)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterDelegateTx; $data = new MinterDelegateTx('Mp0eb98ea04ae466d8d38f490db3c99b3996a90e24243952ce9822c6dc1e2c1a43', 123, '10000'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名的SetCandidateOn交易
- 构造函数:
MinterSetCandidateOnTx($publicKey)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterSetCandidateOnTx; $data = new MinterSetCandidateOnTx('Mp0eb98ea04ae466d8d38f490db3c99b3996a90e24243952ce9822c6dc1e2c1a43'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名的SetCandidateOff交易
- 构造函数:
MinterSetCandidateOffTx($publicKey)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterSetCandidateOffTx; $data = new MinterSetCandidateOffTx('Mp0eb98ea04ae466d8d38f490db3c99b3996a90e24243952ce9822c6dc1e2c1a43'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名的RedeemCheck交易
- 构造函数:
MinterRedeemCheckTx($check, $proof)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterRedeemCheckTx; $data = new MinterRedeemCheckTx('your check', 'created by MinterCheck proof'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名的Unbond交易
- 构造函数:
MinterUnbondTx($publicKey, $coin, $value)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterUnbondTx; $data = new MinterUnbondTx('Mp....', 123, '10000'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名的MultiSend交易
- 构造函数:
MinterMultiSendTx($list)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterSendCoinTx; use Minter\SDK\MinterCoins\MinterMultiSendTx; $data = new MinterMultiSendTx([ new MinterSendCoinTx(0, 'Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee99', '15'), new MinterSendCoinTx(123, 'Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee92', '10') ]); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名的EditCandidate交易
- 构造函数:
MinterEditCandidateTx($publicKey, $rewardAddress, $ownerAddress, $controlAddress)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterEditCandidateTx; $data = new MinterEditCandidateTx('candidate public key', 'Minter address for rewards', 'Minter address of owner', 'Minter address for control'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名的CreateMultisig交易
- 构造函数:
MinterCreateMultisigTx($threshold, $weights, $addresses)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterCreateMultisigTx; $data = new MinterCreateMultisigTx(7, [1, 3, 5], [ 'Mxee81347211c72524338f9680072af90744333143', 'Mxee81347211c72524338f9680072af90744333145', 'Mxee81347211c72524338f9680072af90744333144' ]); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名 SetHaltBlock 交易
- 构造函数:
MinterSetHaltBlockTx($publicKey, $height)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterSetHaltBlockTx; $data = new MinterSetHaltBlockTx('your public key', 236503); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名 RecreateCoin 交易
- 构造函数:
MinterRecreateCoinTx($name, $symbol, $amount, $reserve, $crr, $maxSupply)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterRecreateCoinTx; $data = new MinterRecreateCoinTx('TEST', '10000', '10', 10000, 10, '10000'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名 EditCoinOwner 交易
- 构造函数:
MinterEditCoinOwnerTx($symbol, $newOwner)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterEditCoinOwnerTx; $data = new MinterEditCoinOwnerTx('COINSYMBOL', 'Mxee81347211c72524338f9680072af90744333145'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名 EditMultisig 交易
- 构造函数:
MinterEditMultisigTx($threshold, $weights, $addresses)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterEditMultisigTx; $data = new MinterEditMultisigTx(1, [1, 2], ['Mxee81347211c72524338f9680072af90744333145', 'Mxee81347211c72524338f9680072af90744333146']); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名 EditCandidatePublicKey 交易
- 构造函数:
MinterEditCandidatePublicKeyTx($publicKey, $newPublicKey)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterEditCandidatePublicKeyTx; $data = new MinterEditCandidatePublicKeyTx('public key', 'new public key....'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名 AddLiquidity 交易
- 构造函数:
MinterAddLiquidityTx($coin0, $coin1, $volume0, $maximumVolume1)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterAddLiquidityTx; $data = new MinterAddLiquidityTx(0, 1, '1000', '2000'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名 RemoveLiquidity 交易
- 构造函数:
MinterRemoveLiquidityTx($coin0, $coin1, $liquidity, $minimumVolume0, $minimumVolume1)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterRemoveLiquidityTx; $data = new MinterRemoveLiquidityTx(0, 1, '2000', '500', '1000'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名 SellSwapPool 交易
- 构造函数:
MinterSellSwapPoolTx(array $coins, $valueToSell, $minimumValueToBuy)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterSellSwapPoolTx; $data = new MinterSellSwapPoolTx([1, 2], '20', '2'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名 BuySwapPool 交易
- 构造函数:
MinterBuySwapPoolTx($coins, $valueToBuy, $maximumValueToSell)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterBuySwapPoolTx; $data = new MinterBuySwapPoolTx([2, 3], '3', '5000'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名 SellAllSwapPool 交易
- 构造函数:
MinterSellAllSwapPoolTx(array $coins, $minimumValueToBuy)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterSellAllSwapPoolTx; $data = new MinterSellAllSwapPoolTx([1, 4, 5], '100'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名 EditCandidateCommission 交易
- 构造函数:
MinterEditCandidateCommissionTx($publicKey, $commission)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterEditCandidateCommissionTx; $data = new MinterEditCandidateCommissionTx('public key', 77); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名 MintToken 交易
- 构造函数:
MinterMintTokenTx($coin, $value)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterMintTokenTx; $data = new MinterMintTokenTx(2, '3000'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key')
示例
- 签名 BurnToken 交易
- 构造函数:
MinterBurnTokenTx($coin, $value)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterBurnTokenTx; $data = new MinterBurnTokenTx(3, '100000'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key')
示例
- 签名 CreateToken 交易
- 构造函数:
MinterCreateTokenTx($name, $symbol, $initialAmount, $maxSupply, $mintable, $burnable)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterCreateTokenTx; $data = new MinterCreateTokenTx('TEST COIN IS MINTABLE ONLY', 'TEST', '10000', '50000', true, false); $tx = new MinterTx($nonce, $data); $tx->sign('your private key')
示例
- 签名 RecreateToken 交易
- 构造函数:
MinterRecreateTokenTx($name, $symbol, $initialAmount, $maxSupply, $mintable, $burnable)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterRecreateTokenTx; $data = new MinterRecreateTokenTx('TEST COIN IS TURNED TO BE BURNABLE ONLY', 'TEST', '50000', '50000', false, true); $tx = new MinterTx($nonce, $data); $tx->sign('your private key')
示例
- 签名 PriceCommission 交易
- 构造函数:
MinterPriceCommissionTx( $pubKey, $height, $coin, $payloadByte, $send, $buyBancor, $sellBancor, $sellAllBancor, $buyPoolBase, $buyPoolDelta, $sellPoolBase, $sellPoolDelta, $sellAllPoolBase, $sellAllPoolDelta, $createTicker3, $createTicker4, $createTicker5, $createTicker6, $createTicker7to10, $createCoin, $createToken, $recreateCoin, $recreateToken, $declareCandidacy, $delegate, $unbond, $redeemCheck, $setCandidateOn, $setCandidateOff, $createMultisig, $multisendBase, $multisendDelta, $editCandidate, $setHaltBlock, $editTickerOwner, $editMultisig, $editCandidatePublicKey, $createSwapPool, $addLiquidity, $removeLiquidity, $editCandidateCommission, $burnToken, $mintToken, $voteCommission, $voteUpdate )
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterPriceCommissionTx; $data = new MinterPriceCommissionTx('public key', 100000,0,'1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41', '42'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key');
示例
- 签名 CreateSwapPoll 交易
- 构造函数:
MinterCreateSwapPoolTx($coin0, $coin1, $volume0, $volume1)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterCreateSwapPoolTx; $data = new MinterCreateSwapPoolTx(1, 2, '11000', '22000'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key')
示例
- 签名 AddLimitOrder 交易
- 构造函数:
MinterAddLimitOrderTx($coinToSell, $valueToSell, $coinToBuy, $valueToBuy)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterAddLimitOrderTx; $data = new MinterAddLimitOrderTx(0, '10', 1841, '7'); $tx = new MinterTx($nonce, $data); $tx->sign('your private key')
示例
- 签名 RemoveLimitOrder 交易
- 构造函数:
MinterRemoveLimitOrderTx($id)
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterRemoveLimitOrderTx; $data = new MinterRemoveLimitOrderTx($limitOrderId); $tx = new MinterTx($nonce, $data); $tx->sign('your private key')
使用多重签名签名交易
返回已签名的交易。
示例
- 要使用多重签名签名交易,您需要调用 signMultisig 方法并传递 多重签名 Minter 地址 及其 私钥(任意顺序)。
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterSendCoinTx; $data = new MinterSendCoinTx(123, 'Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee99', '10'); $tx = new MinterTx($nonce, $data); $signedTx = $tx->signMultisig('Mxdb4f4b6942cb927e8d7e3a1f602d0f1fb43b5bd2', [ 'b354c3d1d456d5a1ddd65ca05fd710117701ec69d82dac1858986049a0385af9', '38b7dfb77426247aed6081f769ed8f62aaec2ee2b38336110ac4f7484478dccb', '94c0915734f92dd66acfdc48f82b1d0b208efd544fe763386160ec30c968b4af' ])
示例
- 要获取交易的 签名(未签名的交易),您需要调用 createSignature
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterSendCoinTx; $data = new MinterSendCoinTx(123, 'Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee99', '10'); $tx = new MinterTx($nonce, $data); $txSignature = $tx->createSignature($privateKey);
示例
- 要使用已准备好的签名签名交易,您需要调用 signMultisigBySigns 方法并传递 多重签名 Minter 地址 及您的 签名(任意顺序)。
use Minter\SDK\MinterTx; use Minter\SDK\MinterCoins\MinterSendCoinTx; $data = new MinterSendCoinTx(123, 'Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee99', '10'); $tx = new MinterTx($nonce, $data); $signature1 = $tx->createSignature($privateKey1); $signature2 = $tx->createSignature($privateKey2); $signature3 = $tx->createSignature($privateKey3); $signedTx = $tx->signMultisigBySigns('Mxdb4f4b6942cb927e8d7e3a1f602d0f1fb43b5bd2', [ $signature1, $signature2, $signature3 ])
获取交易费用
- 计算交易费用。您可以在签名或解码交易后获取费用。
use Minter\SDK\MinterTx; $tx = new MinterTx(...); $tx->getFee();
解码交易
返回包含交易数据的数组。
示例
- 解码交易
use Minter\SDK\MinterTx; $tx = MinterTx::decode('transaction raw starting from 0x...'); // $tx->getSenderAddress() // $tx->getData() // $tx->getNonce() // $tx->getChainID() // $tx->getGasPrice() // $tx->getPayload() // $tx->getSignatureData()
创建 Minter 检查
示例
- 创建检查
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', 'gasCoin' => 'MNT' ], 'your pass phrase'); echo $check->sign('your private key here'); // Mc.......
- 创建证明
use Minter\SDK\MinterCheck; $check = new MinterCheck('your Minter address here', 'your pass phrase'); echo $check->createProof();
- 解码检查
use Minter\SDK\MinterCheck; $check = new MinterCheck('your Minter check here'); $check->getBody(); // check body $check->getOwnerAddress(); // check owner address
Minter 钱包
示例
- 创建钱包。
use Minter\SDK\MinterWallet; $wallet = new MinterWallet(); // $wallet->getPublicKey(); // $wallet->getPrivateKey(); // $wallet->getMnemonic(); // $wallet->getAddress();
- 从助记词创建钱包
use Minter\SDK\MinterWallet; $wallet = MinterWallet::createFromMnemonic($mnemonic);
- 从私钥创建钱包
use Minter\SDK\MinterWallet; $wallet = MinterWallet::createFromPrivate($privateKey);
Minter Link
示例
- 创建 Minter 深链接。
- 您可以将任何 Minter 交易的数据传递给构造函数。
use Minter\SDK\MinterDeepLink; use Minter\SDK\MinterCoins\MinterSendCoinTx; $txData = new MinterSendCoinTx(123, 'Mx18467bbb64a8edf890201d526c35957d82be3d95', '1.23456789'); $link = new MinterDeepLink($txData); $link->encode(); // returns encoded link as string
- 您可以定义可选字段,例如 host、payload、nonce、gas price、gas coin、check password。
use Minter\SDK\MinterDeepLink; use Minter\SDK\MinterCoins\MinterSendCoinTx; $txData = new MinterSendCoinTx(123, 'Mx18467bbb64a8edf890201d526c35957d82be3d95', '1.23456789'); $link = new MinterDeepLink($txData); $link->setPayload('Hello World') ->setNonce($nonce) ->setGasPrice($gasPrice) ->setGasCoin($gasCoin) ->setHost('https://testnet.bip.to/tx') ->setPassword('some check password'); $link->encode(); // returns encoded link as string
测试
运行单元测试
vendor/bin/phpunit tests