Bit-Wasp/bitcoin-lib-php

How to use createrawtransaction and set fees?

cevin opened this issue · 18 comments

cevin commented
How to use createrawtransaction and set fees?
afk11 commented

Have you looked in the examples folder for it's usage?

cevin commented
//  value of output is 0.0002
$inputs = array(
    array(
        'txid' => '6737e1355be0566c583eecd48bf8a5e1fcdf2d9f51cc7be82d4393ac9555611c',
        'vout' => 0,
        'value' => 0.0002,
        'scriptPubKey' => '76a9147e3f939e8ded8c0d93695310d6d481ae5da3961688ac',
    )
);

about key value in RawTransaction::create did not use. Why at here?

If I send 0.0002 to address_a I set key value is $to_amount+0.0001 and not set change address, this is set a transaction fee?

like this

$output = ['address_a' => (int)bcmul(0.0002,100000000)];
$input = [[
    'txid'=>'somevalue',
    'vout' => 0,
    'scriptPubKey' => 'from decode from address last transaction id',
    'value' => 0.0002+0.0001
]];
afk11 commented

You would have to send 0.0003 to your address in order to have 0.0001 left as a fee :)

The code is pretty much ignores fees. Even if the user provided it something, it can't really check, so mistakes can still happen. Since the library doesn't much network/API code, determining fee's would be out of scope.

I'm curious, where did you hear about this repo? I'd actually like more eyes on the rewrite if you're not too far into things: https://github.com/Bit-Wasp/bitcoin-php It's more correct, has more features and tests (and is actively being maintained)

cevin commented

@afk11

Aha~ I want make a online personal bitcoin wallet like blockchain.info, I found lots of repo and I can generate address and get the address private hex key , wif key. But could not make a transaction.

Look for a very long time, the final search createrawtransaction on Github, one by one find it. The last, I found this repo. :)

About this question, So in input I can do not set key value and only set target address amount+0.0001?

looks it's not ok. When send The last signed transaction hex id to bitcoin network I got an error report.
Transaction rejected by network (code -26). Reason: 66: insufficient priority

:( Do not want to use bitcoind.

cevin commented

@afk11

At https://github.com/Bit-Wasp/bitcoin-php , I not found how to set tx fees too. :( help

cevin commented

Oh, ~ ! I know! I am wrong!!! The last transaction id must be another address send to the current address and must be more than will send total amount !!

I try use the current address send to another address's transaction id, So It's wrong! - -##

Please write it on the repo. :)

add

The change address will receive all of received transaction id amount minus total send amount !

custom set transaction fees at here!

afk11 commented

You'll have to calculate the necessary fee first. It's a hard problem to work out what fee to use, most wallets use a static amount, but that doesn't work well when the blocks are full.

It also depends on the values of your inputs, which as you know the software ignores anyway. If you make a mistake, and use a software calculated fee that's wrong, the network will send the coins to the miners.

It's better off not having the feature, and leaving it in your hands!

$inputs = []; // your software will learn about these, paying your wallet

$inValue = '0';
foreach ($inputs as $in) {
  $inValue += $in['value'];
}

$fee = 0.0001; // YOU decide this. It depends on # inputs, # outputs, type of scriptPubKey.. 
$toSpend = $inValue - $fee;
$outputValue = '1.0000000';
$changeValue = $toSpend - $outputValue;

$sendTo = 'bitcoin address';
$changeAddress = 'change address';

$outputs = [  // (be nice, and randomize this array)
    $sendTo => $outputValue,
    $changeAddress => $changeValue
];

// Now make your transaction
cevin commented

@afk11 tks. But isn't a problem. :) very tks.

cevin commented

look here #101 (comment)

afk11 commented

Ok, great! I'll add it as an example. This library doesn't even know what 'change addresses' are ;)

cevin commented

Hope you will be keep update it.

another question, this library can to use for other coins? like dogecoin or litecoin.

afk11 commented

This library is too old, and won't be updated with new features.

I'd recommend you go with Bit-wasp/bitcoin-php. It supports other networks out of the box, whereas this particular library doesn't do it very well.

cevin commented

@afk11

bitcoin-php rely Bitcoind, not friendly. I hope that is generated directly rawtransaction direct broadcast like. like some enterprise have lots of bitcoind-servers to sync bitcoin datas and have a internal custom http interface for developer.

afk11 commented

It doesn't rely on bitcoind, or any API. It's role is a library, not something you can query for blockchain data. https://xkcd.com/927/

https://github.com/Bit-wasp/bitcoin-p2p-php lets you connect to the P2P network if you want to build something for broadcasting.

cevin commented

Okay, I'll to review it.

The key vout value of inputs is unspent transaction's vout value ? Or the value must be 0 in inputs.

Please can any body help me how i can use electrium usage in yii2 using this extention step by step.I am new in yii2.

afk11 commented

Please have a look at the examples and code - it's just a library so shouldn't matter what framework you use. All the same, this issue / repository isn't the place to ask about yii.

Thanks Thomas

On Tue, Mar 15, 2016 at 2:40 AM, Thomas Kerin notifications@github.com
wrote:

Please have a look at the examples and code - it's just a library so
shouldn't matter what framework you use. All the same, this issue /
repository isn't the place to ask about yii.


Reply to this email directly or view it on GitHub
#101 (comment)
.