{"id":24428943,"url":"https://github.com/ranjbar-dev/bitcoin-wallet","last_synced_at":"2025-04-12T11:12:55.530Z","repository":{"id":64300597,"uuid":"571607694","full_name":"ranjbar-dev/bitcoin-wallet","owner":"ranjbar-dev","description":"bitcoin wallet package for creating and generating wallet, transferring BTC, getting wallet unspent transactions(UTXOs), getting wallet txIs , getting wallet balance and crawling blocks to find wallet transactions","archived":false,"fork":false,"pushed_at":"2025-02-07T11:43:14.000Z","size":78,"stargazers_count":14,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-12T11:12:50.434Z","etag":null,"topics":["address","bitcoin","btc","sign","transaction","wallet"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ranjbar-dev.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-28T13:54:25.000Z","updated_at":"2025-03-18T03:49:09.000Z","dependencies_parsed_at":"2024-07-09T10:06:42.780Z","dependency_job_id":"814c6718-b93d-41a2-a714-2bd160c08544","html_url":"https://github.com/ranjbar-dev/bitcoin-wallet","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ranjbar-dev%2Fbitcoin-wallet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ranjbar-dev%2Fbitcoin-wallet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ranjbar-dev%2Fbitcoin-wallet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ranjbar-dev%2Fbitcoin-wallet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ranjbar-dev","download_url":"https://codeload.github.com/ranjbar-dev/bitcoin-wallet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248557842,"owners_count":21124168,"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":["address","bitcoin","btc","sign","transaction","wallet"],"created_at":"2025-01-20T13:24:59.740Z","updated_at":"2025-04-12T11:12:55.523Z","avatar_url":"https://github.com/ranjbar-dev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bitcoin wallet v2 \n\nBitcoin wallt version 2 for golang programming language \n\ncheck out avaiable methods in pacakge \n\ninstall using `go get -u github.com/ranjbar-dev/bitcoin-wallet@2.0.18`\n\n## Configuration \n\n#### Set config \n\n```\n\n// configure package \nbitcoinwallet.SetConfig(\u0026bitcoinwallet.Config{\n    Timeout:      30,                                 // http client timeout in second\n    Explorer:     explorer.NewTrezorExplorer(),       // exporer to get blockchain info, check ./exporer folder for other options\n    PriceCrawler: pricecrawler.NewBinanceCraweler(),  // price crawler to get current price data, check ./pricecrawler folder for other options\n    FeeCrawler:   feecrawler.NewBlockstreamCrawler(), // fee crawler to get current fee data, check ./feecrawler folder for other options\n    Chaincfg:     \u0026chaincfg.MainNetParams,            // Bitcoin chain config\n})\n\n```\n\n## Private key  \n\n#### Generate new private key \n\n```\n\nprivateKey, _ := bitcoinwallet.GeneratePrivateKey()\nfmt.Println(\"*ecdsa.PrivateKey:\", privateKey)\n\n```\n\n#### Private key to hex string\n\n```\n\nhex, _ := bitcoinwallet.PrivateKeyToHex(privateKey)\nfmt.Println(\"private key hex:\", hex)\n\n```\n\n#### Private key to bytes \n\n```\n\nbytes, _ := bitcoinwallet.PrivateKeyToBytes(privateKey)\nfmt.Println(\"private key bytes:\", bytes)\n\n```\n\n#### Hex string to private key \n\n```\n\nprivateKey, _ := bitcoinwallet.BytesToPrivateKey(bytes)\nfmt.Println(\"*ecdsa.PrivateKey:\", bytes)\n\n```\n\n#### Bytes to private key \n\n```\n\nprivateKey, _ := bitcoinwallet.HexToPrivateKey(hex)\nfmt.Println(\"*ecdsa.PrivateKey:\", bytes)\n\n```\n\n## Address   \n\n#### Private key to address \n\n```\n\naddress, _ := bitcoinwallet.PrivateKeyToAddress(privateKey)\nfmt.Println(\"Address:\", address)\n\n```\n\n#### Address balance  \n\nretrieve address balacne from explorer configured in package\n\n```\n\nbalance, _ := bitcoinwallet.FetchAddressBalance(address)\nfmt.Println(\"Balance in satoshi:\", balance)\n\n```\n\n\n#### Address UTXO's\n\nretrieve address utxo from explorer configured in package \n\n```\n\nutxos, _ := bitcoinwallet.FetchAddressUTXOs(address)\nfmt.Println(\"UTXO records:\", utxos)\n\n```\n\n## Utils \n\n#### Estimate fee \n\nretrieve blockchain high, mid and low fee in sat/vbyte using fee crawler configured in package \n\n```\n\nlow, mid, high, err := bitcoinwallet.FetchEstimateFee()\n\n```\n\n#### Current BTC price \n\nretrieve BTC price in USD using price crawler configured in package \n\n```\n\nprice, err := bitcoinwallet.FetchPrice()\n\n```\n\n\n## Block \n\nIn the Bitcoin blockchain, a block is a collection of transactions that have been confirmed and recorded on the blockchain.\n\n\n### Current block number \n\nfetch current block number using explorer configured in package \n\n```\n\nblockNumber, _ := bitcoinwallet.FetchCurrentBlockNumber()\nfmt.Println(\"blockNumber:\", blockNumber)\n\n```\n\n### Current block hash \n\nfetch current block hash using explorer configured in package \n\n```\n\nblockHash, _ := bitcoinwallet.FetchCurrentBlockHash()\nfmt.Println(\"blockHash:\", blockHash)\n\n```\n\n### Get block by number \n\nfetch block data by block number using explorer configured in package \n\n```\n\nblockData, _ := bitcoinwallet.FetchBlockByNumber(blockNumber)\nfmt.Println(\"blockData:\", blockData)\n\n```\n\n\n## Transaction \n\n### create / sign / broadcast transaction \n\n```\n\nvar inputs models.TransactionInput\n\n// add transaction inputs\ninputs[0] = models.NewTransactionInput(privateKey, utxoValue, utxoIndex, utxoTxId)\n\nvar outputs models.TransactionOutput\n\n// add transaction outputs\noutputs[0] = models.NewTransactionOutput(toAddressBytes, valueInSatoshi)\n\n// create a new transaction\ntransaction := bitcoinwallet.NewTransaction(inputs, outputs)\n\n// get transaction size in bytes\nsize := transaction.Size()\nfmt.Println(\"size of transaction in bytes: \", size)\n\n// get transaction inputs\nfmt.Println(\"transaction inputs: \", transaction.Inputs())\n\n// get transaction outputs\nfmt.Println(\"transaction outputs: \", transaction.Outputs())\n\n// calculate transaction fee based on inputs and outputs\nfmt.Println(\"transaction fee: \", transaction.Fee())\n\n// sign transaction\nerr := transaction.SignAndSerialize()\nif err != nil {\n\n    fmt.Println(\"error on sign and serialize transaction: \", err)\n    return\n}\n\n// broadcast transaction into blockchain\ntxID, err := transaction.Broadcast()\nif err != nil {\n\n    fmt.Println(\"error on broadcast transaction: \", err)\n    return\n}\n\nfmt.Println(\"transaction broadcasted successfully with txID: \", txID)\n\n```\n\n## TODOS \n\n- add tests \n\n- replace int and int64 with big.Int for balance and satoshi transfer usages \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Franjbar-dev%2Fbitcoin-wallet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Franjbar-dev%2Fbitcoin-wallet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Franjbar-dev%2Fbitcoin-wallet/lists"}