비트코인 전도
파이썬) 전액 출금하지 않고 일부만 출금하는 방법
bitlog
2022. 12. 2. 18:42
전액 출금하지 않고 일부는 기존 주소로 남기겠다고 하실 경우에는,
아래와 같이 입력으로 사용했던 주소를 그대로 출력에 하나 추가해 주시면 됩니다!
from cryptos import *
c = Bitcoin()
from_address = 'address1'
inputs = c.unspent(from_address)
balance = sum([i['value'] for i in inputs])
fee = 1500
change = 20000 # 2만 사토시는 그대로 잔액으로 남기는 경우,
to = 'address2'
outs = [{'value': balance - fee - change, 'address': to}, {'value': change, 'address': from_address}]
tx = c.mktx(inputs, outs)
signed_tx = c.signall(tx, priv)
# send tx to bitcoin node
c.pushtx(signed_tx)
블로그내 관련 글
728x90
반응형