kornrunner/ethereum-token
Composer 安装命令:
composer require kornrunner/ethereum-token
包简介
PHP Ethereum Token Utils
关键字:
README 文档
README
PHP Ethereum Token Utils
Installation
$ composer require kornrunner/ethereum-token
Usage
To prepare a offline transaction, using kornrunner/ethereum-offline-raw-tx
Transfer
use kornrunner\Ethereum\Token; use kornrunner\Ethereum\Transaction; $nonce = '04'; $gasPrice = '03f5476a00'; $gasLimit = '027f4b'; $to = '1a8c8adfbe1c59e8b58cc0d515f07b7225f51c72'; $privateKey = 'b2f2698dd7343fa5afc96626dee139cb92e58e5d04e855f4c712727bf198e898'; $token = new Token; $usdt = new Token\USDT; $amount = 20; $hexAmount = $token->hexAmount($usdt, $amount); // 0x1312d00 $data = $token->getTransferData($to, $hexAmount); // 0xa9059cbb0000000000000000000000001a8c8adfbe1c59e8b58cc0d515f07b7225f51c720000000000000000000000000000000000000000000000000000000001312d00 $transaction = new Transaction($nonce, $gasPrice, $gasLimit, $usdt::ADDRESS, '', $data); $transaction->getRaw($privateKey); // f8a9048503f5476a0083027f4b94dac17f958d2ee523a2206206994597c13d831ec7b844a9059cbb0000000000000000000000001a8c8adfbe1c59e8b58cc0d515f07b7225f51c720000000000000000000000000000000000000000000000000000000001312d00801ba03e141ea4233ec00bb3a80d7fea5f774b736772851b7bad18453d0f3c6097c42e9fa6eb47b6bead6a76d7db12809e2c916df999d7b99b613fcaa135abd8a0078e
Approve
Approve another address to spend tokens on your behalf:
use kornrunner\Ethereum\Token; use kornrunner\Ethereum\Transaction; $token = new Token; $usdt = new Token\USDT; $spender = '1a8c8adfbe1c59e8b58cc0d515f07b7225f51c72'; $amount = 100; $hexAmount = $token->hexAmount($usdt, $amount); $data = $token->getApproveData($spender, $hexAmount); // use $data with Transaction as shown above
Burn
Burn (destroy) tokens:
use kornrunner\Ethereum\Token; use kornrunner\Ethereum\Transaction; $token = new Token; $usdt = new Token\USDT; $amount = 50; $hexAmount = $token->hexAmount($usdt, $amount); $data = $token->getBurnData($hexAmount); // use $data with Transaction as shown above
Mint
Mint (create) new tokens to an address:
use kornrunner\Ethereum\Token; use kornrunner\Ethereum\Transaction; $token = new Token; $usdt = new Token\USDT; $recipient = '1a8c8adfbe1c59e8b58cc0d515f07b7225f51c72'; $amount = 1000; $hexAmount = $token->hexAmount($usdt, $amount); $data = $token->getMintData($recipient, $hexAmount); // use $data with Transaction as shown above
TransferFrom
Transfer tokens from one address to another using allowance:
use kornrunner\Ethereum\Token; use kornrunner\Ethereum\Transaction; $token = new Token; $usdt = new Token\USDT; $from = 'd9040b8a1f12a40511ac1f7b994a21dd08ceac20'; $to = '1a8c8adfbe1c59e8b58cc0d515f07b7225f51c72'; $amount = 50; $hexAmount = $token->hexAmount($usdt, $amount); $data = $token->getTransferFromData($from, $to, $hexAmount); // use $data with Transaction as shown above
Read-Only Functions
For querying token information (generates ABI-encoded call data):
BalanceOf
Get the token balance of an address:
use kornrunner\Ethereum\Token; $token = new Token; $address = '1a8c8adfbe1c59e8b58cc0d515f07b7225f51c72'; $data = $token->getBalanceOfData($address); // 0x70a082310000000000000000000000001a8c8adfbe1c59e8b58cc0d515f07b7225f51c72
Allowance
Check how many tokens a spender is allowed to use:
use kornrunner\Ethereum\Token; $token = new Token; $owner = '1a8c8adfbe1c59e8b58cc0d515f07b7225f51c72'; $spender = 'd9040b8a1f12a40511ac1f7b994a21dd08ceac20'; $data = $token->getAllowanceData($owner, $spender); // 0x...
TotalSupply
Get the total supply of tokens:
use kornrunner\Ethereum\Token; $token = new Token; $data = $token->getTotalSupplyData(); // 0x18160ddd
Crypto
kornrunner/ethereum-token 适用场景与选型建议
kornrunner/ethereum-token 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.34k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2020 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「transaction」 「offline」 「tx」 「ethereum」 「eth」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kornrunner/ethereum-token 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kornrunner/ethereum-token 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kornrunner/ethereum-token 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
DUKPT implementation in PHP
Rich payment solutions for Laravel framework. Paypal, payex, authorize.net, be2bill, omnipay, recurring paymens, instant notifications and many more
The BlockTrail PHP SDK, for integration of Bitcoin functionality through the BlockTrail API
Set Facebook offline conversion
Rich payment solutions for Yii framework. Paypal, payex, authorize.net, be2bill, omnipay, recurring paymens, instant notifications and many more
Bitcoin and Altcoin Payment Gateway for Magento 2 via CoinGate
统计信息
- 总下载量: 13.34k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 20
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-08
0x9c7b7a00972121fb843af7af74526d7eb585b171