ceseshi/vottun-php-sdk

Vottun PHP SDK

0.2.0 2024-04-13 18:13 UTC

This package is auto-updated.

Last update: 2024-09-22 13:15:26 UTC


README

Vottun PHP SDK提供了一个易于使用的PHP接口,用于与Vottun API交互。最初用于在以太坊兼容区块链上执行ERC20和ERC721代币操作,此SDK简化了将Vottun API功能集成到您的PHP应用程序中的过程,包括合约部署、代币转账、查询余额和管理授权。

License: LGPL v3

作者

功能

  • 部署和铸造ERC20代币
  • 部署和铸造ERC721 NFT
  • 部署和铸造ERC1155 NFT
  • 部署和管理POAP代币
  • 转账代币
  • 管理授权
  • 查询代币余额
  • 支持大数运算
  • 易于集成到PHP项目中

需求

文件夹结构

├── examples                  # Example scripts
├── lib                       # Libraries
│   └── Web3                  # web3p/web3.php library
│       └── Utils.php         # The web3.php Utils class, used to manage big numbers.
└── src                       # Source files
    ├── VottunClient.php      # The main VottunClient class, used to interact with the Vottun API.
    └── ERCv1                 # Vottun ERC v1 API clients
        ├── BaseClient.php    # The BaseClient class, used to interact with the Vottun API.
        ├── ERC20Client.php   # The ERC20Client class, used to interact with ERC20 tokens.
        ├── ERC721Client.php  # The ERC721Client class, used to interact with ERC721 tokens.
        ├── ERC1155Client.php # The ERC1155Client class, used to interact with ERC1155 tokens.
        └── POAPClient.php    # The POAPClient class, used to interact with POAP tokens.

安装

在您的项目目录中运行以下命令,以将Vottun PHP SDK添加为依赖项

composer require ceseshi/vottun-php-sdk

使用方法

以下是关于如何在您的项目中使用Vottun PHP SDK的快速入门指南

初始化客户端

require_once 'vendor/autoload.php';

use Vottun\VottunClient;
use Vottun\ERCv1\ERC20Client;

$vottunApiKey = 'your_api_key_here';
$vottunApplicationVkn = 'your_application_vkn_here';
$vottunClient = new VottunClient($vottunApiKey, $vottunApplicationVkn);
$network = 80002; // Amoy testnet

部署ERC20

$erc20token = new ERC20Client($vottunClient, $network, null);

$name = 'MyToken';
$symbol = 'MTK';
$decimals = 18;
$initialSupply = strval(\Web3\Utils::toWei("1000000", 'ether')); // Initial supply in Wei

$transactionHash = $erc20token->deploy($name, $symbol, $decimals, $initialSupply);
$contractAddress = $erc20token->getContractAddress();

echo "Deploy hash: {$transactionHash}";
echo "Deploy address: {$contractAddress}";

转账ERC20

$contractAddress = 'your_contract_address_here';
$erc20token = new ERC20Client($vottunClient, $network, $contractAddress);

$recipientAddress = 'recipient_address_here';
$amount = strval(\Web3\Utils::toWei("100.001", 'ether')); // Amount in Wei

$transactionHash = $erc20token->transfer($recipientAddress, $amount);
$balance = $erc20token->balanceOf($recipientAddress);

echo "Transfer hash: {$transactionHash}";
echo "Recipient balance: {$balance}";

铸造ERC721

$contractAddress = 'your_contract_address_here';
$erc721token = new ERC721Client($vottunClient, $network, $contractAddress);

$recipientAddress = 'recipient_address_here';
$ipfsUri = 'ipfs_uri_here';
$ipfsHash = 'ipfs_hash_here';
$royaltyPercentage = 10;
$tokenId = 1;

$transactionHash = $erc721token->mint($recipientAddress, $tokenId, $ipfsUri, $ipfsHash, $royaltyPercentage);
echo "Mint hash: {$transactionHash}";

待办功能

  • Web3 Core客户端
  • IPFS客户端
  • 托管钱包客户端
  • 余额客户端
  • 估算燃气客户端

贡献

欢迎为Vottun PHP SDK做出贡献。请确保您的贡献遵循以下指南

  • 从main分支创建分支并Fork存储库。
  • 如果您添加了需要测试的代码,请添加测试。
  • 确保测试套件通过。
  • 提交拉取请求!

支持

如果您遇到任何问题或需要帮助,请在该GitHub存储库上创建问题。

许可

本项目根据LGPL许可。请参阅LICENSE文件以获取详细信息。

致谢

  • 感谢Vottun团队提供API。