kaadon/erc20-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kaadon/erc20-php

最新稳定版本:v0.3.2

Composer 安装命令:

composer require kaadon/erc20-php

包简介

Interact with any ERC20 standard/backward-compatible Ethereum token

README 文档

README

Interact with any ERC20 standard Ethereum token

This package is ultimate response to historic issue of no native API being available to PHP developers to interact with ERC20 tokens (i.e. web3js contracts API).

This package relies on furqansiddiqui/ethereum-php package to perform all ABI encoding and decoding, as well as communication with Ethereum node using RPC/API, resulting in pure simple and easy to use API for developers to perform all ERC20 standard operations.

Ethereum Node Status
Geth / Ethereum-Go RPC ✔️
Infura.IO ✔️

Demo

  • Testing interaction with Thether USD / USDT ERC20 smart contract:
use FurqanSiddiqui\Ethereum\RPC\Infura;
use FurqanSiddiqui\Ethereum\ERC20\ERC20;

$infura = new Infura("PROJECT-ID", "PROJECT-SECRET");
$infura->ignoreSSL(); // In case Infura.IO SSL errors (or provide "caRootFile:" to constructor above)

$erc20 = new ERC20($infura);
$usdt = $erc20->deployedAt("0xdac17f958d2ee523a2206206994597c13d831ec7");
var_dump($usdt->name());
var_dump($usdt->symbol());
var_dump($usdt->decimals());
var_dump($usdt->totalSupply());
$balance = $usdt->balanceOf($eth->getAccount("ETHEREUM-ADDRESS"));
var_dump($balance);
var_dump($usdt->getScaledValue($balance));

Result:

string(9) "TetherUSD"
string(4) "USDT"
int(6)
string(18) "32284517903064882"
string(11) "53150417979"
string(12) "53150.417979"

Custom ABI

  • Standard/base ERC20 ABI is included in package.
  • To included extended/custom ERC20 ABI (depending on your requirments), use one of the following methods:
    • Extend BaseERC20Contract class to define custom ABI functions and events.
    • Decode your custom ABI JSON file and provide it to constructor:
use \FurqanSiddiqui\Ethereum\Contracts\Contract;

$customABI  =   Contract::fromArray(json_decode(file_get_contents("YOUR-CUSTOM-ABI.json"), true), true);
$erc20 = new ERC20(abi: $customABI);

Scaled Values

Use getScaledValue and fromScaledValue to convert amounts from/to uint256.

Prerequisites

Installation

composer require furqansiddiqui/erc20-php

Changelog

  • 0.3.0: This library alongside several others such as ethereum-php have been modernised and requires PHP ^8.1.

统计信息

  • 总下载量: 31
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 96
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固