Author

Topic: [Help] Create raw transaction PHP (Read 538 times)

newbie
Activity: 37
Merit: 0
July 22, 2017, 05:58:09 PM
#3
It looks like you might not constructing the $json_where variable correctly... Specifically... What is this attempting to do?

Code:
$where[''] = 0.00400000;

Are you trying to set the fee? If so, don't... The fee is automatically calculated as the difference between inputs and specified outputs... You don't explicitly list it in the transaction.

Thanks man, i deleted this variable and works well.

Send me your address i will send some tips....
HCP
legendary
Activity: 2086
Merit: 4361
July 21, 2017, 12:01:07 AM
#2
It looks like you might not constructing the $json_where variable correctly... Specifically... What is this attempting to do?

Code:
$where[''] = 0.00400000;

Are you trying to set the fee? If so, don't... The fee is automatically calculated as the difference between inputs and specified outputs... You don't explicitly list it in the transaction.
newbie
Activity: 37
Merit: 0
July 19, 2017, 01:46:11 PM
#1
Hello everybody,

I having some problems to create a raw transaction, bellow my code:

Code:
    $client  = new \Nbobtc\Http\Client('http://user:ext12561244@localhost:18332');
    $send_amount = 0.00100000;
    $amount = 0;
    $i = 0;
    $j = 1;
    $command = new \Nbobtc\Command\Command('listunspent', $j,$j + 50);
    $response = $client->sendCommand($command);
    $output   = json_decode($response->getBody()->getContents(), true);
    $system_return = new \Nbobtc\Command\Command('getaddressesbyaccount', array('testes'));
    $response2 = $client->sendCommand($system_return);
    $system_output   = json_decode($response2->getBody()->getContents(), true);
   

    while($amount < $send_amount){
    foreach($output['result'] as $trans){
//var_dump($trans['amount']);
$translist[$i]['txid'] = $trans['txid'];
$translist[$i]['vout'] = $trans['vout'];
//$translist[$i]['scriptPubKey'] = $trans['scriptPubKey'];
$addr[$i] = $trans['address'];
$amount += $trans['amount'];
$i++;
if($amount > $send_amount)break;

}
        $j += 50;
    }
    //echo $amount . "\n\n";
    $address_return = $system_output['result']['0'];
    $rest = $amount - $send_amount;
    $where['mwCwTceJvYV27KXBc3NJZys6CjsgsoeHmf'] = $send_amount;
    $where["'" .$address_return. "'"] = $rest;
    $where[''] = 0.00400000;
    $json_translist = $translist;
    //echo $json_translist . "\n\n";
    $json_where = $where;
    //echo $json_where . "\n\n";

    $bitcoind = new BitcoinClient([
    'scheme' => 'http',                 // optional, default http
    'host'   => 'localhost',            // optional, default localhost
    'port'   => 18332,                   // optional, default 8332
    'user'   => 'user',              // required
    'pass'   => 'ext12561244',          // required
    ]);
    $raw= $bitcoind->request('createrawtransaction', $json_translist,$json_where);
    var_dump($raw);


Everytime i run the code i receive the folowing error:

Code:
createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,"data":"hex",...} ( locktime ) ( optintorbf )

Create a transaction spending the given inputs and creating new outputs.
Outputs can be addresses or data.
Returns hex-encoded raw transaction.
Note that the transaction's inputs are not signed, and
it is not stored in the wallet or transmitted to the network.

Arguments:
1. "inputs" (array, required) A json array of json objects
[
{
"txid":"id", (string, required) The transaction id
"vout":n, (numeric, required) The output number
"sequence":n (numeric, optional) The sequence number
}
,...
]
2. "outputs" (object, required) a json object with outputs
{
"address": x.xxx, (numeric or string, required) The key is the bitcoin address, the numeric value (can be string) is the BTC amount
"data": "hex" (string, required) The key is "data", the value is hex encoded data
,...
}
3. locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs
4. optintorbf (boolean, optional, default=false) Allow this transaction to be replaced by a transaction with higher fees. If provided, it is an error if explicit sequence numbers are incompatible.

Result:
"transaction" (string) hex string of the transaction

Examples:
> bitcoin-cli createrawtransaction "[{\"txid\":\"myid\",\"vout\":0}]" "{\"address\":0.01}"
> bitcoin-cli createrawtransaction "[{\"txid\":\"myid\",\"vout\":0}]" "{\"data\":\"00010203\"}"
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "createrawtransaction", "params": ["[{\"txid\":\"myid\",\"vout\":0}]", "{\"address\":0.01}"] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "createrawtransaction", "params": ["[{\"txid\":\"myid\",\"vout\":0}]", "{\"data\":\"00010203\"}"] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/

Someone ca give a help?


thanks in advance
Jump to: