티스토리 뷰

비트코인 공부

`NULL DATA` script

bitlog 2022. 10. 31. 09:41

Background

비트코인 표준 스크립트 종류

 

 

null-data 스크립트란

비트코인 장부에 특정 데이터를 저장하기 위한 목적으로 사용

 

OP_RETURN 의 op_code 는 `0x6a`

 

`NULL DATA` 의 scriptPubKey 의 구조

{OP_RETURN} + {문자열길이} + {임의문자열}

 

예시)

OP_RETURN + 11 + hello world
=>
6a
0b
68656c6c6f20776f726c64

 

 

null-data 트랜잭션 만들기

from cryptos import *

c = Bitcoin()
addr = 'address'
inputs = c.unspent(addr)
balance = inputs[0].get('value')
fee = 500

message = b'Jesus is the Christ, the Son of the living God.'
bin = binascii.hexlify(message)
bin_message = str(bin, 'ascii')

length = hex(len(message))[2:]
op_return = '6a'


outs = [{'value': balance - fee, 'address': addr}, {'value':0, 'script': op_return + length + bin_message}]
tx = c.mktx(inputs[0:1], outs)

# sign tx
signed_tx = c.signall(tx, priv)

# send tx to bitcoin node
c.pushtx(signed_tx)

 

 

signed_tx

0100000001b75d944e1cbd096ab3f0b10f928af2ade2826912709d62321e3e4e74dd175352000000008b4830450221008491c8038d015a339d0d1f4341fc12f726b9cfdc54c98832a1d8789eabb725da02202c89805087e6676fce7a125962a2a9833f3f055bb257dffbae2220710e261ccd0141042a66c68052932e64cafc796a19debca1e8c7572178d2a44546496955fa150818e7a3826c230484e627f6cc7d7400d68820678f78f3ceaa32c3695016a7e3e537ffffffff0212290100000000001976a914e4d6e6c5e7b462ef86d1e2776ba0a316988e681688ac0000000000000000316a2f4a6573757320697320746865204368726973742c2074686520536f6e206f6620746865206c6976696e6720476f642e00000000

 

 

Decoded transaction

https://live.blockcypher.com/btc/decodetx/

{
    "addresses": [
        "1MrzWMSL738SZ7w5fKrssejWjWhGtDxTjH"
    ],
    "block_height": -1,
    "block_index": -1,
    "confirmations": 0,
    "data_protocol": "unknown",
    "double_spend": false,
    "fees": 500,
    "hash": "862ad0316f9cb974f285db9403384a3cc64f3e1f01dd8e5f945b578548a8b59d",
    "inputs": [
        {
            "addresses": [
                "1MrzWMSL738SZ7w5fKrssejWjWhGtDxTjH"
            ],
            "age": 760708,
            "output_index": 0,
            "output_value": 76550,
            "prev_hash": "525317dd744e3e1e32629d70126982e2adf28a920fb1f0b36a09bd1c4e945db7",
            "script": "4830450221008491c8038d015a339d0d1f4341fc12f726b9cfdc54c98832a1d8789eabb725da02202c89805087e6676fce7a125962a2a9833f3f055bb257dffbae2220710e261ccd0141042a66c68052932e64cafc796a19debca1e8c7572178d2a44546496955fa150818e7a3826c230484e627f6cc7d7400d68820678f78f3ceaa32c3695016a7e3e537",
            "script_type": "pay-to-pubkey-hash",
            "sequence": 4294967295
        }
    ],
    "outputs": [
        {
            "addresses": [
                "1MrzWMSL738SZ7w5fKrssejWjWhGtDxTjH"
            ],
            "script": "76a914e4d6e6c5e7b462ef86d1e2776ba0a316988e681688ac",
            "script_type": "pay-to-pubkey-hash",
            "value": 76050
        },
        {
            "addresses": null,
            "data_hex": "4a6573757320697320746865204368726973742c2074686520536f6e206f6620746865206c6976696e6720476f642e",
            "data_string": "Jesus is the Christ, the Son of the living God.",
            "script": "6a2f4a6573757320697320746865204368726973742c2074686520536f6e206f6620746865206c6976696e6720476f642e",
            "script_type": "null-data",
            "value": 0
        }
    ],
    "preference": "low",
    "received": "2022-10-31T09:15:37.978744559Z",
    "relayed_by": "3.228.7.237",
    "size": 282,
    "total": 76050,
    "ver": 1,
    "vin_sz": 1,
    "vout_sz": 2,
    "vsize": 282
}

 

 

결과물

https://www.blockchain.com/btc/tx/862ad0316f9cb974f285db9403384a3cc64f3e1f01dd8e5f945b578548a8b59d

 

 

 

검증

OP_RETURN 아래  hex 코드를 ascii 로 변환합니다.

https://www.binaryhexconverter.com/hex-to-ascii-text-converter

 

 

 

Ref

 


https://youtu.be/TgOt48s0JTA

 

728x90
반응형
댓글
250x250
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함