Crypto-Collector (OP)
Newbie
Offline
Activity: 18
Merit: 11
|
|
September 02, 2019, 07:52:37 PM Last edit: September 02, 2019, 08:15:41 PM by Crypto-Collector |
|
So using the easybitcoin.php library I'm making a test wallet controller for regtest. I have it working to generate blocks and new addresses but transactions arent working properly. I have a form that sends which address and which amount and the script is as follows for processing the transaction: $amount= (float) number_format($_POST['amount'], 8); $bitcoin->settxfee(0.0004); $txid = $bitcoin->sendtoaddress($_POST['sendTo'], $amount); Doing that when I get txinfo I get a txid and all that but the amount is 0 every time. Same if I used the code like this: $amount= $_POST['amount']; $bitcoin->settxfee(0.0004); $txid = $bitcoin->sendtoaddress($_POST['sendTo'], (float) $amount); This is very frustrating as it makes it difficult to test my app. I also hard coded 3.32 for example so it was a float to begin with and still the transaction is sent with a 0 amount. What is going on? $bitcoin->settxfee(0.0004); $txid = $bitcoin->sendtoaddress($_POST['sendTo'], 3.32); All of them I get a $txid and using $txinfo = gettransaction($txid) I can get the txid using $txinfo['txid'] but $txinfo['amount'] always returns as 0.
|
|
|
|
HeRetiK
Legendary
Offline
Activity: 3122
Merit: 2177
Playgram - The Telegram Casino
|
|
September 02, 2019, 08:18:11 PM |
|
Is this the library you are using? https://github.com/aceat64/EasyBitcoin-PHPBecause that library appears to be outdated: easybitcoin seems to be no longer working, or needs some tweaking. I have written a php function using curl. You can use this php function, if you are also looking for a solution: Just pass the method in the function and make sure to edit out your rpc details inside the function. <?php
function bitcoin($method){ $ch = curl_init(); $rpcuser='rpcusername'; $rpcpassword='rpcpassword'; $host='nodeIP'; //IP address of your node or localhost, if running locally $port='port';
curl_setopt($ch, CURLOPT_URL, "http://$rpcuser:$rpcpassword@$host:$port/"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"jsonrpc\":\"1.0\",\"id\":\"curltext\",\"method\":\"$method\",\"params\":[]}"); curl_setopt($ch, CURLOPT_POST, 1);
$headers = array(); $headers[] = "Content-Type: application/x-www-form-urlencoded"; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close ($ch); return($result); } $method="getblockchaininfo"; //bitcoin-cli method like getchaininfo,getwalletinfo etceter $lol=bitcoin($method); ?>
Cheers! It also says so on the GitHub page itself: If you are referring to another PHP library please post a link for clarification.
|
|
|
|
▄▄███████▄▄███████ ▄███████████████▄▄▄▄▄ ▄████████████████████▀░ ▄█████████████████████▄░ ▄█████████▀▀████████████▄ ██████████████▀▀█████████ █████████████████████████ ██████████████▄▄█████████ ▀█████████▄▄████████████▀ ▀█████████████████████▀░ ▀████████████████████▄░ ▀███████████████▀▀▀▀▀ ▀▀███████▀▀███████ | ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ Playgram.io ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ | ▄▄▄░░ ▀▄ █ █ █ █ █ █ █ ▄▀ ▀▀▀░░
| │ | ▄▄▄███████▄▄▄ ▄▄███████████████▄▄ ▄███████████████████▄ ▄██████████████▀▀█████▄ ▄██████████▀▀███▄██▐████▄ ██████▀▀████▄▄▀▀█████████ ████▄▄███▄██▀█████▐██████ ██████████▀██████████████ ▀███████▌▐██▄████▐██████▀ ▀███████▄▄███▄████████▀ ▀███████████████████▀ ▀▀███████████████▀▀ ▀▀▀███████▀▀▀ | | │ | ██████▄▄███████▄▄████████ ███▄███████████████▄░░▀█▀ ███████████░█████████░░█ ░█████▀██▄▄░▄▄██▀█████░█ █████▄░▄███▄███▄░▄██████ ████████████████████████ ████████████████████████ ██░▄▄▄░██░▄▄▄░██░▄▄▄░███ ██░░░█░██░░░█░██░░░█░████ ██░░█░░██░░█░░██░░█░░████ ██▄▄▄▄▄██▄▄▄▄▄██▄▄▄▄▄████ ███████████████████████ ███████████████████████ | | │ | ► | |
[/
|
|
|
Crypto-Collector (OP)
Newbie
Offline
Activity: 18
Merit: 11
|
|
September 02, 2019, 08:26:05 PM |
|
I dont think its the library, just tried sending a transaction using the cli with same result. ./bitcoin-cli -regtest sendtoaddress [address] 2.1 Returns a transaction ID, then when I run ./bitcoin-cli -regtest gettransaction [txid] The amount still says 0.. This is my most recent return for gettransaction: ./bitcoin-cli -regtest gettransaction f8d306e9649aad81e1bac5f1e61cb752f886a0d5340b4ad9ac305fb5027182cc { "amount": 0.00000000, "fee": -0.00006640, "confirmations": 0, "trusted": true, "txid": "f8d306e9649aad81e1bac5f1e61cb752f886a0d5340b4ad9ac305fb5027182cc", "walletconflicts": [ ], "time": 1567455718, "timereceived": 1567455718, "bip125-replaceable": "no", "details": [ { "address": "2N72hQwNLCXYmDnyBFDXwcUAvppm1bLLzX8", "category": "send", "amount": -2.40000000, "label": "", "vout": 0, "fee": -0.00006640, "abandoned": false }, { "address": "2N72hQwNLCXYmDnyBFDXwcUAvppm1bLLzX8", "category": "receive", "amount": 2.40000000, "label": "", "vout": 0 } ], "hex": "02000000000101519e1d7e4a983b8135148dbb32198e23b7500a407048805bd9ffd97d38fd163300000000171600148e193f47083de7efbe286f289e7034c084a7f70bfeffffff02001c4e0e0000000017a91497333f2c2bdf79ec3637fbef6f331fabb2f451aa8710bcb71b0100000017a914b9d9b20cb6cbf043cae1b361bc391d102dc6d49c870247304402207f71c6bdde891742d274d227f51d9f0e8a0477c2776c057278f035d9606eb0bf022014cb9951b6144462fe7423bf99f137c38846a3c647cf5426b27412ced26a47b201210340ce4e488b13b4c9dedabe231722211a2e4f02237ea347e81b804a714fac2d4500000000" It's looking like its maybe sending and receiving to the same address which I dont know how its possible because I literally just generated the address with getnewaddress.
|
|
|
|
|
Crypto-Collector (OP)
Newbie
Offline
Activity: 18
Merit: 11
|
|
September 02, 2019, 10:48:30 PM |
|
I'm using regtest where I have my own private blockchain not testnet. I have a balance of like 700 BTC in addresses I generated because I mined several hundred blocks.
|
|
|
|
pooya87
Legendary
Offline
Activity: 3640
Merit: 11039
Crypto Swap Exchange
|
|
September 03, 2019, 03:06:24 AM |
|
this may be another bug in bitcoin core similar to decoderawtransaction which fails to decode transactions containing witnesses properly unless you explicitly pass a Boolean (true) to tell it the transaction is a SegWit one. https://bitcointalk.org/index.php?topic=5014781.0try using a legacy transaction and see if the amount you get is zero again. this means use a regular address like a P2PKH (address starting with 1 on mainnet) and spend coins from that address. if you don't see the same problem then it must be the bug i mentioned.
|
|
|
|
Crypto-Collector (OP)
Newbie
Offline
Activity: 18
Merit: 11
|
|
September 03, 2019, 03:40:27 AM |
|
this may be another bug in bitcoin core similar to decoderawtransaction which fails to decode transactions containing witnesses properly unless you explicitly pass a Boolean (true) to tell it the transaction is a SegWit one. https://bitcointalk.org/index.php?topic=5014781.0try using a legacy transaction and see if the amount you get is zero again. this means use a regular address like a P2PKH (address starting with 1 on mainnet) and spend coins from that address. if you don't see the same problem then it must be the bug i mentioned. How do I do that in regtest mode? I'm using the current version.
|
|
|
|
pooya87
Legendary
Offline
Activity: 3640
Merit: 11039
Crypto Swap Exchange
|
|
September 03, 2019, 03:55:19 AM |
|
this may be another bug in bitcoin core similar to decoderawtransaction which fails to decode transactions containing witnesses properly unless you explicitly pass a Boolean (true) to tell it the transaction is a SegWit one. https://bitcointalk.org/index.php?topic=5014781.0try using a legacy transaction and see if the amount you get is zero again. this means use a regular address like a P2PKH (address starting with 1 on mainnet) and spend coins from that address. if you don't see the same problem then it must be the bug i mentioned. How do I do that in regtest mode? I'm using the current version. when you mine, just send the new coins to a P2PKH output instead of a P2SH (P2WPKH nested in script hash) like the one you used above. then spend those coins. that means first sending the coins to an address starting with m or n and then spending from that address.
|
|
|
|
Crypto-Collector (OP)
Newbie
Offline
Activity: 18
Merit: 11
|
|
September 03, 2019, 04:22:17 AM |
|
I use getnewaddress to generate my addresses, how do I set the type of address?
|
|
|
|
pooya87
Legendary
Offline
Activity: 3640
Merit: 11039
Crypto Swap Exchange
|
|
September 03, 2019, 04:35:46 AM |
|
I use getnewaddress to generate my addresses, how do I set the type of address?
you have to pass the optional parameter called "address_type" with "legacy". i believe the command should be typed like this: getnewaddress -addresstype legacy
more info: https://bitcoincore.org/en/doc/0.18.0/rpc/wallet/getnewaddress/
|
|
|
|
Crypto-Collector (OP)
Newbie
Offline
Activity: 18
Merit: 11
|
|
September 03, 2019, 10:03:32 PM |
|
Still the same issue when I send to address generated with legacy flag (produces address that begins with an m instead of one that begins with a 2). I think it has to do with this. How do I make it not send from the same address? "details": [ { "address": "mgt64uGFQHg6Q6hw6NBK2ZQib3zqek7CHQ", "category": "send", "amount": -15.00000000, "label": "-addresstype", "vout": 1, "fee": -0.00006720, "abandoned": false }, { "address": "mgt64uGFQHg6Q6hw6NBK2ZQib3zqek7CHQ", "category": "receive", "amount": 15.00000000, "label": "-addresstype", "vout": 1 } ],
|
|
|
|
achow101
Moderator
Legendary
Offline
Activity: 3542
Merit: 6886
Just writing some code
|
You are sending money back to yourself, of course it's going to register as 0 amount.
Amount is calculated by: amount_in - amount_out - fees. amount_in is the total value of the outputs that belong to you. amount_out is the total value of the inputs that are yours. fees is the transaction fees paid. You have 2.4 + 47.59993360 = 49.99993360 in as that's the amount you are sending + the change output; no Bitcoin is going to anyone else. You have 50 out as that is the value of the input that is being spent.And -0.00006640 as the transaction fee itself. So the final amount is 49.99993360 - 50 - -0.00006640 = 0.
In order to get an amount that is not 0, you need to send Bitcoin to an address that is not part of that wallet. You can easily do this by creating another wallet using createwallet, getting an address from it, and sending coins there.
|
|
|
|
Crypto-Collector (OP)
Newbie
Offline
Activity: 18
Merit: 11
|
|
September 04, 2019, 05:26:45 AM |
|
In electrum you can send transactions to other addresses in your wallet and it transfers it all to the new address, how come its not doing this behavior in regtest CLI? The coins are not stored in that address, when I use generatetoaddress I use a different address than the one I'm sending it to.
I'll try using createwallet
|
|
|
|
achow101
Moderator
Legendary
Offline
Activity: 3542
Merit: 6886
Just writing some code
|
|
September 04, 2019, 06:15:09 PM |
|
In electrum you can send transactions to other addresses in your wallet and it transfers it all to the new address, how come its not doing this behavior in regtest CLI? The coins are not stored in that address, when I use generatetoaddress I use a different address than the one I'm sending it to.
They are all being sent to a new address. But that new address is part of your wallet. A wallet is a collection of multiple addresses and their scripts and keys. Bitcoin Core does not treat eat address separately, they are all bundled together as a single wallet. Since you are sending coins from one address in your wallet to another address, the net value going in and out (ignoring fees) does not change with that transaction, so it lists the amount of that transaction as 0.
|
|
|
|
nc50lc
Legendary
Offline
Activity: 2604
Merit: 6416
Self-proclaimed Genius
|
|
September 05, 2019, 02:48:17 AM |
|
In electrum you can send transactions to other addresses in your wallet and it transfers it all to the new address, how come its not doing this behavior in regtest CLI? The coins are not stored in that address, when I use generatetoaddress I use a different address than the one I'm sending it to.
I'll try using createwallet
You need to specify the address when you call " sendtoaddress" like: bitcoin-cli sendtoaddress "other bitcoin address" 2.1 ( including the quotation marks) " getnewaddress" doesn't automatically select the one generated as the next receiving address. Next, I just tested Electrum, it also indicates any self-send transaction with " 0 amount sent" like BitcoinCore does. Even sending to a different address from the same wallet.
|
|
|
|
Crypto-Collector (OP)
Newbie
Offline
Activity: 18
Merit: 11
|
|
September 05, 2019, 07:35:08 AM |
|
So I used createwallet and created a sender wallet and a receiver wallet to test with where I will mine to the sender wallet and try sending it to the receiver address. From here I'm not sure how to switch between wallets. I have 3 wallet.dat files now, two of which are in folders regtest/wallets/sender and regtest/wallets/receiver so I'm assuming bitcoind automatically grabs the wallet.dat in regtest/wallets/wallet.dat. How do I switch between receiver and senders wallet.dat's to test this? I tried looking at this link of outdaated calls to see if there is an RPC call for it, theres not in the outdated API: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_listThe link to the updated list does not list API calls. It has the header that says it but its blank then moves on to hash byte order: https://bitcoin.org/en/developer-reference#bitcoin-core-apis
|
|
|
|
achow101
Moderator
Legendary
Offline
Activity: 3542
Merit: 6886
Just writing some code
|
|
September 05, 2019, 06:10:39 PM |
|
So I used createwallet and created a sender wallet and a receiver wallet to test with where I will mine to the sender wallet and try sending it to the receiver address. From here I'm not sure how to switch between wallets. I have 3 wallet.dat files now, two of which are in folders regtest/wallets/sender and regtest/wallets/receiver so I'm assuming bitcoind automatically grabs the wallet.dat in regtest/wallets/wallet.dat. How do I switch between receiver and senders wallet.dat's to test this? I tried looking at this link of outdaated calls to see if there is an RPC call for it, theres not in the outdated API: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_listThe link to the updated list does not list API calls. It has the header that says it but its blank then moves on to hash byte order: https://bitcoin.org/en/developer-reference#bitcoin-core-apisYou can get a list of available RPCs from Bitcoin Core directly using the help command, and the help documentation for each command using help <command> where <command> is the command you are interested in. In order to load a wallet, you use the loadwallet command. In order to send RPCs to that specific wallet, you use the -rpcwallet=<wallet name> option in bitcoin-cli where <wallet name> is the name of the wallet you want to access. To use the sender wallet, you would have -rpcwallet=sender, for the receiver, -rpcwallet=receiver. And for the default wallet (the one in regtest/wallets/wallet.dat), use -rpcwallet= as the default wallet has no name.
|
|
|
|
|