使用命令 fundrawtransaction 设置changeAddress

fundrawtransaction "hexstring" ( options )

Add inputs to a transaction until it has enough in value to meet its out value.
This will not modify existing inputs, and will add at most one change output to the outputs.
No existing outputs will be modified unless "subtractFeeFromOutputs" is specified.
Note that inputs which were signed may need to be resigned after completion since in/outputs have been added.
The inputs added will not be signed, use signrawtransaction for that.
Note that all existing inputs must have their previous output transaction be in the wallet.
Note that all inputs selected must be of standard form and P2SH scripts must be
in the wallet using importaddress or addmultisigaddress (to calculate fees).
You can see whether this is the case by checking the "solvable" field in the listunspent output.
Only pay-to-pubkey, multisig, and P2SH versions thereof are currently supported for watch-only

Arguments:
1. "hexstring"           (string, required) The hex string of the raw transaction
2. options                 (object, optional)
   {
     "changeAddress"          (string, optional, default pool address) The bitcoin address to receive the change
     "changePosition"         (numeric, optional, default random) The index of the change output
     "includeWatching"        (boolean, optional, default false) Also select inputs which are watch only
     "lockUnspents"           (boolean, optional, default false) Lock selected unspent outputs
     "feeRate"                (numeric, optional, default not set: makes wallet determine the fee) Set a specific feerate (BTC per KB)
     "subtractFeeFromOutputs" (array, optional) A json array of integers.
                              The fee will be equally deducted from the amount of each specified output.
                              The outputs are specified by their zero-based index, before any change output is added.
                              Those recipients will receive less bitcoins than you enter in their corresponding amount field.
                              If no outputs are specified here, the sender pays the fee.
                                  [vout_index,...]
     "replaceable"            (boolean, optional) Marks this transaction as BIP125 replaceable.
                              Allows this transaction to be replaced by a transaction with higher fees
     "conf_target"            (numeric, optional) Confirmation target (in blocks)
     "estimate_mode"          (string, optional, default=UNSET) The fee estimate mode, must be one of:
         "UNSET"
         "ECONOMICAL"
         "CONSERVATIVE"
   }
                         for backward compatibility: passing in a true instead of an object will result in {"includeWatching":true}

Result:
{
  "hex":       "value", (string)  The resulting raw transaction (hex-encoded string)
  "fee":       n,         (numeric) Fee in BTC the resulting transaction pays
  "changepos": n          (numeric) The position of the added change output, or -1
}

Examples:

Create a transaction with no inputs
> bitcoin-cli createrawtransaction "[]" "{\"myaddress\":0.01}"

Add sufficient unsigned inputs to meet the output value
> bitcoin-cli fundrawtransaction "rawtransactionhex"

Sign the transaction
> bitcoin-cli signrawtransaction "fundedtransactionhex"

Send the transaction
> bitcoin-cli sendrawtransaction "signedtransactionhex"
 (code -1)

源码:

https://github.com/bitcoin/bitcoin/blob/d799efe21432ad55c41d5315f24c002bc8b3d119/src/wallet/rpcwallet.cpp

bitcoin rpc命令、源码剖析:

https://mistydew.github.io/blog/category.html#Blockchain-ref

用法示例:

先创建一笔没有输入的交易,
添加充足的未签名的输入用以满足输出金额,
签名交易,
发送交易。

