承接 nettchain/phpsdk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

nettchain/phpsdk

Composer 安装命令:

composer require nettchain/phpsdk

包简介

SDK de PHP para la API de NettChain

README 文档

README

This is the official PHP SDK for interacting with the NettChain API, a blockchain platform that supports multiple cryptocurrencies including Bitcoin, Ethereum, Litecoin, Dogecoin, TRON, Binance Coin, Solana, Ripple, and USDT.

Requirements

  • PHP 7.4 or higher
  • Composer
  • PHP JSON extension

Installation

composer require nettchain/phpsdk

Usage

<?php

require 'vendor/autoload.php';

use NettChain\NettChainClient;

// Initialize client with global password (optional)
$client = new NettChainClient('your-api-key', 'global-password');

// Or change global password later
$client->setGlobalPassword('new-global-password');

// Create a new wallet (using global password)
$wallet = $client->createWallet(
    'my-wallet',
    'BTC'
);

// Or specify a different password for this operation
$wallet = $client->createWallet(
    'my-wallet',
    'BTC',
    'specific-password'
);

// Import an existing wallet
$wallet = $client->importWallet(
    'my-imported-wallet',
    'ETH',
    'mainnet',
    '0x123abc...456',
    'ENCRYPTED_PRIVATE_KEY'
);

// Export a wallet
$walletInfo = $client->exportWallet('0x123abc...456');
// Returns wallet information including:
// - encrypted: boolean
// - encrypted_version: string
// - name: string
// - blockchain: string
// - network: string
// - address: string

// Send Ethereum (ETH)
$transaction = $client->sendEth(
    'source-address',
    'destination-address',
    1.5,
    20000000000, // gasPrice in wei
    21000,       // gasLimit
    'password'   // optional if set globally
);

// Send ERC20 token
$transaction = $client->sendErc20(
    'source-address',    // from address
    'destination-address', // to address
    1000,               // amount
    'token-contract-address', // contract address
    20000000000,        // gasprice
    21000               // gaslimit
);

// Send Tron (TRX)
$transaction = $client->sendTron(
    'source-address',
    'destination-address',
    1.5
);

// Send TRC20 token
$transaction = $client->sendTrc20(
    'source-address',    // from address
    'destination-address', // to address
    0.000001,           // amount (minimum 0.000001)
    'token-contract-address', // contract address
    'password'          // optional if set globally
);

// Send Solana (SOL)
$transaction = $client->sendSolana(
    'source-address',
    'destination-address',
    1.5
);

// Send Dogecoin
$transaction = $client->sendDoge(
    'source-address',
    'destination-address',
    1.5,
    'change-address',
    0.0001
);

// Send Ripple (XRP)
$transaction = $client->sendRipple(
    'source-address',
    'destination-address',
    1.5
);

// Send AVAX (Avalanche)
$transaction = $client->sendAvax(
    'source-address',
    'destination-address',
    1.5
);

// Get all wallets
$wallets = $client->getAllWallets();

// Get specific wallet
$wallet = $client->getWalletByAddress('wallet-address');

// Get wallet by name
$wallet = $client->getWalletByName('wallet-name');

// Get Dogecoin UTXOs
$utxos = $client->getDogeUtxos('doge-address');

// Get cryptocurrency price
$price = $client->getCoinPrice('BTC', 'USD');

// Get batch prices for multiple cryptocurrencies
$prices = $client->getBatchPrices('BTC,ETH,LTC', 'USD,EUR');

// Validate blockchain address
$validation = $client->validateAddress('address', 'BTC');

Password Management

The client allows password management in two ways:

  1. Global Password: Can be set when creating the client or later using setGlobalPassword(). This password will be used for all operations that require it.

  2. Specific Password: Can be provided for each individual operation. This password takes precedence over the global password.

If no password is provided (neither global nor specific), the client will throw an exception.

Available Methods

Wallet Management

  • createWallet(string $name, string $blockchain, ?string $password = null): Creates a new wallet
  • getAllWallets(): Gets all user wallets
  • getWalletByAddress(string $address): Gets a wallet by its address
  • getWalletByName(string $name): Gets a wallet by its name
  • importWallet(string $name, string $blockchain, string $network, string $address, string $encryptedKey): Imports an existing wallet
  • exportWallet(string $address): Exports a wallet's information

