ogbitblt/electrum-interface
Composer 安装命令:
composer require ogbitblt/electrum-interface
包简介
php library interfaces with electrum to send and receive bitcoin payments without a 3rd party.
README 文档
README
Easily accept bitcoin payments using your Electrum wallet
No 3rd party libraries required, uses Electrum v4xx
This is a simple class library, developed so that all functionality can be accessed from a single object. Completely functional as a standalone library, the original design and architecture of the library is that this will be a specific component of a crypto payment processing platform, still under development as of the time of this writing.
Setting up Electrum
Prior to using this library, Electrum must be configured so that it will run as a daemon and accept JSONRPC calls. Electrum will only accept RPC calls on localhost, but this library will allow you to host electrum on another host. When you do this you must setup your firewall on the Electrum host server to forward the requests from this library to localhost and to the port configured for RPC calls within Electrum. Below are the steps for setting up Electrum:
- Download and install Electum from https://electrum.org/#download
- Electrum has to be running as a daemon on the system you install it on, the following commands all work on a linux command line.
- To start electrum as a daemon enter the command
electrum daemon -d - You must specify a username
electrum setconfig rpcuser 'user name' - and a password
electrum setconfig rpcpassword 'password' - Specify a port for electrum to listen on
electrum setconfig rpcport 7777 - Restart the electrum daemon at this point so that the new settings will be in effect.
- Then tell electrum to load the wallet
electrum load_wallet - Note: If you want to test your configuration, add the --testnet flag at the end of each of the commands above.
- At this point your electrum wallet is ready to receive RPC commands. Here is a linux script to automate the process, note you have to replace the values specified in between < >
#!/bin/sh
electrum daemon -d --testnet
electrum setconfig rpcuser <username> --testnet
electrum setconfig rpcpassword <password> --testnet
electrum setconfig rpcport 7777 --testnet
electrum stop --testnet
electrum daemon -d --testnet
electrum load_wallet --testnet
Using the client vs object manager interfaces
There are 2 ways to make calls to the electrum interface. It is always recommended that you use the client object for all of your calls, but in some instances you may want to create your own object managers. Below are examples of both using the Address manager to get a new receive address.
Example using the client object (recommended method):
$client = new ElectrumClient('user','pass','localhost',7777,false);
try {
$client->Init();
} catch(ElectrumClientConfigurationException $e) {
echo 'Electrum is not running';
return;
}
// get a new payment address using the client object manager
$address = $client->getManager(AddressManager::class)->GetNewPaymentAddress();
Example by creating the object manager (alternative method):
$client = new ElectrumClient('user','pass','localhost',7777,false);
try {
$client->Init();
} catch(ElectrumClientConfigurationException $e) {
echo 'Electrum is not running';
return;
}
// create an address manager
$addressManager = new AddressManager($client);
$address = $addressManager->GetNewPaymentAddress();
The rest of this document describes the APIs available within the library, I tried to make the documentation as clean as possible but if you find a mistake please email me and let me know .
Address Functions
Address functions are available via the AddressManager object :
$addressManager = $client->getManager(AddressManager::class);
-
AddressManager->GetNewPaymentAddress() : string
- Creates a new bitcoin payment address
- return string containing the new receive address
// ...create client and initialize
$address = $client->getManager(AddressManager::class)->GetNewPaymentAddress();
-
AdressManager->GetAddressBalance(string $address, bool $confirmed) : float
- Get the balance of the bitcoin address
- param: $address string value of the bitcoin address
- param: $confirmed bool value, true if you only want to see confirmed transactions in the balance and false otherwise
- return: a float value of the balance for the address
// ... create client and initialize
// ... get address
// pass true as the second argument if you only want confirmed transactions
// pass false if you want confirmed and unconfirmed transactions included in the balance
$balance = $client->getManager(AddressManager::class)->GetAddressBalance($address, false);
-
AddressManager->IsValidAddress(string $address) : bool
- Determines if the address is valid or not
- param: $address a string containing the address to check
- return: true if is a valid address, false otherwise
-
AddressManager->IsMyAddress(string $addres) : bool
- Determines if the address is associated with your wallet or not
- param: $address a string holding the bitcoin address to check
- return: true if the address belongs to your wallet, false otherwise.
-
AddressManager->GetAddressHistory(string $address) : array
- Get the transaction history for an address
- param: $address a string holding the address you want to get the history for
- Returns a history of transactions for the adddress in an associative array that looks like:
array(3) {
[0]=>
array(2) {
["height"] =>
int(2348296)
["tx_hash"] =>
string(64) "ae0722e99cc8c7759c0eff973dabdd247c94edf111259f11babe02aae629f3a8"
}
[1]=>
array(2) {
["height"] =>
int(2348296)
["tx_hash"] =>
string(64) "1583791b040ba101e7fbb71c8dd07ecc0b6166e2217d2f5c1f426fb0d40e7077"
}
[2]=>
array(2) {
["height"] =>
int(2348296)
["tx_hash"] =>
string(64) "787a0e4e5bcab07524da9ac60802c163b86fcd297f9649ced6fafbb2005c5adf"
}
}
Wallet Functions
Wallet functions are available via the WalletManager object:
$walletManager = $client->getManager(WalletManager::class);
-
WalletManger->GetWalletBalance(bool $confirmed = false) : float
- param: $confirmed (optional) defaults to false; set to true if you only want to include confirmed transactions in the wallet balance.
- return: float balance of the wallet.
Transaction Functions
Transaction functions are available via the TransactionManager object:
$transactionManager = $client->getManager(TransactionManager::class);
-
TransactionManager->BroadCastTransaction(string $transactionid) : string
- Broadcasts the transaction to the network
- param: $transaction string containing the transaction id
- return: string transaction hash
-
TransactionManager->IsFeeAmountValid(float $fee_level) : bool
- Determins if the fee level is valid
- param: $fee_level float 0.0 to 1.0
- returns: true if the fee level is valid and false otherwise
-
TransactionManager->GetRecommendedTransactionFee(float $level = 0.5) : float
- Returns the recommended transaction fee based on the fee level
- param: $level (optional) float value containing the fee level, defaults to 0.5
- return: a float amount containing the recommended fee amount
-
TransactionManager->GetTransactionConfirmations(string $transaction) : int
- Gets the number of confirmations the transaction has on the network
- param: $transaction string containing the transaction id
- returns: an integer value of the number of confirmations the transaction has on the network
Payment Functions
Payment functions are available via the PaymentManager object:
$paymentManager = $client->getManager(PaymentManager::class);
-
PaymentManager->PayTo(string $address, float $amount, float $fee) : string
- Pays a specified amount to the specified address
- param: $address string value holding the bitcoin address to pay
- param: $amount float amount to be paid
- param: $fee float amount of the transaction fee to pay
- return: a string containing the transaction id
-
PaymentManager->PayMax(string $address, float $fee) : string
- Pays the total wallet balance amount to the specified address
- param: $address string value holding the bitcoin address to pay
- param: $fee float amount of the transaction fee to pay
- return: a string containing the transaction id
Version Functions
Version functions are available via the VersionManager object:
$versionManager = $client->getManager(VersionManager::class);
-
VersionManager->GetElectrumVersion() : string
- Provides version info for the Electrum wallet
- return: a string containing the version info formatted as nn.nn.nn (major.minor.revision)
-
VersionManager->GetVersionInfo(string $versionInfo) : int
- Returns specific version info (major, minor, revision)
- param: VersionManager has 3 constants that can be used to retrieve version info
- VersionManager::MAJOR_VERSION
- VersionManager::MINOR_VERSION
- VersionManager::REVISION
- return: an integer value of the version info requested
$major = $versionManager->GetVersionInfo(VersionManager::MAJOR_VERSION);
$minor = $versionManager->GetVersionInfo(VersionManager::MINOR_VERSION);
$revision = $versionManager->GetVersionInfo(VersionManager::REVISION);
ogbitblt/electrum-interface 适用场景与选型建议
ogbitblt/electrum-interface 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 12 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bitcoin」 「btc」 「cryptocurrency」 「electrum」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ogbitblt/electrum-interface 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ogbitblt/electrum-interface 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ogbitblt/electrum-interface 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The BlockTrail PHP SDK, for integration of Bitcoin functionality through the BlockTrail API
Bitcoin and Altcoin Payment Gateway for Magento 2 via CoinGate
Laravel package for cryptomus.com
Cryptonator Merchant API
CoinDesk Bitcoin Price Index API for Laravel
Implementation of Bitclout API interaction through its node
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-31