$ bitcoin-cli createrawtransaction "[]" "{\"1Mcg7MDBD38sSScsX3USbsCnkcMbPnLyTV\":0.01}"
01000000000140420f00000000001976a914e221b8a504199bec7c5fe8081edd011c3653118288ac00000000
$ bitcoin-cli decoderawtransaction 01000000000140420f00000000001976a914e221b8a504199bec7c5fe8081edd011c3653118288ac00000000
{"txid": "b88e6b7777cbcca8f316fde34ab27917f62734c127a218887f032884751a7a94","size": 44,"version": 1,"locktime": 0,"vin": [],"vout": [{"value": 0.01000000,"n": 0,"scriptPubKey": {"asm": "OP_DUP OP_HASH160 e221b8a504199bec7c5fe8081edd011c36531182 OP_EQUALVERIFY OP_CHECKSIG","hex": "76a914e221b8a504199bec7c5fe8081edd011c3653118288ac","reqSigs": 1,"type": "pubkeyhash","addresses": ["1Mcg7MDBD38sSScsX3USbsCnkcMbPnLyTV"]}}]
}
$ bitcoin-cli fundrawtransaction 01000000000140420f00000000001976a914e221b8a504199bec7c5fe8081edd011c3653118288ac00000000
{"hex": "01000000014412ee17ce40921719443ac884702a5100db85a98fa0eea49fe185c36aab546e0100000000feffffff02188de605000000001976a91441068d02c7c981b7a7ac4f4c2f28b480a76a66c188ac40420f00000000001976a914e221b8a504199bec7c5fe8081edd011c3653118288ac00000000","changepos": 0,"fee": 0.00004520
}
$ bitcoin-cli decoderawtransaction 01000000014412ee17ce40921719443ac884702a5100db85a98fa0eea49fe185c36aab546e0100000000feffffff02188de605000000001976a91441068d02c7c981b7a7ac4f4c2f28b480a76a66c188ac40420f00000000001976a914e221b8a504199bec7c5fe8081edd011c3653118288ac00000000
{"txid": "17b65e7c94c81e71e03e763051c85e94dc74f44f385b61bb0c60391717ee5cdb","size": 119,"version": 1,"locktime": 0,"vin": [{"txid": "6e54ab6ac385e19fa4eea08fa985db00512a7084c83a4419179240ce17ee1244","vout": 1,"scriptSig": {"asm": "","hex": ""},"sequence": 4294967294}],"vout": [{"value": 0.98995480,"n": 0,"scriptPubKey": {"asm": "OP_DUP OP_HASH160 41068d02c7c981b7a7ac4f4c2f28b480a76a66c1 OP_EQUALVERIFY OP_CHECKSIG","hex": "76a91441068d02c7c981b7a7ac4f4c2f28b480a76a66c188ac","reqSigs": 1,"type": "pubkeyhash","addresses": ["16vpmdSDaX3Nv9UMuk2vSecMrdstjjSP4R"]}}, {"value": 0.01000000,"n": 1,"scriptPubKey": {"asm": "OP_DUP OP_HASH160 e221b8a504199bec7c5fe8081edd011c36531182 OP_EQUALVERIFY OP_CHECKSIG","hex": "76a914e221b8a504199bec7c5fe8081edd011c3653118288ac","reqSigs": 1,"type": "pubkeyhash","addresses": ["1Mcg7MDBD38sSScsX3USbsCnkcMbPnLyTV"]}}]
}
$ bitcoin-cli signrawtransaction 01000000014412ee17ce40921719443ac884702a5100db85a98fa0eea49fe185c36aab546e0100000000feffffff02188de605000000001976a91441068d02c7c981b7a7ac4f4c2f28b480a76a66c188ac40420f00000000001976a914e221b8a504199bec7c5fe8081edd011c3653118288ac00000000
{"hex": "01000000014412ee17ce40921719443ac884702a5100db85a98fa0eea49fe185c36aab546e010000006b483045022100c49f5b0ff43f2b35266c6944b042bbaef667c3504c556a915636930d857465e1022041421645d9fb25b154c5356508d08f69054a57cfd0f9f9a60975855de62167430121029add8d65b91a60990c1ca7e45d8239631511a217cd23521054727c63ff1ff7c0feffffff02188de605000000001976a91441068d02c7c981b7a7ac4f4c2f28b480a76a66c188ac40420f00000000001976a914e221b8a504199bec7c5fe8081edd011c3653118288ac00000000","complete": true
}
$ bitcoin-cli sendrawtransaction 01000000014412ee17ce40921719443ac884702a5100db85a98fa0eea49fe185c36aab546e010000006b483045022100c49f5b0ff43f2b35266c6944b042bbaef667c3504c556a915636930d857465e1022041421645d9fb25b154c5356508d08f69054a57cfd0f9f9a60975855de62167430121029add8d65b91a60990c1ca7e45d8239631511a217cd23521054727c63ff1ff7c0feffffff02188de605000000001976a91441068d02c7c981b7a7ac4f4c2f28b480a76a66c188ac40420f00000000001976a914e221b8a504199bec7c5fe8081edd011c3653118288ac00000000
cd92e2a951d5624355fff82288d28cd4d213a711f7ddb10fcdd22bc6fa16801f
$ bitcoin-cli getrawtransaction cd92e2a951d5624355fff82288d28cd4d213a711f7ddb10fcdd22bc6fa16801f 1
{"hex": "01000000014412ee17ce40921719443ac884702a5100db85a98fa0eea49fe185c36aab546e010000006b483045022100c49f5b0ff43f2b35266c6944b042bbaef667c3504c556a915636930d857465e1022041421645d9fb25b154c5356508d08f69054a57cfd0f9f9a60975855de62167430121029add8d65b91a60990c1ca7e45d8239631511a217cd23521054727c63ff1ff7c0feffffff02188de605000000001976a91441068d02c7c981b7a7ac4f4c2f28b480a76a66c188ac40420f00000000001976a914e221b8a504199bec7c5fe8081edd011c3653118288ac00000000","txid": "cd92e2a951d5624355fff82288d28cd4d213a711f7ddb10fcdd22bc6fa16801f","size": 226,"version": 1,"locktime": 0,"vin": [{"txid": "6e54ab6ac385e19fa4eea08fa985db00512a7084c83a4419179240ce17ee1244","vout": 1,"scriptSig": {"asm": "3045022100c49f5b0ff43f2b35266c6944b042bbaef667c3504c556a915636930d857465e1022041421645d9fb25b154c5356508d08f69054a57cfd0f9f9a60975855de6216743[ALL] 029add8d65b91a60990c1ca7e45d8239631511a217cd23521054727c63ff1ff7c0","hex": "483045022100c49f5b0ff43f2b35266c6944b042bbaef667c3504c556a915636930d857465e1022041421645d9fb25b154c5356508d08f69054a57cfd0f9f9a60975855de62167430121029add8d65b91a60990c1ca7e45d8239631511a217cd23521054727c63ff1ff7c0"},"sequence": 4294967294}],"vout": [{"value": 0.98995480,"n": 0,"scriptPubKey": {"asm": "OP_DUP OP_HASH160 41068d02c7c981b7a7ac4f4c2f28b480a76a66c1 OP_EQUALVERIFY OP_CHECKSIG","hex": "76a91441068d02c7c981b7a7ac4f4c2f28b480a76a66c188ac","reqSigs": 1,"type": "pubkeyhash","addresses": ["16vpmdSDaX3Nv9UMuk2vSecMrdstjjSP4R"]}}, {"value": 0.01000000,"n": 1,"scriptPubKey": {"asm": "OP_DUP OP_HASH160 e221b8a504199bec7c5fe8081edd011c36531182 OP_EQUALVERIFY OP_CHECKSIG","hex": "76a914e221b8a504199bec7c5fe8081edd011c3653118288ac","reqSigs": 1,"type": "pubkeyhash","addresses": ["1Mcg7MDBD38sSScsX3USbsCnkcMbPnLyTV"]}}]
}

