monero-integrations / monerophp Goto Github PK
View Code? Open in Web Editor NEWMonero PHP library + JsonRPC Client
License: MIT License
Monero PHP library + JsonRPC Client
License: MIT License
Is there any way to use a 'hardcoded' fee, instead a dynamic one, when sending payments?
All the best;
jaheller
Hello, I noticed we use a SHA3 class, could we use native PHP SHA-3 when available? Is there anything which prevents us from doing this?
#1: There's a useful option for both of these commands in the CLI and GUI, but that's not reflected in the walletRPC.php.
#2: Checking check_spend_proof with a signature not created with the corresponding txid results in an error "incorrect signature size" (which throws an exception), rather than a "good=false" return which is what is given if it's the correct txid but bad signature.
I think it's not best thing to do to use global namespace, lets do it in our own
I have my daemon running and its currently downloading the blockchain. When I can run other commands like getlastblockheader()
I get output.
"block_header" => array:20 [▼
"block_size" => 0
"cumulative_difficulty" => 0
"cumulative_difficulty_top64" => 0
"depth" => 0
"difficulty" => 0
"difficulty_top64" => 0
"hash" => ""
"height" => 0
"major_version" => 0
"miner_tx_hash" => ""
"minor_version" => 0
"nonce" => 0
"num_txes" => 0
"orphan_status" => false
"pow_hash" => ""
"prev_hash" => ""
"reward" => 0
"timestamp" => 0
"wide_cumulative_difficulty" => ""
"wide_difficulty" => ""
]
"credits" => 0
"status" => "BUSY"
"top_hash" => ""
"untrusted" => false
But when trying to run get_connections
I get the following error..
Request have return error: Method not found; Request: {"jsonrpc":"2.0","method":"get_connections","params":null};
Multiple open wallets can not be made. This ridiculous is using the last purse
in the website;
Amy getbalance request
Jones getbalance request
Mark getbalance request
Lee getbalance request
At the same time, OpenWallet is involved
this code is dead since php version is required to be at least 5.6
monerophp/src/jsonRPCClient.php
Line 216 in 72fe8b0
Might I suggest making the following addition to walletRPC.php:
/**
*
* Refresh the wallet after opening
*
* @param int $start_height Block height from which to start (optional)
*
* @return object Example: {
* // TODO example
* }
*
*/
public function refresh($start_height = null)
{
$params = array('start_height' => $start_height);
return $this->_run('refresh', $params);
}
To support the refresh() RPC call as documented here: https://web.getmonero.org/resources/developer-guides/wallet-rpc.html#refresh
Cheers
Send monero to a number of recipients.
Inputs:
Outputs:
For some reason, the public addresses i am getting are not valid
$crypto_note = new Cryptonote;
$hex_seed = $crypto_note->gen_new_hex_seed();
$address = $crypto_note->address_from_seed($hex_seed);
$is_valid_address = $crypto_note->verify_checksum($address); //is false
Here is a detailed output :
hex seed: 73dd6d63f0078e5b22db04b5a4e95247b1620c12762c4f89edea51c76bcb5da8
public address: 47BBbiKw29U2RAvscPNny5Q96nWEScga9ANoMyKUGRdKbe1Ygzm8BaEiBWBbDMWqUdeAeKjNvE4kPYB7pW7WDdT928
is valid address: verify_checksum returned false
private spend key: 3196d3c1e828d6eac2ba5857f2269d76b0620c12762c4f89edea51c76bcb5d08
private view key: 296a9ddb344a78a10e0b53bdc8855828b6aa72bff266beaea63a09729eea6906
public spend key: 9288f05f5464bf08785c9298d197908a57ca60858dd9e6380df6e441df55e2cf
public view key: 166eeca7dff4a7f634a507135edecade33dd2a8654a638ba613ad806177e2c41
Following the tool at https://xmr.llcoins.net/addresstests.html , all the spend/view keys are correct, but the address should be
47BBbiKw29U2RAvscPNny5Q96nWEScga9ANoMyKUGRdKbe1Ygzm8BaEiBWBbDMWqUdeAeKjNvE4kPYB7pW7WDdT98QKbKku
not
47BBbiKw29U2RAvscPNny5Q96nWEScga9ANoMyKUGRdKbe1Ygzm8BaEiBWBbDMWqUdeAeKjNvE4kPYB7pW7WDdT928
It is like Cryptonote::encode_address() based on base58::encode is not correct.
Also i am able to generate a subaddress, i don't know how to verify it, but it may be erroneous as well as it is using base58::encode() too.
$sub = $crypto_note->generate_subaddress(0, 0, $private_view_key, $public_spend_key);
Which will generate (based on the hex seed from above)
89WJ3xCkoAoMzHXHGKhBxwA2sWXdeczfxESZtBnjA25pF7iXGAu7Ch99VSJeWfFSYdhVpFQhzt6vF3AySXDuNv9VVJfW2BK
System: Ubuntu 18.04
PHP: 7.3.9
In #54 I let an errant $new_amount
slip in, which was undefined and caused transfer
calls to fail. A comprehensive unit testing suite (or at least having example.php test each and ever method) would have caught this issue.
It's really weird. I've tried with all sorts of combinations of parameters, but it only returns an empty array. I decided to settle on incoming_transfers for the time being, and that worked but it didn't seem to filter by subaddress, when I had the subaddress index, for example '3', fed to it.
Am I doing something wrong? I'm calling the functions with $WalletRPC->get_transfers().
I appreciate any help! :)
When calling the get_transfers method with an array parameter I get an "Undefined offset: 0" exception.
Example code:
$transfer_params = array(
'input_types' => array('in', 'out'),
'account_index' => 0,
);
$transfers = $walletRPC->get_transfers($transfer_params); //<-- Exception here
Offending source line:
1347| $params = array('account_index' => $account_index, 'subaddr_indices' => $subaddr_indices, 'min_height' => $min_height, 'max_height' => $max_height);
1347| for ($i = 0; $i < count($input_types); $i++) {
> 1348| $params[$input_types[$i]] = true;
1349| }
1350| }
If I change the following source line from:
1324| if (is_object($input_types)) { // Parameters passed in as object/dictionary`
to
1324| if (is_array($input_types)) { // Parameters passed in as array?`
then it works fine.
The documentation says that you can pass an object but the only way I could get it to work was by changing it to an array. Is there a better way to construct the $transfer_params
parameter in my example?
Lines 181 to 185 in 68900c3
please see
http://sandbox.onlinephpfunctions.com/code/bbb3f59200711389962f0860e7df3b826a810c4b
Your input validation is always true, so you don't catch unwanted types.
use https://www.php.net/manual/en/function.is-float.php
and
https://www.php.net/manual/en/function.is-int.php
Monero recently did a hardfork to move away from the payment ID model, and implemented a new address format that included payment id in the address. Has this been implemented yet in this library? Thanks
Does the RPC support this? Or would I need to shell_exec(?) my way through monero-wallet-cli --generate-from-view-key
and then use the rpc to open_wallet?
Is there any plan to support using mnemonics without an RPC connection? Specifically generating a new random mnemonic and reading/validating a mnemonic.
I see there is already offline support for creating addresses and sub-addresses.
hello i have problem, when i using the getbalance function etc rpc work fine, but when i using the transfer function the result is eror Response Http Error - 401 Unauthorized but the transaction in wallet is successfull. how to fixed the error response ?
Thank you
Thank you for the library. It's awesome because it helps me to work with monero more easily.
But during looking at the code, I've found that code does not look very pretty (at least to me).
What I want is to encourage use of code styles. The best one that I see at the moment is https://github.com/doctrine/coding-standard ( with we can configure)
Currently SSL validation is disabled via:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Line 132 in 7d0b2c3
I suggest to:
CURLOPT_SSL_VERIFYHOST, '2'
CURLOPT_SSL_VERIFYPEER, '1'
Thus it will be easier to integrate this library into new projects & maintain library upgrades.
for example: have a look at: (similar library?)
https://packagist.org/packages/psychiccat/monero-php
which is currently the only result for searching monero in packagist:
https://packagist.org/search/?q=monero
Work progressing in https://github.com/sneurlax/monerophp#feature/rpc (src/daemonRPC.php)
JSON RPC methods:
getblockcount
on_getblockhash
getblocktemplate
submitblock
getlastblockheader
getblockheaderbyhash
getblockheaderbyheight
getblock
get_connections
get_info
hard_fork_info
Testing:
getblockcount
on_getblockhash
getblocktemplate
getlastblockheader
getblockheaderbyhash
getblockheaderbyheight
getblock
get_connections
get_info
hard_fork_info
Note: testing for submitblock
deferred
I have to use --disable-rpc-login in monero-wallet-rpc but i want to use authorized rpc. So how to use username and password in example.php? I have tried monero:password@ip instead of ip in example.php but it's didn't work. It show '401 Unauthorized' in browser. I want to make explorer and wallet website with free api. Is it safe to use rpc without login? Thanks.
jsonRPCClient.php on line 107 make false error when json_last_error_msg returns "No error" message.
fix:
$this->validate( !is_null($jsonErrorMsg) && $jsonErrorMsg !== 'No error' , $jsonErrorMsg . ': ' . $responseMessage);
Since php 5.6 is out of date, I think you need to rise the version to 7.2 (since it's least supported currently see http://php.net/supported-versions.php)
Also think way you can introduce some kind of strict types in your project.
Work progressing in https://github.com/sneurlax/monerophp#feature/rpc (src/walletRPC.php)
JSON RPC methods:
getbalance
getaddress
getheight
transfer
transfer_split
sweep_dust
sweep_all
store
get_payments
get_bulk_payments
get_transfers
get_transfer_by_txid
incoming_transfers
query_key
make_integrated_address
split_integrated_address
stop_wallet
make_uri
parse_uri
rescan_blockchain
set_tx_notes
get_tx_notes
sign
verify
export_key_images
import_key_images
get_address_book
add_address_book
delete_address_book
rescan_spent
start_mining
stop_mining
get_languages
create_wallet
open_wallet
Testing:
getbalance
getaddress
getheight
transfer
transfer_split
sweep_dust
sweep_all
store
get_transfers
incoming_transfers
query_key
make_integrated_address
split_integrated_address
stop_wallet
make_uri
parse_uri
rescan_blockchain
set_tx_notes
get_tx_notes
sign
export_key_images
import_key_images
get_address_book
add_address_book
delete_address_book
rescan_spent
start_mining
stop_mining
get_languages
create_wallet
open_wallet
The latest version on the packagist https://packagist.org/packages/monero-integrations/monerophp#dev-master is 16b39cd but on the github is the commit hash b9aed56 .
Default mixing in Monero clients were updated to 11. We should increase it here too for more anonymity.
I think it will be nice to lock the package version. As first release, for example, you can set version to 0.1.0 and then if you want to break the things, do it in 0.2 branch (or master but don't do release unless it's stable)
Hello,
I coudnt get the result from monero wallet after the installation of both wallet and this plug in. I changed the ip and port number in the example.php file.but i coudnt get the expected reply. how can i get the result.is there any additional settings is needed for the proper integration.
You can call the rpc with:
curl -X POST http://127.0.0.1:18082/json_rpc \-H 'Content-Type: application/json' \-d '{"jsonrpc":"2.0","id":"0","method":"get_transfer_by_txid","params":{"txid":"<TX_HASH>"}}'
New methods were added in 0.12.0.0, especially regarding subaddresses. Here are the methods that aren't wrapped yet:
create_address
label_address
get_accounts
create_account
label_account
get_account_tags
tag_accounts
untag_accounts
set_account_tag_description
sweep_unmixable
sweep_all
(parameter updates)sweep_single
relay_tx
set_attribute
get_attribute
get_tx_key
check_tx_key
get_tx_proof
get_spend_proof
check_spend_proof
get_reserve_proof
check_reserve_proof
is_multisig
prepare_multisig
make_multisig
export_multisig_info
import_multisig_info
finalize_multisig
sign_multisig
submit_multisig
Thanks for the API. I have cloned and run this code, but it seems that for some reason your example.php file cannot find the daemonRPC class? When running the code I get this error
Fatal error: Uncaught Error: Class 'daemonRPC' not found in /var/www/html/monerophp/example.php:11 Stack trace: #0 {main} thrown in /var/www/html/monerophp/example.php on line 11
After two request i start to get this error, did this not happen a few weeks ago?
018-11-29 00:41:46.706 [RPC0] ERROR wallet.wallet2 src/wallet/wallet2.cpp:4582 !is_keys_file_locked(). THROW EXCEPTION: error::wallet_internal_error
My code is written in Laravel. Whenever I try to generate an address + payment ID using make_integrated_address, I always get the fallowing error in laravel.log:
[2021-02-09 18:32:42] local.ERROR: Request have return error: Method not found;
Request: {"jsonrpc":"2.0","method":"make_integrated_address","params":{"payment_id":null}};
My code:
Thank you!
Some issues after the recent autoloading changes:
psr-4 is case sensitive, i.e. cryptonote.php must be Cryptonote.php, or the class renamed. Same with Serialize, Varint.
Namespaced classes using the standard Exceptions class also now need 'use Exception;'
Getting rid of response id as for changes in v0.17
Work progressing in https://github.com/sneurlax/monerophp#feature/rpc (src/daemonRPC.php)
These methods are accessible via their own route (not /json_rpc
. I haven't figured out how to access them using jsonRPCClient.php
yet.)
/getheight
/gettransactions
/is_key_image_spent
/sendrawtransaction
/get_transaction_pool
/stop_daemon
Testing:
/getheight
/gettransactions
/is_key_image_spent
/sendrawtransaction
/get_transaction_pool
/stop_daemon
Input validation:
/is_key_image_spent
/sendrawtransaction
Generating a Monero address by PHP library!
bigint library for generating seed
base58 library
Monero functions for generating address
Monero "Config" (https://github.com/mymonero/mymonero-core-js/blob/master/monero_utils/monero_config.js)
Should we create a repo that will contain the library for a general cryptocoin based on cryptonote algorithm?
The wallet RPC documentation allows for filtering of transfers by block height. The monerophp get_transfers
method has the optional $min_height
and $max_height
parameters but they don't work unless the filter_by_height
parameter is also set, which it isn't
I was having fits trying to get a certain transfer to go today. Tracking it down it turns out that an amount submitted for transfer as 0.06784267 was getting sent to the wallet daemon as 67842669999.99999.
Here's a log snippit:
Blockchain submitTransaction: address: xyz, amount: 0.06784267
...
{"jsonrpc":"2.0","method":"transfer","params":{"destinations":[{"amount":67842669999.99999,"address":"xyz"}],"mixin":6,"get_tx_key":true,"payment_id":"","account_index":0,"subaddr_indices":"","priority":1,"do_not_relay":false},"id":4}
Digging into it I discovered that PHP seems to like to take floats and do crazy things with them inside of json_encode(), so I figured somewhere along the line a conversion was happening and it was coming out a float before going into json_encode(). The culprit turned out to be walletRPC.php's _transform() method. Changing it from this:
public function _transform($amount = 0) { return $amount * 1000000000000; }
to this:
public function _transform($amount = 0) { return intval($amount * 1000000000000); }
managed to get me a transfer amount of 67842669999 ... still not right. So I ended up with this:
public function _transform($amount = 0) { return intval(bcmul($amount, 1000000000000)); }
and now everything works fine.
{"jsonrpc":"2.0","method":"transfer","params":{"destinations":[{"amount":67842670000,"address":"xyz"}],"mixin":6,"get_tx_key":true,"payment_id":"","account_index":0,"subaddr_indices":"","priority":1,"do_not_relay":false},"id":4}
Hope that helps someone!
Syntax errors:
Line 75:
if (!is_array($bin) {
should be:
if (!is_array($bin)) {
Line 97:
if (!is_string($str) {
should be:
if (!is_string($str)) {
Type check error:
Line 220, double is valid.
if (!is_int($index)) {
should be:
if (!is_int($index) && !is_float($index)) {
When autoloading, an exception will try to load a class named 'MoneroIntegrations\MoneroPhp\Exception' resulting in a class not found error.
After line 30:
namespace MoneroIntegrations\MoneroPhp;
re-add:
use Exception;
Hi there,
I have a script running on cronjob, and when sending a payment with this script everything works great. However, for the PHP/RPC to report the correct unlocked_balance again it needs the RPC daemon to be restarted (or the Monero daemon - either works). I'm uncertain why this is happening, the monero-wallet-cli seems to always show the correct unlocked_balance so I think it has something to do with this script and Monero RPC, or maybe just Monero RPC?
so i followed the steps in the getting started section, and now i have a web page that looks like the example web page, but the rest of the docs are way above my head.
I dont know php. I just have a simple html apache website hosted on a debain 10 vps.
I just want a webpage that functions the same as the "merchent view" in the regular gui wallet. Or somethign like the wordpress woocommerce plugin.
When trying to use the transfer function, the wallet rpc gives error:zero_destination and and warning: N5tools5error16zero_destinationE: destination amount is zero
I am using $walletRPC->transfer() among other functions, and whenever I run this command, the function returns null instead of error messages or resulting information from the transfer() function.
For example, I ran the following command:
$result = $walletRPC->transfer(0.00001, '43CHhRBuqiPFevrGEnQeSR76CMhKnV21AfHDsp47oY3CH7dBLFE7egBT2vT3niBXWC8k4WzJ8zFkLdTYVKKuBpwhVXiq7ZS', 'd9e3f557812a49ddaaa096555b22e658d88052c09ec64bde9bcc2be905fb04a2');
$result
was NULL, despite my monero-rpc log showing these errors.
ERROR wallet.wallet2 src/wallet/wallet2.cpp:8369 needed_moner + min_fee > unlocked_balance_subtotal. THROW EXCEPTION: error:not_enough_unlocked_money.
What is the correct way to see my error messages through this API?
Thanks!
Actually if you pass params, the library will give an error! This hasn't implemented yet!
I was looking at the code and noticed that it will be cool to use guzzle instead of/ inside of jsonRPCClient
since guzzle does all the dirty work that you need to do your self (doing all the stuff with curl_setopt)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.