In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
How to understand the USDT PHP development package OmniTool, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
The OmniTool package is suitable for rapidly increasing the support for Omni Layer/USDT digital assets for PHP applications, not only for application scenarios that use their own Omni Layer nodes, but also for lightweight deployment scenarios based on third-party Omni Layer services and offline naked transactions.
1. Brief introduction of OmniTool development package
The OmniTool development package mainly includes the following features:
Perfect RPC encapsulation of Omni Layer nodes
Support the use of own nodes or third-party services to obtain utxo collections of specified addresses
Support offline generation of omni tokens transfer naked transactions
Support for broadcasting naked transactions using own nodes or third-party services
OmniTool supports locally deployed Omnicored nodes, as well as open API provided by blockchain.info and btc.com. It is also very easy to increase support for other third-party services. You only need to refer to the code to implement the following APIs:
UtxoCollectorInterface:utxo collector
UtxoSelectorInterface:utxo filter
BroadcasterInterface: naked transaction broadcaster
ExplorerInterface: data query interface
The OmniTool software package runs under the environment of * * Php 7.1 clients *. The current version 1.0.0. The main classes / interfaces and relationships are shown in the following figure:
For a list of the main code files for OmniTool, see: http://sc.hubwiz.com/codebag/omni-php-lib/
2. Instructions for using the RpcClient class
The RpcClient class encapsulates Omni Layer's RPC interface protocol. When you create a RpcClient object, you need to pass in the node RPC URL that contains valid identity information. For example, suppose the omnicored node software installed on this machine is configured as follows:
Rpcuser:user
Rpcpassword:123456
Rpcport:8332
Then you can instantiate RpcClient using the following code:
Use\ OmniTool\ RpcClient;$client = new RpcClient (URL*/ of the RPC interface of the 'http://user:123456@localhost:8332' / * node)
In addition to the original RPC interface of Bitcoin, the Omni Core node expands additional interfaces to operate the data of the Omni layer. These extended RPC interfaces use the omni_ prefix to distinguish from the original RPC interface of Bitcoin. In order to distinguish the RPC calls of these two layers, RpcClient introduces the concept of protocol sub-module, and connects the original RPC interface of Bitcoin and the extended RPC interface of Omni to BTC sub-module and omni sub-module respectively.
For example, to get the USDT token balance of an address, you need to use the omni_getbalance call of the Omni layer, which calls the getBalance () method of the omni submodule corresponding to the RpcClient instance. The following code gets the USDT (asset ID:31) balance of the address 1EXoDusjGwvnjZUyKkxZ4UHEf77z6A5S4P:
$ret = $client- > omni- > getBalance ('1EXoDusjGwvnjZUyKxZ4UHEf77z6A5S4Please, / * address * / 31 / * Asset ID:USDT*/)
Similarly, you can use the omni_send call to perform a simple USDT transfer, which corresponds to the send () method of the omni submodule of the RpcClient instance. The following code transfers 100.0 USDT tokens from the address 3M9qvHKtgARhqcMtM5cRT9VaiDJ5PSfQGY to the address 37FaKponF7zqoMLUjEiko25pDiuVH5YLEa:
$ret = $client- > omni- > send ('3M9qvHKtgARhqcMtM5cRT9VaiDJ5PSfQGYY, / * token transfer address * /' 37FaKponF7zqoMLUjEiEiko25pDiuVH5YLEafortune, / * token transfer address * / 31, / * token ID:USDT*/ "100.00" / * number of tokens transferred * /)
The original RPC interface of bitoin layer can be accessed through the BTC sub-module of RpcClient. For example, use the listunspent call to get the utxo of the specified address in the local node:
$ret = $client- > btc- > listUnspent (6, / * minimum acknowledgements * / 999999, / * maximum confirmations * / ['mgnucj8nYqdrPFh3JfZSB1NmUThUGnmsqe'] / * address list * /)
The demo/rpc-demo.php sample code in the development package uses the RpcClient class to fully demonstrate the token issuance and transfer functions in the Omni layer. If you plan to build your own Omni Core node, I believe this example will be of great help.
3. Instructions for using Wallet class
If you don't want to build your own Omni Core node, but want to add Omni Layer/USDT support to your PHP application based on third-party API, then the easiest way is to use the offline transaction entry class Wallet.
The main function of the Wallet class is to create and broadcast Omni token transfer naked transactions or bitcoin transfer naked transactions. The basic steps for its use are as follows:
Create a Wallet instance that supports cloud API services using the Wallet::cloud () static method
Use the addKey () method to add the necessary private key to the Wallet instance, such as the private key of the transfer address, because Wallet needs to sign the naked transaction with the private key
Use the omniSendTx () method to generate Omni token transfer naked transactions, or use the btcSendTx () method Bitcoin transfer naked transactions
Broadcast naked transactions using the broadcast () method
3.1 Omni token transfer
The sample code of Omni token transfer implemented with Wallet is as follows. For more information, please see the notes:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.