Lettering on bitcoin blockchain

Posted by BrianM on Fri, 07 Jan 2022 16:12:39 +0100

This task can be verified on BTC Testnet. When we really need something memorable and want to record it on the main network, we can operate in the same way. However, it is necessary to purchase cash withdrawal from the exchange. The process should be more complex, and there are also cash withdrawal handling fees in the middle.

First, we get the token of the test network from the water pipe of the test network.

Download Bitcoin Core, add the parameter - testnet in the startup shortcut, and then the startup icon will turn green.

After the block synchronization is completed, create a wallet, then click "receive" and "create a new collection address". In this way, we get the address of a test network.

(the above figure is only an example. In the following example, the test token received is in tb1qsjdrhtd9jyaz882n2kkdfwf24ekxnxh3ehtq32, and then I created the change address tb1qgavaaw2qtsxvh3lh77glnj0cm63t2rkvgycuvn)

After that, we can fill in this address on the website of the test network water pipe, and we can get the token of the test network.

After the test token arrives, we open the Bitcoin Core console. Specific location: window console.

Let's first look at the UTXO that can be used.

listunspent

We can see that we now have a 22.70916208BTC UTXO, which is created by the 0th output created by the transaction f8f732ee2872ef22a277e7c4a773cd59febd58e5714a6278553ea4cd8adaac35.

We think about what we want to create. What I want to engrave here is:

This is a test by KK in BJ,CHN

Convert it to hex format:

5468697320697320612074657374206279204b4b20696e20424a2c43484e

After that, we will spend the UTXO and create two outputs. One output contains the content we want to engrave, which does not contain the actual bitcoin, and the other is a conventional address transfer output. The address for receiving change is tb1qgavaaw2qtsxvh3lh77glnj0cm63t2rkvgycuvn. The value of change is the denomination of the original UTXO - miner's fee (according to the network situation at the time of transaction, there will be a suggested handling fee, which is calculated according to? Sat/kB.)

The following command resolves:

The content after txid is txid of UTXO, and vout is the same.

The content after data is the hex to be engraved

The back tb1qgavaaw2qtsxvh3lh77glnj0cm63t2rkvgycuvn is the address where I receive change. In practice, replace it with your own change address.

The miner fee I pay here is 0.00055500BTC. So we filled in the change amount as 22.70916208-0.000555000 = 22.70860708

createrawtransaction '[{"txid":"f8f732ee2872ef22a277e7c4a773cd59febd58e5714a6278553ea4cd8adaac35","vout":0}]' '{"data":"5468697320697320612074657374206279204b4b20696e20424a2c43484e","tb1qgavaaw2qtsxvh3lh77glnj0cm63t2rkvgycuvn":22.70860708}'

Here is a very important point. The basic feature of UTXO is indivisibility. To spend this UTXO, you must spend all his money as transaction input. If we do not set change reception, all bitcoins contained in UTXO will be used as miners' fees, which is a very dangerous thing. So be sure to create two transaction outputs for change. The calculation method of handling fee itself is the sum of transaction input - the sum of transaction output.

 

Then we sign the raw transaction and assemble it. The parameter content here is the output of the previous step

signrawtransactionwithwallet 020000000135acda8acda43e5578624a71e558bdfe59cd73a7c4e777a222ef7228ee32f7f80000000000ffffffff020000000000000000206a1e5468697320697320612074657374206279204b4b20696e20424a2c43484ea4955a87000000001600144759deb9405c0ccbc7f7f791f9c9f8dea2b50ecc00000000

Before the final broadcast transaction, for the sake of insurance, we can use decoderwtransaction to finally verify the transaction to be broadcast.

21:54:29

decoderawtransaction 0200000000010135acda8acda43e5578624a71e558bdfe59cd73a7c4e777a222ef7228ee32f7f80000000000ffffffff020000000000000000206a1e5468697320697320612074657374206279204b4b20696e20424a2c43484ea4955a87000000001600144759deb9405c0ccbc7f7f791f9c9f8dea2b50ecc0247304402206f472a8e5970c6da36279ddc58e19fc69d42055b8694ee08334a59eccc35d6c00220627e3a0cef0bf6e4a5eaf6ca83fb8c5c554ebb2530a31deaf7ec8c3a0c56138f012103cb4b882dabc46ec69b07da7b14a5dd46bb5c60454dd9caea37691fb2887fb1e900000000


21:54:29

{
  "txid": "fa342494192d3130a782158935cf287913c38c577bbc077ffa62b3dca5a35e42",
  "hash": "e14594587963f3eb6261b78f872ca207768947ec4c569ed11501f34f0f3d7b1b",
  "version": 2,
  "size": 232,
  "vsize": 151,
  "weight": 601,
  "locktime": 0,
  "vin": [
    {
      "txid": "f8f732ee2872ef22a277e7c4a773cd59febd58e5714a6278553ea4cd8adaac35",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "304402206f472a8e5970c6da36279ddc58e19fc69d42055b8694ee08334a59eccc35d6c00220627e3a0cef0bf6e4a5eaf6ca83fb8c5c554ebb2530a31deaf7ec8c3a0c56138f01",
        "03cb4b882dabc46ec69b07da7b14a5dd46bb5c60454dd9caea37691fb2887fb1e9"
      ],
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.00000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_RETURN 5468697320697320612074657374206279204b4b20696e20424a2c43484e",
        "hex": "6a1e5468697320697320612074657374206279204b4b20696e20424a2c43484e",
        "type": "nulldata"
      }
    },
    {
      "value": 22.70860708,
      "n": 1,
      "scriptPubKey": {
        "asm": "0 4759deb9405c0ccbc7f7f791f9c9f8dea2b50ecc",
        "hex": "00144759deb9405c0ccbc7f7f791f9c9f8dea2b50ecc",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "tb1qgavaaw2qtsxvh3lh77glnj0cm63t2rkvgycuvn"
        ]
      }
    }
  ]
}

After confirmation, we will send this transaction.

21:58:04

sendrawtransaction 0200000000010135acda8acda43e5578624a71e558bdfe59cd73a7c4e777a222ef7228ee32f7f80000000000ffffffff020000000000000000206a1e5468697320697320612074657374206279204b4b20696e20424a2c43484ea4955a87000000001600144759deb9405c0ccbc7f7f791f9c9f8dea2b50ecc0247304402206f472a8e5970c6da36279ddc58e19fc69d42055b8694ee08334a59eccc35d6c00220627e3a0cef0bf6e4a5eaf6ca83fb8c5c554ebb2530a31deaf7ec8c3a0c56138f012103cb4b882dabc46ec69b07da7b14a5dd46bb5c60454dd9caea37691fb2887fb1e900000000


21:58:04

fa342494192d3130a782158935cf287913c38c577bbc077ffa62b3dca5a35e42

https://blockstream.info/testnet/tx/fa342494192d3130a782158935cf287913c38c577bbc077ffa62b3dca5a35e42?expand

Click the + sign of DETAILS, we can see that we have successfully engraved

Soon, our transaction will be packaged and linked. After a period of transaction confirmation, the lettering was successful.

Topics: Blockchain network Bitcoin Digital Currency