Bitcoin Gold Raw Transaction Generation

My Bitcoin Gold is currently stored in a CoinBase MultiSig Vault.

I have all the passwords for the vault as well as the redeem script and two private keys for the address where my BTG (Bitcoin Gold) is currently stored.

I have previously used this information and a fork of https://coinb.in/ to create a transaction to send my Bitcoin Cash from my vault to an external wallet address.

I followed these instructions and it worked perfectly:

Is there a way to do something similar for Bitcoin Gold? I would like a tool to build a transaction similar to https://coinb.in/ but for Bitcoin Gold. I can’t seem to find anything anywhere online.

Thanks.

1 Like

Is there a specific time line you have in mind, or any urgency behind this?

My understanding is that this can be done with the Bitcoin Gold Wallet, but that would require syncing up the blockchain (which can take a good bit of time even if you download the bootstrap), and then doing some non-trivial things.

1 Like

Sorry. It looks like not an easy task so far. We have a paper wallet tool, btgwallet.online, but it is missing the ability to sign a transaction. The core wallet can do it but you need to download the full blockchain and it’s still not trivial to do the remeaning steps (long command lines).

But don’t worry. I will try to find out a better way. Will get back when I get some findings. BTW, we are working on Electrum fork for BTG. Hope this kind of issue will not be a problem in future.

1 Like

It is fairly urgent.

It looks as if your tool allows you to sign the transactions.

However, it does not have the ability to create the initial raw transactions similar to:

https://coinb.in/#newTransaction

I also do not see the ability to broadcast to the blockchain.

1 Like

Tools

  1. A browser
  2. Bitcoin Gold core client
  3. (optional) An offline computer

Overall steps

  1. Get the transaction details (tx inputs) from a blockchain explorer
  2. Build a transaction to unlock your coins using the Bitcoin Gold core client
  3. Broadcast your transaction to the network

Basic knowledge

Bitcoin Gold transaction is made up of two parts: inputs and outputs. An input defines which wallet to consume and an output defines where to send the coin. A transaction can have multiple inputs and outputs.

Let"s see an example:

// inputs
[
  {
    "txid": "eca4b25e99484aa6907ab0e12486d4784c620730751587065beeb6a1d195114f",
    "vout": 0,
    "scriptPubKey": "a914daebff513795e6e8bb8c27d540afa5cee93c16d287",
    "redeemScript": "5221032aa3765290ceb951c492fb37cc35dc7bf288faa63185b4fa96a4e8399342f2242103711df91db362c61536aaf8486548ff1686c6793bc6049afab79faed19b1a804052ae",
    "amount": 0.21
  },
  {
    "txid": "f22d9d88a414ee5ac2be4d5c58dbbf2d685bd739ec172db348bd4526a6a307eb",
    "vout": 2,
    "scriptPubKey": "a914225b3a7de5a8693c75e06cc81953741863c142d087",
    "redeemScript": "522103711df91db362c61536aaf8486548ff1686c6793bc6049afab79faed19b1a804021032aa3765290ceb951c492fb37cc35dc7bf288faa63185b4fa96a4e8399342f22452ae",
    "amount": 0.33
  }
]

// outputs
{
  "GWcPKN52GdMAd6rT5tAh5eEz8ZkfWKTTZB": 0.5,
  "GL3GUp22D9QVscgpm24NYPUAEcGwVKKkBq": 0.039
}

This tx sends 0.54 BTG from two inputs to two addresses. The sum of the inputs is equal to the sum of the outputs, plus the miner fee:

0.21 + 0.33 (inputs) = 0.5 + 0.039 (outputs) + 0.001 (miner fee)

Transactions are chained by inputs and outputs. Each input consumes an output from a previous tx. So all you need to build a transaction is to find out the inputs that you want to spend from the blockchain, and write down your destination.

After you have created a correct tx, you can sign the tx by your private keys. Then the tx will be extended to include your signatures. And when all the signatures are attached, you are ready to send out the tx.

Walkthrough

Step 1: Get transaction details (inputs)

1.1: Get the your multis-sig address in BTG format

  1. Open https://btgwallet.online/#verify
  2. In “Verify” page, enter your redeem script and click “Submit”
  3. You will get the multi-sig address in BTG format (starts with “A”). Please save it somewhere for later use.