Cryptocurrency Operations

  • sendEth(string $from, string $to, float $amount, int $gasPrice, int $gasLimit): Sends Ethereum (ETH)
  • sendErc20(string $from, string $to, int $amount, string $contractAddress, int $gasPrice, int $gasLimit): Sends ERC20 token
  • sendTron(string $from, string $to, float $amount): Sends Tron (TRX)
  • sendTrc20(string $from, string $to, float $amount, string $contractAddress, ?string $password = null): Sends TRC20 token
  • sendSolana(string $from, string $to, float $amount, ?string $password = null): Sends Solana (SOL)
  • sendDoge(string $from, string $to, float $amount, string $addressReturn, float $fee, ?string $password = null): Sends Dogecoin
  • sendRipple(string $from, string $to, float $amount, ?string $password = null): Sends Ripple (XRP)
  • sendAvax(string $from, string $to, float $amount, ?string $password = null): Sends AVAX (Avalanche)

Utilities

  • getCoinPrice(string $coin, string $currency): Gets current price of a cryptocurrency
  • getBatchPrices(string $coins, string $currencies): Gets current prices of multiple cryptocurrencies
  • validateAddress(string $address, string $blockchain): Validates a blockchain address
  • getDogeUtxos(string $address): Gets Dogecoin UTXOs

Encryption

The SDK provides encryption capabilities for secure data handling:

// Encrypt data
$encryptedData = $client->encryption->encrypt('sensitive-data', 'encryption-password');

// Decrypt data
$decryptedData = $client->encryption->decrypt($encryptedData, 'encryption-password');

The encryption method uses AES-256-GCM for secure encryption and includes:

  • Automatic IV (Initialization Vector) generation
  • Authentication tag for data integrity
  • Secure key derivation using PBKDF2
  • Base64 encoding for encrypted output

Important Security Notes:

  • All encryption/decryption operations are performed locally on your machine
  • Private keys are never sent to the server in plain text
  • When importing or exporting wallets, private keys are always encrypted before transmission
  • The encryption password is never stored or transmitted to the server

Error Handling

The client uses cURL for HTTP requests. All cURL exceptions are propagated, so you should handle CurlException in your code:

try {
    $wallet = $client->createWallet('my-wallet', 'BTC');
} catch (\CurlException $e) {
    // Handle API error
} catch (\InvalidArgumentException $e) {
    // Handle missing password error
}

Webhooks

The SDK provides webhook functionality to receive real-time notifications about blockchain events. Webhooks are supported for the following blockchains:

  • Ethereum
  • Bitcoin
  • Dogecoin
  • Ripple
  • Binance Smart Chain (BSC)
  • Polygon (MATIC)
  • Tron (TRX)
  • Solana (SOL)

Webhook Management

// Register a new webhook
$webhook = $client->registerWebhook(
    '0x123456789abcdef',  // blockchain address to monitor
    'Ethereum',           // blockchain type
    'https://your-callback-url.com/webhook'  // callback URL
);

// Get all registered webhooks
$webhooks = $client->getWebhooks();

//find a webhook
$client->findWebhook('webhook-id');

// Delete a webhook
$client->deleteWebhook('webhook-id');

Webhook Features

  • Register new webhooks to receive notifications at a specific URL
  • Query all webhooks created by the authenticated user
  • Delete registered webhooks when no longer needed
  • Automatic disabling of expired webhooks

Webhook Events

Webhooks will notify you about:

  • Transaction confirmations
  • Balance changes
  • Token transfers
  • Other blockchain-specific events

Supported Blockchains

  • Bitcoin (BTC)
  • Litecoin (LTC)
  • Dogecoin (DOGE)
  • Ethereum (ETH)
  • TRON (TRX)
  • Binance Coin (BNB)
  • Solana (SOL)
  • Ripple (XRP)
  • USDT (Tether, both ERC-20 and TRC-20)
  • Avalanche (AVAX)

nettchain/phpsdk 适用场景与选型建议

nettchain/phpsdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 05 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 nettchain/phpsdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nettchain/phpsdk 我们能提供哪些服务?
定制开发 / 二次开发

基于 nettchain/phpsdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-27