自定义BTC找零地址相关推荐

  1. qt designer 自定义插件找不到指定的模块_SpringBoot之spring-boot-load模块

    一.前言 正常情况下classloader只能找到jar里面当前目录或者文件类里面的*.class文件.为了能够加载嵌套jar里面的资源之前都是把嵌套jar里面的class文件和应用的class文件打 ...

  2. qt designer 自定义插件找不到指定的模块_go与qt的新酒老瓶

    前言 只所以说是新酒老瓶而不是新瓶老酒是有用意的. 因为QT是器,老瓶,出来时配合着C++的.而如今go来势凶凶,自然英雄所见略同. 两大开源神器,跨平台开发,终将双剑合璧了,让你如虎添翼. 过程记录 ...

  3. MATLAB函数判断绝对素数,自定义函数,找出 以内所有素数(质数)并计算它们的和,matlab...

    C++,VC2008,问题是 编写一个函数,找出3~1000之内,所有的素数.求高手!我在线等 #include#includevoidf(){//筛法charprime[1001];memset(p ...

  4. 打包后自定义attr找不到_80后长沙文物修复师刘胄造“精绝古城”,修复实力连X光都找不到破绽...

    提到匠人,大家印象中都是满头白发的样子.然而在最新一期<巧手神探>中,却有一位80后巧手,如今才32岁.别看他年纪轻轻,却拥有十余年的文物修复经历,不仅恢复了上百件文物,多次参与国家级博物 ...

  5. 打包后自定义attr找不到_本硕985裸辞后找不到工作,该何去何从?

    向大家汇报下自己现在的情况.男生,出身于山东十八线小县城,父母在体制内,上世纪80年代的中专生,家庭年入20来万,家里算是中产.去年上海交大某传统工科学院硕士毕业,本科西安某985,去年四月硕士毕业后 ...

  6. python自定义函数找最大值_python – 查找用户定义函数的局部最大值和最小值

    我想要的是 我想找到一个静止点列表,它们的值和位置,以及它们是最小值还是最大值. 我的功能如下: import numpy as np def func(x,y): return (np.cos(x* ...

  7. mysql 自定义函数 找不到表_mysql 自定义函数

    新建: Create function function_name(参数列表)returns返回值类型 函数体 函数名,应该合法的标识符,并且不应该与已有的关键字冲突. 一个函数应该属于某个数据库,可 ...

  8. 名派照明连接天猫精灵_统一的动态精灵照明

    名派照明连接天猫精灵 Sprites in Daedalus make use of Unity's lighting system to appear with 3D-like properties ...

  9. USDT离线签名交易

    本文作者:陈进坚 个人博客:https://jian1098.github.io CSDN博客:https://blog.csdn.net/c_jian 简书:https://www.jianshu. ...

最新文章

  1. Peter Cnudde谈雅虎如何使用Hadoop、深度学习和大数据平台
  2. 在线白板,基于socket.io的多人在线协作工具
  3. 【转载】2009年.NET技术大会讲义(上)——PDF分享
  4. RTEMS实时操作系统精要(1)-简介
  5. 【java】项目环境配置
  6. VHDL基础 学习笔记
  7. 我的新书终于写完了。
  8. sql azure 语法_Azure Kubernetes服务(AKS)–管理SQL Server数据库文件
  9. python字符串函数split_Python常见字符串操作函数小结【split()、join()、strip()】
  10. 一张图看Docker
  11. 用QBE语言实现关系代数
  12. Interpreting Attributions and Interactions of Adversarial Attacks论文解读
  13. 掌上百度2011java_掌上百度2011通用版 掌上百度 Java空间版
  14. 原子结构示意图全部_所有原子结构示意图 (1)
  15. python接口测试第二期_上海悠悠python接口自动化测试第二期视频教程价值1600
  16. html表格中的字体上下居中 css,css 文字垂直居中实现方法总结
  17. 怎么杀php源文件的木马,PHP一句话木马及查杀
  18. 【华为OD机试真题 JAVA】叠积木
  19. 最细致全面架设单机传奇教程
  20. python习题_Python练习题-for循环练习

热门文章

  1. 深度学习 Day 3——解决深度学习环境配置问题
  2. 媒体处理软件:MKVToolnix-MKV编辑合成软件
  3. APP的缓存文件放在哪里?
  4. win2003配置java_WinPE 下安装 Windows Server 2003 服务器
  5. 传说中的防骑969宏
  6. 关于计算机的名人名言英语,立春了 名人名言英语描写春天的句子
  7. 京东支付,支付宝网页支付,财付通支付
  8. win7运行java配色方案_技术编辑帮您win7系统运行游戏时提示配色方案已更改为Windows 7 Basic的恢复教程...
  9. tencent实习----阶段总结报告
  10. C# RichTextBox 自动滚动到末尾