1.2: Get ScriptPubkey for your address

  1. Open https://chainquery.com/bitcoin-api/validateaddress
  2. Enter your multi-sig address in “Bitcoin Address” in Bitcoin format (starts with “3”) and click “Execute Command”
  3. You will find the “scriptPubKey” in the “Command Result”. Please save it for later use.

1.3: Get the inputs from Trezor’s Insight explorer

  1. Open https://btg-bitcore2.trezor.io/api/addr/<YOUR ADDRESS>/utxo in your browser. <YOUR ADDRESS> is the address you got from last step.
    (e.g. https://btg-bitcore2.trezor.io/api/addr/AbjRfhXSz1ywEK5iNj8cACuwZCU9dXCLei/utxo)
  2. You will see a list of inputs. The sum of “amount” should be your balance in this address. Please confirm it’s correct.
  3. Save all the inputs for later use.

Step 2: Build the raw transaction

2.1: Compose the input configuration

The inputs should be in the format shown below. Each input is surrounded by braces and separated by commas. Please duplicate if you have more than two inputs.

[
  {
    "txid": "<txid>",
    "vout": "<vout>",
    "scriptPubKey": "<script pubkey>",
    "redeemScript": "<redeem script>",
    "amount": <amount>
  },
  {
    "txid": "<txid>",
    "vout": "<vout>",
    "scriptPubKey": "<script pubkey>",
    "redeemScript": "<redeem script>",
    "amount": <amount>
  }
]

You can find <txid>, <vout>, and <amount> from the inputs you got from Step 1.3 and <script pubkey> from Step 1.1. <redeem script> can be gotten from Coinbase. Note that <amount> is measured in BTG (BTC) instead of satoshi.

Don’t forget to validate the format of the inputs. You can copy the final input info to https://jsonlint.com and click “Validate JSON”. Be aware of the comma and quotes. If everything is good, it will show a green “Valid JSON” message.

2.2 Compose the output configuration

Write down the output in the format shown below. The sum of the output amounts should be equal to the sum of the input amounts minus the miner fee.

{
  "<address 1>": <amount 1>,
  "<address 2>": <amount 2>,
  "<address 3>": <amount 3>
}

Don’t forget to validate the JSON configuration. Now you should have the input and output configurations. The example in “Basic Knowledge” section can be a sample to compare.

2.2 Build a raw transaction

  1. Install Bitcoin Gold core node. You don’t need to wait for the full blockchain. There’s no problem to run it offline.
  2. If you run the GUI client, open the console. Otherwise you should use bgold-cli command line utility.

For GUI: Run this command with your own input and output configuirations:

createrawtransaction '<input configuration>' '<output configuiration>'

For command line: Run this command with your own input and output configuirations. Be aware of the escape:

bgold-cli createrawtransaction '''
<input configuration>
''' '''
<output configuration>
'''

Example:

bgold-cli createrawtransaction '''
[
  {
    "txid": "eca4b25e99484aa6907ab0e12486d4784c620730751587065beeb6a1d195114f",
    "vout": 0,
    "scriptPubKey": "a914daebff513795e6e8bb8c27d540afa5cee93c16d287",
    "redeemScript": "5221032aa3765290ceb951c492fb37cc35dc7bf288faa63185b4fa96a4e8399342f2242103711df91db362c61536aaf8486548ff1686c6793bc6049afab79faed19b1a804052ae",
    "amount": 0.21
  },
  {
    "txid": "f22d9d88a414ee5ac2be4d5c58dbbf2d685bd739ec172db348bd4526a6a307eb",
    "vout": 2,
    "scriptPubKey": "a914225b3a7de5a8693c75e06cc81953741863c142d087",
    "redeemScript": "522103711df91db362c61536aaf8486548ff1686c6793bc6049afab79faed19b1a804021032aa3765290ceb951c492fb37cc35dc7bf288faa63185b4fa96a4e8399342f22452ae",
    "amount": 0.33
  }
]''' '''{
  "GWcPKN52GdMAd6rT5tAh5eEz8ZkfWKTTZB": 0.5,
  "GL3GUp22D9QVscgpm24NYPUAEcGwVKKkBq": 0.039
}'''

Result:

02000000024f1195d1a1b6ee5b068715753007624c78d48624e1b07a90a64a48995eb2a4ec0000000000ffffffffeb07a3a62645bd48b32d17ec39d75b682dbfdb585c4dbec25aee14a4889d2df20200000000ffffffff0280f0fa02000000001976a9148c0a446a29c6f57df14fbb880bc90c3969ddae4688ac60823b00000000001976a9141815934900d3709ba7253e45bb7907205d75343788ac00000000

Then you will get a long hex string like the above one. It’s your raw transaction data. Please save it for later use.

2.3 Sign the transaction

[Warning] This is the only step that you need to use your private key. Please do it with great caution. It’s advisable to run it on an offline computer and destroy the key after this step.

For GUI: Run this command with the hex string you got from 2.2 and the input configuration:

signrawtransaction '<hex you got from 2.2>' '<input configuration>' '["<private key 1>", "<private key 2>"]'

For command line: Run this command with the hex string you got from 2.2 and the input configuration:

bgold-cli signrawtransaction '<hex you got from 2.2>' '''
<input configuration>''' '''
["<private key 1>", "<private key 2>"]
'''

Example:

bgold-cli signrawtransaction '02000000024f1195d1a1b6ee5b068715753007624c78d48624e1b07a90a64a48995eb2a4ec0000000000ffffffffeb07a3a62645bd48b32d17ec39d75b682dbfdb585c4dbec25aee14a4889d2df20200000000ffffffff0280f0fa02000000001976a9148c0a446a29c6f57df14fbb880bc90c3969ddae4688ac60823b00000000001976a9141815934900d3709ba7253e45bb7907205d75343788ac00000000' '''
[
  {
    "txid": "eca4b25e99484aa6907ab0e12486d4784c620730751587065beeb6a1d195114f",
    "vout": 0,
    "scriptPubKey": "a914daebff513795e6e8bb8c27d540afa5cee93c16d287",
    "redeemScript": "5221032aa3765290ceb951c492fb37cc35dc7bf288faa63185b4fa96a4e8399342f2242103711df91db362c61536aaf8486548ff1686c6793bc6049afab79faed19b1a804052ae",
    "amount": 0.21
  },
  {
    "txid": "f22d9d88a414ee5ac2be4d5c58dbbf2d685bd739ec172db348bd4526a6a307eb",
    "vout": 2,
    "scriptPubKey": "a914225b3a7de5a8693c75e06cc81953741863c142d087",
    "redeemScript": "522103711df91db362c61536aaf8486548ff1686c6793bc6049afab79faed19b1a804021032aa3765290ceb951c492fb37cc35dc7bf288faa63185b4fa96a4e8399342f22452ae",
    "amount": 0.33
  }
]''' '''
["L37v8XbTUgguPcz3C5TmWzMQvW4mcPkY4CMcQQCGCszneM4vsttK", "L3wCBNPCvR2s9DpovpXdcixZzFhu29BCESoE5BQNvj3t1PCQ4oL3"]
'''

Result:

{
  "hex": "02000000024f1195d1a1b6ee5b068715753007624c78d48624e1b07a90a64a48995eb2a4ec00000000da00483045022100daa75f382405a14c29c35dc7be8ffaf9840fa91a2ae1a6766c9585d8d83a18420220032ae93e7aab45d36ffd360e17934b0ece7cf1daebb737900d9bfdb204cd947e4147304402206f4804ca7b39e75381318bcdb307e6bf308c4ef77d11deb4f19f6f29a8f326ac022040351d94f386520800388a1aab50ae051714585ca9e7ca91a58afdce461bdf7f41475221032aa3765290ceb951c492fb37cc35dc7bf288faa63185b4fa96a4e8399342f2242103711df91db362c61536aaf8486548ff1686c6793bc6049afab79faed19b1a804052aeffffffffeb07a3a62645bd48b32d17ec39d75b682dbfdb585c4dbec25aee14a4889d2df202000000da00473044022048ea6824940a7d9847e7613a81effead7ec03a065d1f9f44b43753c0bfeff92702205381a1fbe25e5c154250fceca28baf570f14615e4ce74cd29f3d6517deafbce4414830450221008d8b5b00e365a8f65e76d0b20e1fadee626de91729fc3d9f0e3b935e74bae6ec02202bdd7f098db7e4d241bb56f7eadfa2f714b4502afd08386eee4ee356154cb41d4147522103711df91db362c61536aaf8486548ff1686c6793bc6049afab79faed19b1a804021032aa3765290ceb951c492fb37cc35dc7bf288faa63185b4fa96a4e8399342f22452aeffffffff0280f0fa02000000001976a9148c0a446a29c6f57df14fbb880bc90c3969ddae4688ac60823b00000000001976a9141815934900d3709ba7253e45bb7907205d75343788ac00000000",
  "complete": true
}

If everything is good, you should see the result. It should have "complete": true. Otherwise the signing is failed. You should be able to find another very long hex string in the output as well. Please save it for broadcasting.

{
  "hex" : "<final tx string>",
  "complete" : true
}

Setp 3: Broadcast the transaction

Before doing anything, please check the input and output configuration (amount, target addresses, etc). Then check if the final transaction hex string is correct (it should only contain digital and a-z characters).

When everything is fine, you can open https://btg-bitcore2.trezor.io/tx/send, paste your raw transaction data there and press “Send transaction”.

1 Like

Thank you. I will have a lot of questions I am sure.

  1. Where do I get the txid and vout inputs?

I do not see this on the trezor site as per the instructions in 1.3.

  1. For step 3. It looks as if that Broadcast window is for Bitcoin. Will it work for Bitcoin Gold as well?
1 Like

When I do step 1.3 on the trezor site I receive these inputs:

{“addrStr”:"",“balance”:,“balanceSat”:,“totalReceived”:,“totalReceivedSat”:,“totalSent”:,“totalSentSat”:,“unconfirmedBalance”:,“unconfirmedBalanceSat”:,“unconfirmedTxApperances”:,“txApperances”:,“transactions”:[""]}

Which is vout and txid?

Txid looks like a transactionid of something already used so I am not sure if it needs to be a new id.

Also, please let me know For step 3. It looks as if that Broadcast window is for Bitcoin. Will it work for Bitcoin Gold as well?

1 Like

I’ll leave it to @h4x3rotab to answer your other questions, but I’ll take a crack at this one:

I believe that’s simply because Trezor forked their btc explorer/broadcast site to create a btg explorer/broadcast site, but they have not modified all the text on the btg version to say “Bitcoin Gold” instead of Bitcoin.

Until they do that, you can still tell which blockchain you’re working with using the URL and the Height:

And although the Replay Protection was implemented to prevent malicious broadcasting of a transaction to a different chain, it also protects you against accidentally pushing the transaction onto the wrong chain when manually creating a transaction like this.

Thanks.

Still need help with inputs 1.3 vout and txid.

Where do I input the miner fee? Is it simply that the output quantity should be less than the input quantity (like in your example (0.21 + 0.33) > (0.5 + 0.39). What is a large enough miner fee to ensure I am on the next block?

When I do step 1.3 on the trezor site I receive these inputs:

{“addrStr”:“”,“balance”:,“balanceSat”:,“totalReceived”:,“totalReceivedSat”:,“totalSent”:,“totalSentSat”:,“unconfirmedBalance”:,“unconfirmedBalanceSat”:,“unconfirmedTxApperances”:,“txApperances”:,“transactions”:[“”]}

Looks like you forgot the the /utxo after your address. Please make sure you have entered the correct url. Here is an example, you can just replace the address by yours:

https://btg-bitcore2.trezor.io/api/addr/AJ7nbgZAyatuxa6NaYeotsQiuB25TQ3SpR/utxo

Where do I input the miner fee?

When you write the output, just ensure the sum of the output amounts is a bit less than the sum of the inputs. The delta is the miner fee.

What is a large enough miner fee to ensure I am on the next block?

I think 0.001 is more than enough because Bitcoin Gold doesn’t suffer full block problem.

1 Like

A Bitcoin raw transaction is a chunk of bytes that contains the information about a Bitcoin transaction. That raw transaction will become part of the blockchain when a miner adds it to a block.