Bitcoin Forum
March 19, 2024, 04:18:19 AM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Proper API Parameter Formatting  (Read 1413 times)
a63ntsm1th (OP)
Member
**
Offline Offline

Activity: 95
Merit: 11


View Profile
September 11, 2012, 06:42:38 AM
 #1

Working on a little PHP project I got going here. As a hobbyist I'm not a pro by any means, and I was unable to find specific information on this.

Starting with the example code from the Wiki:
Code:
$bitcoin = new jsonRPCClient('http://user:PW@127.0.0.1:8332/');
 
  print_r($bitcoin->getinfo()); echo "\n";

Obviously works as does, for example:

Code:
print_r($bitcoin->getaddressesbyaccount('user')); echo "\n";

However this doesnt work?:
Code:
print_r($bitcoin->getrawmempool()); echo "\n";

JSON is new for me so is it something about the formatting of the parameters being passed to the API?
But getrawmempool needs no other paramaters just as getinfo doesn't... or does it? Maybe its my client?

Also other API calls seem to be hit and miss, so clearly I'm missing something important and probably obvious... would love a little help Smiley

Client Info:
Code:
Array
(
    [version] => 60300
    [protocolversion] => 60001
    [walletversion] => 10500
    [balance] => 2.6432
    [blocks] => 198267
    [connections] => 8
    [proxy] =>
    [difficulty] => 2694047.952955
    [testnet] =>
    [keypoololdest] => 1312129826
    [keypoolsize] => 101
    [paytxfee] => 0
    [errors] =>
)

just my .02 btc
1710821899
Hero Member
*
Offline Offline

Posts: 1710821899

View Profile Personal Message (Offline)

Ignore
1710821899
Reply with quote  #2

1710821899
Report to moderator
1710821899
Hero Member
*
Offline Offline

Posts: 1710821899

View Profile Personal Message (Offline)

Ignore
1710821899
Reply with quote  #2

1710821899
Report to moderator
1710821899
Hero Member
*
Offline Offline

Posts: 1710821899

View Profile Personal Message (Offline)

Ignore
1710821899
Reply with quote  #2

1710821899
Report to moderator
Even if you use Bitcoin through Tor, the way transactions are handled by the network makes anonymity difficult to achieve. Do not expect your transactions to be anonymous unless you really know what you're doing.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
a63ntsm1th (OP)
Member
**
Offline Offline

Activity: 95
Merit: 11


View Profile
September 11, 2012, 06:54:53 AM
 #2

Yeah so clearly obviously I need version 7..... bitcoin.org is 6.3 so i guess its compiling time??

just my .02 btc
Pieter Wuille
Legendary
*
Offline Offline

Activity: 1072
Merit: 1170


View Profile WWW
September 11, 2012, 10:07:18 AM
 #3

See https://bitcointalk.org/index.php?topic=106236.0

I do Bitcoin stuff.
a63ntsm1th (OP)
Member
**
Offline Offline

Activity: 95
Merit: 11


View Profile
September 11, 2012, 10:22:21 AM
 #4

Thanks! am dl'ing now.

While I'm waiting (re dl'ing the blockchain, was having problems with dbase errors) I am wondering exactly how bitcoin transactions are formatted.

Does the entire output of a transaction have to be spent when using it as an input for a new transaction? If so can the address of that original output be an output on the subsequent transaction ie. returning the change to the original address?

Working with offline wallet concept so will be generating and signing raw transactions through the API.

just my .02 btc
Pieter Wuille
Legendary
*
Offline Offline

Activity: 1072
Merit: 1170


View Profile WWW
September 11, 2012, 11:12:43 AM
 #5

Yes, transaction inputs always spend one previous transaction output completely.

Change addresses is something that doesn't exist at the protocol level (arguably, even addresses don't). it's just an artefact of how wallets work.

If you use the raw transaction API, you can implement wallets that work any way you like - including ones that return change back to the original output address. In general, this is not a good idea in my opinion, as it decreases privacy (it makes it obvious which output is change and which is real payment) and encourages address reuse, but it may come in handy in certain situations.

I do Bitcoin stuff.
a63ntsm1th (OP)
Member
**
Offline Offline

Activity: 95
Merit: 11


View Profile
September 13, 2012, 03:45:07 AM
 #6

Thanks to for all the help, been fun learning the API

only 1 problem remains, I can't get sendrawtransaction to work.  I can get raw hex (as ouputed from signrawtransaction) as follows:
Code:
$bitcoin = "" //connect to server

$signedtx = $bitcoin->signrawtransaction($inputs,$outputs);
Outputs
Code:
Array
(
   [hex] => 0100..........
   [complete] => 1
)

After some trouble I even dump into non array...
Code:
$signedHEX = $signedtx['hex'];
however still no luck with:
Code:
$senttx = $bitcoin->sendrawtransaction($signedHEX);

var dumps show both the array and the var both string(518)

all my other code runs, just this one line...

just my .02 btc
a63ntsm1th (OP)
Member
**
Offline Offline

Activity: 95
Merit: 11


View Profile
September 13, 2012, 04:11:11 PM
 #7

After further testing:
my $signedHEX returns fine from decoderawtransaction

possible bug?

will try sending already confirmed transactions so see if I can at least get an error.

Any help appreciated.

just my .02 btc
a63ntsm1th (OP)
Member
**
Offline Offline

Activity: 95
Merit: 11


View Profile
September 13, 2012, 04:16:04 PM
 #8

did send $origrawtx where outputs are from, no response from API, no error.

Should at least get an error no?

just my .02 btc
a63ntsm1th (OP)
Member
**
Offline Offline

Activity: 95
Merit: 11


View Profile
September 13, 2012, 05:01:46 PM
Last edit: September 13, 2012, 07:18:03 PM by a63ntsm1th
 #9

at command line:

did senrawtransaction with existing tx and got error "already in block...."

sent my signed tx and got:

error: {"code":-22,"message":"TX rejected"}

so I guess something is wrong..... everything seems ok?

for reference here is the final signed tx which can be decoded using decoderawtransaction and everything looks ok?

Code:
0100000001f334b858fdee8ae33b6a56010b31aa4c192b5c6b01c4950421d70bbb0620c834010000008c4930460221009efd04aaf24cebbe2d063226955e44391cde6c45c40e51ec8288d0c36f7cbcfa022100daec10ba35b2bf86aff4eb0f6674747bc2da1f0e601f40e96897b6243b24700501410482fc9dccc054288979532fe8432a730c89ed0895be480e181292ffef27ea8c032bc9786baf46585def16ce336aa7cbe51367bd1d0964736935fffc28bf4650f8ffffffff02a0860100000000001976a9146deb5c5ff3eeda25ef41a190d029d7331df6faa788ace00f9700000000001976a91408510f40444f0210b4d2df6e650c3e7004a938df88ac00000000

Also decoding existing transaction and compare with my transaction at command line, seems ok.

using print_r however:

existing transaction has element [hex] at the beginning of the array, this is the hex of the signed transaction it appears, whereas my tx starts with [txid] (no this is just the [verbose=1] returns the object, with its own reference in the first array element).

just my .02 btc
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!