vbuterin / pybitcointools

SImple, common-sense Bitcoin-themed Python ECC library
1.28k stars 856 forks source link

how change_addr did not work for me ? #155

Open svsgoog opened 7 years ago

svsgoog commented 7 years ago

as you said, the fun mksend contains change_addr,

I see it passed as last-but-one arg to mksend, and then in the bottom: 509 if isum < osum+fee: 510 raise Exception("Not enough money") 511 elif isum > osum+fee+5430: 512 outputs2 += [{"address": change, "value": isum-osum-fee}]

in my case, I paid 1000 Satoshi having originally 500 000 Satoshi in my input addr, and this code somehow did not work for me, all the rest 499 000 Satoshi went for fee SILENTLY without any warning to me. I just used the example guide provided by you on the main page:

outs = [{'value': 90000, 'address': '16iw1MQ1sy1DtRPYw3ao1bCamoyBJtRB4t'}]

So how/where do I add my desired change_addr value ? How could I get shown (print) the fee amoung before I send transaction, so I can check what is really going to be sent ?

reiven commented 7 years ago

Hi @cledaso

At the end of the mksend function, you can see that a unsigned raw transaction is generated return mktx(ins, outputs2)

You can easily verify what are the inputs/outputs of the rawtransaction calling the deserialize function, which is also included in the transaction.py file and using that unsigned raw transaction as argument.

I personally recomend you use the testnet for your project devepment so you can't loose real money.

Regards

svsgoog commented 7 years ago

Thanks for you reply, it is partially useful though,

the remaining questions still are: -- So how/where do I add my desired change_addr value ? -- how do I use this pybitcointool with TESTnet ?

thanks for your future answer

svsgoog commented 7 years ago

-- So how/where do I add my desired change_addr value ? I mean I should use some other "outs" instead of that which you show in your example on main page:

outs = [{'value': 90000, 'address': '16iw1MQ1sy1DtRPYw3ao1bCamoyBJtRB4t'}]

svsgoog commented 7 years ago

is it the solution on network ? before using pybitcointool, I should call

set_network( "testnet" )

and then use all commands in the same way as for real net ?

reiven commented 7 years ago

@cledaso to add the _changeaddr to the mksend function, you should use:

mksend : (inputs, outputs, change_addr, fee)

Thats very similar to the way to use mktx function but adds an output to the desired address.

For using the testnet, you shoud:

The rest of the functions should work normally