In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
PHP development package how to dock Monero block chain, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
1. Gateway-Monero docking gateway
Gateway is the top-level class for interfacing with Monero block chain, which is suitable for managing multi-user addresses and transactions. It mainly includes the following methods:
NewAddress (): create a new address
Balance (): get the XMR balance of the specified address
Transfer (): transfer money
To instantiate Gateway, you need to specify the URL of the service node and the wallet node. For example, the following code uses the native Monero node to create an Gateway instance:
$opts = ['daemon_url' = >' http://localhost:28081', / / Service node URL 'wallet_url' = >' http://localhost:28083' / / wallet node URL]; $gateway = new Gateway ($opts); / / return Gateway instance 1.1 to create a new address
Use the newAddress () method of Gateway to create a new Monroe currency address for the user, for example:
$addr = $gateway- > newAddress (); / / create a new XMR address echo 'new address = >'. $addr. PHP_EOL;1.2 gets the address balance
Use the balance () method of Gateway to get the balance of the specified Monero address, for example:
$balance = $gateway- > balance ('9wviCeWe2D8XS82k2o.RrAotYPwq9Gm8'); echo' total = >'. $balance- > total. PHP_EOL; / / Total balance in piconeroecho 'unlocked = >'. $balance- > unlocked. PHP_EOL; / / unfreeze balance (in piconero)
The balance () method returns an object, and the total and unlocked fields represent the total balance and the unlocked balance of the queried address, respectively, in either piconero or pico.
1.3 Monroe money transfer
Use the transfer () method of Gateway to transfer money between the specified addresses. For example, the following code transfers 1000000 piconero from account from to account to:
$from = '9wviCeWe2D8XS82k2ovp5.. 7X1D7Geoo2RrAotYPwq9Gm8 benchmark to =' A2GmyHHJ9jtUhPiwoAbR2tX.. uzKf6RGGgZTFTpVC4QxAiAXtransactions amount = 1000000 / unit: piconero$txid = $gateway- > transfer ($from,$to,$amount); echo'tx hash = >'. $txid. PHP_EOL
The transfer () method returns the hash of the transfer transaction.
The piconero is the smallest unit of Monroe currency, 1 minero = 10 ^ 12 piconero.
Monroe currency Php development package download address: http://sc.hubwiz.com/codebag/monero-php-lib/
2. RpcClient-Rpc Api client
RpcClient is the encapsulation of the official RPC protocol of Monroe, which is used to access the official service node (Daemon) and wallet node (Wallet) in PHP applications. Click here to view the RPC API Chinese documents of Monero.
Creating an RpcClient instance is simple, as long as the RPC API of the incoming node accesses the URL. For example, the following code instantiates a RpcClient object where all RPC call requests are sent to the Monero service node specified by the parameter URL:
$daemon = new RpcClient ('http://localhost:28081'); / / returns client instance 2.1 to call JSON RPC API
For the JSON RPC API in the node, you can call it directly with the method name. For example, the service node provides a get_block_count method to get the number of chunks on the chain, using the RpcClient object as follows:
$ret = $daemon- > get_block_count (); / / call JSON RPC APIecho 'block count = >' with the same name. $ret- > count. PHP_EOL
If the JSON RPC API method requires parameters, such as the get_block method provided by the service node to obtain chunk data, you need to pass in the chunk height or chunk hash, then organize the required parameters into an associative array and pass them in. For example, to view block data with a height of 10 inches:
Ret = $daemon- > get_block (['height'= > 100]); echo' number of txs = >'. $ret- > block_header- > num_txes. PHP_EOL;2.2 calls other RPC API
The service node of Monero also provides other access interfaces that are not JSON RPC specifications, such as the method / get_transactions to query transaction data by transaction ID. These non-JSON RPC have their own specific access-side nodes, so we can use the post () method of RpcClient to specify the access-side nodes and request parameters.
For example, the following code gets the transaction data for the specified hash a6fa.b8fs:
$inputs = ['txs_hashes' = > [' a6fa97b7c1d7a4f68a8041a2e7ca7a250d01391f14a0d5947b0936dca1f2b8f3']; $ret = $daemon- > post ('/ get_transactions',$inputs); / / non-JSON RPC APi call echo 'number of missed tx = >'. Count ($ret- > missed_tx). PHP_EOL;echo 'number of found tx = >'. Count ($ret- > txs). PHP_EOL;3, FaceValue-Monroe denomination
Monroe coins have different units of measure, from the smallest atomic unit piconero to the largest meganero:
The FaceValue class encapsulates the face value calculation logic of Monroe dollars / XMR, and you can think of FaceValue as the number of Monroe coins containing units of measurement. So when instantiating a FaceValue object, you need to specify both quantities and units, for example, to create a FaceValue object that contains 20.34 Monroe coins to represent sales revenue:
$sales = FaceValue::parse ('20.34 mo'); echo' sales = >'. $sales. PHP_EOL; / / 20.34 mo
FaceValue encapsulates the Monroe currency denomination conversion logic, so you can get the amount of sales revenue above converted into other units:
Echo 'sales in pico = >'. $sales- > pico. PHP_EOL; / / 20.340000000000echo 'sales in mega = >'. $sales- > mega. PHP_EOL; / / 0.00002034
You can also directly update the specified unit, such as sales to 203.4 mo:
$sales- > mo = 203.4; echo 'sales in mega = >'. $sales- > mega. PHP_EOL; / / 0.00020344, Mnemonic-mnemonic
Use the Mnemonic class to create Monero proprietary types of mnemonics, or to convert mnemonics into cryptographic seeds. Monero's mnemonic words contain 25 words, and the vocabulary is different from Bitcoin. Here is an example of a Monero mnemonic:
Vipers opposite alpine debut rebel essential enigma irony moon incur fugitive tufts touchy moisture hijack chlorine vivid textbook chrome bias nimbly hamburger wayside tarnished tarnished4.1 generates new Monero mnemonic words
Mnemonic provides a static method new () to generate new mnemonics. For example, the following code generates a random set of new mnemonics:
$words = Mnemonic::new (); echo 'mnemonic = >'. $words. PHP_EOL;4.2 converts mnemonic words into cryptographic seeds
Mnemonic provides a static method seed () to convert the specified mnemonic into a cryptographic seed for use in operations such as the recovery of key pairs. For example, the following code converts mnemonic words into cryptographic seeds:
Seed = Mnemonic::seed ('vipers opposite alpine debut rebel essential enigma irony moon incur fugitive tufts touchy moisture hijack chlorine vivid textbook chrome bias nimbly hamburger wayside tarnished tarnished'); echo' seed = >'. $seed. PHP_EOL; / / 78bf0d6c8e877c8ffbf9701e8063a690a91295d6f3a576e7b61c8c7829d8a7e0
Monroe currency Php development package download address: http://sc.hubwiz.com/codebag/monero-php-lib/
5 、 Credential
The credential class Crendential is used to manage the personal identity certificate-key pair on the chain of Monero blocks:
5.1 generate random identity
You can generate a random credential, for example:
$credential = Credential::new (); / / generate random key pair 5.2 rebuild identity credential
You can also use the previously saved mnemonic to rebuild the identity certificate, for example:
$seed = Mnemonic::seed ('vipers opposite alpine debut rebel essential enigma irony moon incur fugitive tufts touchy moisture hijack chlorine vivid textbook chrome bias nimbly hamburger wayside tarnished tarnished'); $credential = Credential::infer ($seed); / / derive the key pair from the seed 5.3.Consumer key and view key
Monroe currency is a private currency, and transactions entering blockchains are encrypted and confused, so compared with other blockchains, Monero requires two sets of keys: consumer key (spend key) and view key (view key), which is similar to identity key pairs in other blockchains, while viewing keys allows users to view encrypted and confused blockchain transactions so that wallets can track the transaction output.
For example, the following code looks at the consumer key pair of the credential object and looks at the key pair:
Echo 'secret spend key = >'. $credential- > secretSpendKey (). PHP_EOL; echo 'public spend key = >'. $credential- > publicSendKey (). PHP_EOL;echo 'secret view key = >'. $credential- > secretViewKey (). PHP_EOL;echo 'public view key = >'. $credential- > publicViewKey (). PHP_EOL;6 、 Address / SubAddress / IntegratedAddress
Standard address implementation of Address:Monero Block chain
The implementation of the subaddress in the SubAddress:Monero block chain, which is derived from the standard address and the two-level index sequence number
Implementation of integrated address in IntegratedAddress:Monero block chain. The integrated address is derived from standard address and payment ID.
6.1 Decoding standard address string
The address string is decoded using the static method decode () of the Address class, and the returned Address object contains the decoded information.
For example, the following code decodes the specified address and displays the network to which the address belongs, consumes the public key, and looks at the public key:
$addr = Address::decode ('9wviCeWe2D8XS82ovp5EUYLzBt9pYNW2LXUFsZiv8S3Mt21FZ5qQaAroko1enzw3eGr9qC7X1D7Geoo2RrAotYPwq9Gm8'); echo' network = >'. $addr- > network (). PHP_EOL;echo 'spend key = >'. $addr- > spendKey (). PHP_EOL;echo 'view key = >'. $addr- > viewKey (). Derivation of PHP_EOL;6.2 address
Call the address () method of the Credential object to get the Monroe currency address of the credential object. For example:
$addressMain = $credential- > address ('main'); / / return the main network address echo' address@mainnet = >'. $addressMain. PHP_EOL;$addressMain = $credential- > address ('main'); / / return the test network address echo' address@testnet = >'. $addressTest. PHP_EOL
The address () method returns an Address object.
6.3 use an integrated address
Using the generateIntegratedAddress () method of the Address object, you can derive the integrated address IntegratedAddress object from the standard address:
$addr = $credential- > address ('test'); $ia = $addr- > generateIntegratedAddress (); echo' ia = >'. $ia. PHP_EOL;echo'ia payment id = >'. $ia- > paymentId (). PHP_EOL
The integrated address is suitable for merchants' order charges, and a large number of Monero vouchers and standard addresses can be avoided by generating a different payment ID for each order.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.