{"id":15288293,"url":"https://github.com/vivelev/btcd","last_synced_at":"2026-04-27T12:31:06.540Z","repository":{"id":61628754,"uuid":"381375951","full_name":"VIVelev/btcd","owner":"VIVelev","description":"Pure Go from-scratch zero-dependecy implementation of Bitcoin","archived":false,"fork":false,"pushed_at":"2021-07-30T14:45:45.000Z","size":137,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T23:43:48.796Z","etag":null,"topics":["bitcoin","crypto","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VIVelev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-29T13:32:34.000Z","updated_at":"2021-07-30T14:45:48.000Z","dependencies_parsed_at":"2022-10-18T17:45:19.203Z","dependency_job_id":null,"html_url":"https://github.com/VIVelev/btcd","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VIVelev%2Fbtcd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VIVelev%2Fbtcd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VIVelev%2Fbtcd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VIVelev%2Fbtcd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VIVelev","download_url":"https://codeload.github.com/VIVelev/btcd/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245212304,"owners_count":20578443,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitcoin","crypto","golang"],"created_at":"2024-09-30T15:46:37.483Z","updated_at":"2026-04-27T12:31:06.507Z","avatar_url":"https://github.com/VIVelev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# btcd\n\nA pure Go from-scratch zero-dependecy implementation of Bitcoin for educational purposes.\nIt also includes all of the under the hood crypto primitives such as SHA-256, elliptic curves\nover finite prime fields math, ECDSA and other.\n\n## What can it do?\n\nRight now it can create and validate transactions such as Pay-to-PubKey-Hash and\nall the operations related to it.\n\n## Now you may be asking how can I use `btcd` to create transactions. Well...\n\n### 1) You will need to create your own Bitcoin private key, public key and address.\n```golang\n// Generate your own private key, public key, and address.\npriv := ecdsa.GenerateKey(elliptic.Secp256k1, \"vivelev@icloud.comiamfrombetelgeuse\")\n// Use some secret of yours for the passphrase above.\npub := priv.PublicKey\naddress := encoding.Address(\u0026pub, true, true)\n// the last two boolean arguments are:\n//     1) Should I use compressed format for the address? - YES! Space is valuable!\n//     2) Is this address for the testnet or mainnet? - Well, I will use the testnet,\n// because I don't have any spare coins. :)\n\nfmt.Printf(\"My Bitcoin address is: %s. Send me some coins!\\n\", address)\n```\n\n### 2) Now go get some testnet coins! Sadly, they aren't worth a dime. :(\nI personally use the following faucet: https://coinfaucet.eu/en/btc-testnet/\n\n### 3) Lets construct the input of our transaction.\n#### 3.1) You need to get the ID of the transaction that gave you the coins above.\nNavigate to https://mempool.space/testnet and search your address using the search bar.\nMine txId was: `68389d05ce8c54041dafcf12820d4246f5ca5128b2d414b5317af58a5274d09e`.\n\n#### 3.2) Also, the index of your output (the one with your address).\nSince my address showed up second in the column on the right (the outputs), my index is: `1`.\n\n#### 3.3) Combining it all: Lets build the transaction input!\n```golang\n// Get the id:\nprevTxId := \"68389d05ce8c54041dafcf12820d4246f5ca5128b2d414b5317af58a5274d09e\"\n// Get the index:\nprevIndex := 1\n\n// Now construct the input\ntxIn := tx.TxIn{}\nbytes, _ := hex.DecodeString(prevTxId)\ncopy(txIn.PrevTxId[:], bytes)\ntxIn.PrevIndex = uint32(prevIndex)\ntxIn.Testnet = true\n```\n\n### 4) Decide how much coins you want to send me. ;)\nYou decide how much. Also, don't forget the fee!!! Here is what I did:\n```golang\nmyTotalCoinsInSatoshi, _ := txIn.Value() // 1 satoshi = 1e-8 bitcoin\nfmt.Printf(\"I have %d satoshi.\", myTotalCoinsInSatoshi)\n// I will send 60% of my satoshi to myself. :)\ntargetAmount := uint64(0.6 * float64(myTotalCoinsInSatoshi))\n// Lets pay the miners!\nfee := uint64(1500)\n// Calculate the change amount, I will send this back to `address`.\nchangeAmount := myTotalCoinsInSatoshi - targetAmount - fee\n```\n\n### 5) Lets build the transaction output.\nI want you to send me the coins to: `mwJn1YPMq7y5F8J3LkC5Hxg9PHyZ5K4cFv`.\nHere is how:\n```golang\n// Create the target transaction output\ntargetAddress := \"mwJn1YPMq7y5F8J3LkC5Hxg9PHyZ5K4cFv\"\ntargetH160, _ := encoding.AddressToPubKeyHash(targetAddress)\ntargetScript := script.NewP2PKHScript(targetH160)\ntargetTxOut := tx.TxOut{\n    Amount:       targetAmount,\n    ScriptPubKey: targetScript,\n}\n```\n\n### 6) Lets not forget amount the change, that's money!\n```golang\n// Create the change transaction output\nchangeH160, _ := encoding.AddressToPubKeyHash(address)\nchangeScript := script.NewP2PKHScript(changeH160)\nchangeTxOut := tx.TxOut{\n    Amount:       changeAmount,\n    ScriptPubKey: changeScript,\n}\n```\n\n### 7) We are almost done! Now we need to combine the inputs \u0026 outputs into a single transaction.\n```golang\n// Combine the inputs \u0026 outputs in a transaction\ntransaction := tx.Tx{\n    Version:  1,\n    TxIns:    []txscript.TxIn{txIn},\n    TxOuts:   []txscript.TxOut{targetTxOut, changeTxOut},\n    Locktime: 0,\n    Testnet:  true,\n}\n// And sign the inputs please. In this way you verify that the money\n// you are about to spend are, indeed, yours.\ntransaction.SignInput(0, priv)\n```\n\n### 8) Print the hex of the transaction, so we can broadcast it to the network!\n```golang\nbytes, _ = transaction.Marshal()\nfmt.Printf(\"Tx's Hex: %s\\n\", hex.EncodeToString(bytes))\n```\nNow you can navigate to a service like https://live.blockcypher.com/btc-testnet/pushtx/ and\nbroadcast your transaction to the world! Soon, you will be able to do so directly from btcd.\n\n\n#### The full source of making a transaction is in [makeTransaction.go](./makeTransaction.go)\n\n## Unit tests\n```bash\n$ go test ./...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvivelev%2Fbtcd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvivelev%2Fbtcd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvivelev%2Fbtcd/lists"}