### Ruby Setup and Usage Source: https://www.blockcypher.com/dev/bitcoin/index Details how to set up and use the BlockCypher API with Ruby. It includes instructions for installing the official Ruby SDK via RubyGems, initializing the API client with an API token, and provides an example of requiring the library. ```Ruby # Ruby examples use irb, and our official ruby sdk: # https://github.com/blockcypher/ruby-client # You can install it easily from rubygems.org: # https://rubygems.org/gems/blockcypher-ruby gem install blockcypher-ruby # Remember to require the library after installing > require 'blockcypher' => true # Unless otherwise noted, all requests assume an initialized API 'block_cypher' API object > block_cypher = BlockCypher::Api.new(api_token:"YOURTOKEN") => # ``` -------------------------------- ### JavaScript Setup and Usage Source: https://www.blockcypher.com/dev/bitcoin/index Provides instructions for using BlockCypher's API with JavaScript, specifically mentioning the use of jQuery for browser-based examples. It suggests that porting these examples to Node.js is straightforward, recommending the 'request.js' library. ```JavaScript // JavaScript examples use JQuery and can be run directly in your browser // console (ctrl+shift+i or cmd+shift+i). // Porting them to node.js should be trivial, replacing JQuery methods with // request.js for example. console.log('Welcome to BlockCypher'); ``` -------------------------------- ### BlockCypher API Examples Source: https://www.blockcypher.com/dev/bitcoin/index Examples of how to interact with the BlockCypher API using various programming languages and tools. ```bash curl https://api.blockcypher.com/v1/bitcoin/main/txs/push?token=YOUR_TOKEN \ -H "Content-Type: application/json" \ -d '{ ... }' ``` ```javascript const axios = require('axios'); axios.post('https://api.blockcypher.com/v1/bitcoin/main/txs/push?token=YOUR_TOKEN', { // transaction data }).then(response => { console.log(response.data); }).catch(error => { console.error(error); }); ``` ```ruby require 'net/http' require 'uri' uri = URI.parse('https://api.blockcypher.com/v1/bitcoin/main/txs/push?token=YOUR_TOKEN') http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(uri.request_uri) request['Content-Type'] = 'application/json' request.body = '{ ... }' response = http.request(request) puts response.body ``` ```python import requests url = 'https://api.blockcypher.com/v1/bitcoin/main/txs/push?token=YOUR_TOKEN' data = { ... } response = requests.post(url, json=data) print(response.json()) ``` ```go package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://api.blockcypher.com/v1/bitcoin/main/txs/push?token=YOUR_TOKEN" data := map[string]interface{}{} jsonData, _ := json.Marshal(data) resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonData)) if err != nil { fmt.Println("Error:", err) return } defer resp.Body.Close() var result map[string]interface{} json.NewDecoder(resp.Body).Decode(&result) fmt.Println(result) } ``` ```php [ 'header' => "Content-type: application/json\r\n", 'method' => 'POST', 'content' => json_encode($data), ], ]; $context = stream_context_create($options); $result = file_get_contents($url, false, $context); var_dump(json_decode($result, true)); ?> ``` -------------------------------- ### Get Wallet Information - Ruby Example Source: https://www.blockcypher.com/dev/bitcoin/index Example using the blockcypher Ruby gem to retrieve wallet information. ```ruby block_cypher.wallet_get("alice") ``` -------------------------------- ### List Wallets - Go Example Source: https://www.blockcypher.com/dev/bitcoin/index Example using the gobcy Go library to list wallet names. ```go package main import ( "fmt" "github.com/blockcypher/gobcy" ) func main() { btc := gobcy.API{"YOURTOKEN", "btc", "main"} walletNames, err := btc.ListWallets() if err != nil { fmt.Println(err) } fmt.Printf("Wallets:%v\n", walletNames) } ``` -------------------------------- ### Python Setup and Usage Source: https://www.blockcypher.com/dev/bitcoin/index Explains how to use the official BlockCypher Python library, compatible with Python 2 and 3. It covers installation via pip, importing the module, making basic calls, and how to specify different coin symbols (e.g., 'btc', 'ltc', 'doge') for API requests. ```Python # The official python library (https://github.com/blockcypher/blockcypher-python) works with python2/3 # Install it like this at the command line: $ pip install blockcypher # To access any method, first import the blockcypher module: >>> import blockcypher # Then call the method: >>> blockcypher.foo() # In your codebase, you should probably do it like this though: >>> from blockcypher import foo >>> foo() # By default, all methods return results for BTC, but blockcyphers support many coins. # You can pass coin_sybmol='foo' as an argument to any method, where foo is one of the following: >>> blockcypher.constants.COIN_SYMBOL_LIST [ "btc", "btc-testnet", "ltc", "dash", "doge", "bcy", # blockcypher's testnet ] ``` -------------------------------- ### Install and Initialize BlockCypher PHP Client Source: https://www.blockcypher.com/dev/bitcoin/index Provides instructions for installing the BlockCypher PHP client using Git and Composer, and demonstrates the basic initialization code required for API context, including authentication and logging. ```bash git clone https://github.com/blockcypher/php-client.git cd php-client composer install ``` ```PHP true, 'log.FileName' => 'BlockCypher.log', 'log.LogLevel' => 'DEBUG') ); ?> ``` -------------------------------- ### Get Wallet Information - Python Example Source: https://www.blockcypher.com/dev/bitcoin/index Example using the blockcypher Python library to retrieve wallet addresses for a normal wallet. ```python from blockcypher import get_wallet_addresses get_wallet_addresses(wallet_name='alice', api_key='YOUR_TOKEN') ``` -------------------------------- ### Signing Handled by SDK (JavaScript) Source: https://www.blockcypher.com/dev/bitcoin/index A brief note indicating that the signing process is handled by the SDK in both examples, referring to the previously provided JavaScript and potentially other language examples. ```javascript //signing handled in both examples ``` -------------------------------- ### Get Wallet Information - JavaScript Example Source: https://www.blockcypher.com/dev/bitcoin/index Example using JavaScript's jQuery $.get to retrieve wallet addresses for a normal wallet and HD wallet information. ```javascript // normal wallet $.get('https://api.blockcypher.com/v1/btc/main/wallets/alice/addresses?token=YOURTOKEN') .then(function(d) {console.log(d)}); //hd wallet $.get('https://api.blockcypher.com/v1/btc/main/wallets/hd/bob?token=USERTOKEN') .then(function(d) {console.log(d)}); ``` -------------------------------- ### PHP Examples Placeholder Source: https://www.blockcypher.com/dev/bitcoin/index Placeholder for PHP code examples related to BlockCypher API interactions. ```php //todo: php examples ``` -------------------------------- ### List Wallets - JavaScript Example Source: https://www.blockcypher.com/dev/bitcoin/index Example using JavaScript's jQuery $.get to list wallet names. ```javascript $.get('https://api.blockcypher.com/v1/btc/main/wallets?token=YOURTOKEN') .then(function(d) {console.log(d)}); ``` -------------------------------- ### List Wallets - Python Example Source: https://www.blockcypher.com/dev/bitcoin/index Example using the blockcypher Python library to list wallet names. ```python from blockcypher import list_wallet_names list_wallet_names('YOUR_TOKEN') ``` -------------------------------- ### List Wallets - cURL Example Source: https://www.blockcypher.com/dev/bitcoin/index Example using cURL to list wallet names. ```curl curl https://api.blockcypher.com/v1/btc/main/wallets?token=YOURTOKEN ``` -------------------------------- ### BlockCypher Bitcoin API - Bash Example Source: https://www.blockcypher.com/dev/bitcoin/index A bash script example showing how to use `curl` to interact with the BlockCypher Bitcoin API. This is useful for quick testing or integration into shell scripts, demonstrating calls to endpoints like pushing raw transactions. ```bash # Example using curl to push a raw transaction # RAW_TX="0100000001..." # Your raw transaction hex # API_TOKEN="YOUR_API_TOKEN" # curl -s # -X POST # -d "{"tx": "$RAW_TX"}" # "https://api.blockcypher.com/v1/btc/main/txs/push?token=$API_TOKEN" ``` -------------------------------- ### Get Bitcoin Blockchain Overview (PHP) Source: https://www.blockcypher.com/dev/bitcoin/index Shows how to obtain the Bitcoin main blockchain overview using the Blockcypher PHP client. The `get()` method of the `BlockchainClient` is used, requiring an initialized `$apiContext`. ```PHP $blockchainClient = new BlockchainClient($apiContext); $blockchain = $blockchainClient->get('BTC.main'); ``` -------------------------------- ### BlockCypher Bitcoin API - Python Example Source: https://www.blockcypher.com/dev/bitcoin/index A Python example illustrating interaction with the BlockCypher Bitcoin API. This could involve fetching transaction data, creating transactions, or managing assets using a Python client library or direct HTTP requests. ```python # Example using a hypothetical BlockCypher Python SDK # from blockcypher import BlockCypher # api = BlockCypher('YOUR_API_TOKEN', 'bitcoin') # Get unconfirmed transactions # unconfirmed_txs = api.get_unconfirmed_transactions() # print(unconfirmed_txs) # Push a raw transaction # raw_tx = "0100000001..." # Your raw transaction hex # result = api.send_raw_transaction(raw_tx) # print(result) ``` -------------------------------- ### List Payments Endpoint (PHP) Source: https://www.blockcypher.com/dev/bitcoin/index PHP example demonstrating how to list forwarding addresses using the PaymentForwardClient. Requires an API context. ```php $paymentForwardClient = new PaymentForwardClient($apiContext); $paymentForwardArray = $paymentForwardClient->listForwardingAddresses(); ``` -------------------------------- ### Initializing BlockCypher Go SDK Source: https://www.blockcypher.com/dev/bitcoin/index Shows how to initialize the BlockCypher Go SDK by creating an API object with your token, currency, and network. The example prints the initialized object. ```go package main import ( "fmt" "github.com/blockcypher/gobcy" ) func main() { //Adding your token is part of the API coin/chain initialization btc := gobcy.API{"YOURTOKEN", "btc", "main"} fmt.Printf("%+v\n", btc) } //Result from `go run`: //{Token:YOURTOKEN Coin:btc Chain:main} ``` -------------------------------- ### Get Transaction Confidence (Python) Source: https://www.blockcypher.com/dev/bitcoin/index Example using the Blockcypher Python client to get transaction confidence details. ```python >>> from blockcypher import get_transaction_details >>> get_transaction_details('43fa951e1bea87c282f6725cf8bdc08bb48761396c3af8dd5a41a085ab62acc9', confidence_only=True)) { "age_millis": 12725, "confidence": 0.9901509730004237, "receive_count": 666, "txhash": "43fa951e1bea87c282f6725cf8bdc08bb48761396c3af8dd5a41a085ab62acc9", "txurl": "https://api.blockcypher.com/v1/btc/main/txs/43fa951e1bea87c282f6725cf8bdc08bb48761396c3af8dd5a41a085ab62acc9" } ``` -------------------------------- ### Using the BlockCypher Ruby SDK Source: https://www.blockcypher.com/dev/bitcoin/index Provides an example of how to initialize and use the BlockCypher Ruby SDK. It demonstrates creating an API object with your token and setting the currency and network. ```ruby # Import Ruby SDK > require 'blockcypher' => true # Make new Api object, intialize with your token > block_cypher = BlockCypher::Api.new(api_token:"YOURTOKEN") => # ``` -------------------------------- ### Get Wallet Information - cURL Example Source: https://www.blockcypher.com/dev/bitcoin/index Example using cURL to retrieve information for a normal and an HD wallet. ```curl # normal wallet curl https://api.blockcypher.com/v1/btc/main/wallets/alice?token=YOURTOKEN # hd wallet curl https://api.blockcypher.com/v1/btc/main/wallets/hd/bob?token=YOURTOKEN ``` -------------------------------- ### Get Bitcoin Block by Height (PHP) Source: https://www.blockcypher.com/dev/bitcoin/index Provides a PHP example for retrieving Bitcoin block information via the Blockcypher API. It illustrates setting request parameters and calling the `get` method on the `BlockClient`. ```php $blockClient = new BlockClient($apiContext); $params = array( 'txstart' => 1, 'limit' => 1, ); $block = $blockClient->get('671142', $params); ``` -------------------------------- ### Get Bitcoin Blockchain Overview (Go) Source: https://www.blockcypher.com/dev/bitcoin/index Demonstrates how to fetch the Bitcoin main blockchain overview using the `gobcy` Go package. It initializes the API client with a token and currency details, then calls `GetChain()` to retrieve the data. ```Go package main import ( "fmt" "github.com/blockcypher/gobcy" ) func main() { btc := gobcy.API{"YOURTOKEN", "btc", "main"} chain, err := btc.GetChain() if err != nil { fmt.Println(err) } fmt.Printf("%+v\n", chain) } ``` -------------------------------- ### Get Bitcoin Transaction Details with jQuery Source: https://www.blockcypher.com/dev/bitcoin/index This example shows how to fetch Bitcoin transaction details using jQuery's AJAX functionality. It makes a GET request to the Blockcypher API endpoint and logs the response to the console. ```javascript $.get('https://api.blockcypher.com/v1/btc/main/txs/f854aebae95150b379cc1187d848d58225f3c4157fe992bcd166f58bd5063449').then(function(d) {console.log(d)}); ``` -------------------------------- ### Initialize BlockCypher API Client (Go) Source: https://www.blockcypher.com/dev/bitcoin/index Demonstrates how to initialize the BlockCypher API client in Go for Bitcoin mainnet and BlockCypher's testnet. Requires the `gobcy` package and a valid API token. ```Go package main import ( "fmt" "github.com/blockcypher/gobcy" ) func main() { // For Bitcoin main: btc := gobcy.API{"YOURTOKEN","btc","main"} // For BlockCypher's internal testnet: bcy := gobcy.API{"YOURTOKEN","bcy","test"} fmt.Println(btc, bcy) } ``` -------------------------------- ### Get Bitcoin Mainnet Information (JavaScript) Source: https://www.blockcypher.com/dev/bitcoin/index Retrieves current status and statistics for the Bitcoin mainnet using a JavaScript AJAX GET request. The response is logged to the console. This example demonstrates how to interact with the API using client-side JavaScript. ```javascript $.get('https://api.blockcypher.com/v1/btc/main').then(function(d) {console.log(d)}); ``` -------------------------------- ### Initialize Blockcypher API Client in Go Source: https://www.blockcypher.com/dev/bitcoin/index Shows how to initialize the Blockcypher API client in Go using the `gobcy` library. This includes setting the API token, coin type, and network. ```go package main import ( "fmt" "github.com/blockcypher/gobcy" ) func main() { btc := gobcy.API{"YOURTOKEN", "btc", "main"} // Example usage: btc.get_block_overview("671142", nil) fmt.Println("Blockcypher API client initialized.") } ``` -------------------------------- ### Get Transaction Confidence (Ruby) Source: https://www.blockcypher.com/dev/bitcoin/index Example of retrieving transaction confidence using the Blockcypher Ruby client. ```ruby > block_cypher.tx_confidence("4153fddf43c5fd6aa7834bda643619e6dd7d8bf55206bcedb216296881a07830") => {"age_millis"=>114659, "receive_count"=>783, "confidence"=>0.9999808966243114, "txhash"=>"4153fddf43c5fd6aa7834bda643619e6dd7d8bf55206bcedb216296881a07830", "txurl"=>"https://api.blockcypher.com/v1/btc/main/txs/4153fddf43c5fd6aa7834bda643619e6dd7d8bf55206bcedb216296881a07830"} ``` -------------------------------- ### Create, Sign, and Send Bitcoin Transaction (Go) Source: https://www.blockcypher.com/dev/bitcoin/index This Go example shows the complete lifecycle of a Bitcoin transaction using the gobcy SDK. It includes generating addresses, using the faucet to fund an address, creating a new transaction, signing it locally with a private key, and sending the signed transaction to the network. It also prints the resulting transaction details. ```go //this is the same example as below, demonstrates //creating New TXSkels, signing, and Sending TXSkels package main import ( "fmt" "github.com/blockcypher/gobcy" ) func main() { //note the change to BlockCypher Testnet bcy := gobcy.API{"YOURTOKEN", "bcy", "test"} //generate two addresses addr1, err := bcy.GenAddrKeychain() addr2, err := bcy.GenAddrKeychain() //use faucet to fund first _, err = bcy.Faucet(addr1, 3e5) if err != nil { fmt.Println(err) } //Post New TXSkeleton skel, err := bcy.NewTX(gobcy.TempNewTX(addr1.Address, addr2.Address, *big.NewInt(2e5)), false) //Sign it locally err = skel.Sign([]string{addr1.Private}) if err != nil { fmt.Println(err) } //Send TXSkeleton skel, err = bcy.SendTX(skel) if err != nil { fmt.Println(err) } fmt.Printf("%+v\n", skel) } ``` -------------------------------- ### Get Transaction Confidence (PHP) Source: https://www.blockcypher.com/dev/bitcoin/index Example using the Blockcypher PHP client to fetch transaction confidence. ```php // Run on console: // php -f .\sample\confidence-factor\TransactionConfidenceEndpoint.php $txClient = new TXClient($apiContext); $txConfidence = $txClient->getConfidence('43fa951e1bea87c282f6725cf8bdc08bb48761396c3af8dd5a41a085ab62acc9'); { "age_millis":2188284017, "receive_count":-1, "confidence":1, "txhash":"43fa951e1bea87c282f6725cf8bdc08bb48761396c3af8dd5a41a085ab62acc9", "txurl":"https://api.blockcypher.com/v1/btc/main/txs/43fa951e1bea87c282f6725cf8bdc08bb48761396c3af8dd5a41a085ab62acc9" } ``` -------------------------------- ### Initialize BlockCypher Ruby SDK Source: https://www.blockcypher.com/dev/bitcoin/index Demonstrates how to initialize the BlockCypher Ruby SDK with an API token. This is the first step to interacting with the BlockCypher API using the official Ruby client. ```ruby # Import Ruby SDK require 'blockcypher' # Make new Api object, intialize with your token block_cypher = BlockCypher::Api.new(api_token:"YOURTOKEN") ``` -------------------------------- ### Get Transaction Confidence (Go) Source: https://www.blockcypher.com/dev/bitcoin/index Example using the Blockcypher Go client to retrieve transaction confidence. ```go package main import ( "fmt" "github.com/blockcypher/gobcy" ) func main() { btc := gobcy.API{"YOURTOKEN", "btc", "main"} //querying a recent TX hash detected on BTC network conf, err := btc.GetTXConf("bb01beea75683be16b5d59dd3e084d167f41a6866b6880b3070eefff392fdd2a") if err != nil { fmt.Println(err) } fmt.Printf("%+v\n", conf) } //Result from `go run`: //{Age:21112 ReceiveCount:756 Confidence:0.9995223691726662 TXHash:bb01beea75683be16b5d59dd3e084d167f41a6866b6880b3070eefff392fdd2a} ``` -------------------------------- ### Get Transaction Confidence (cURL) Source: https://www.blockcypher.com/dev/bitcoin/index Example using cURL to fetch transaction confidence from the Blockcypher API. ```curl curl https://api.blockcypher.com/v1/btc/main/txs/43fa951e1bea87c282f6725cf8bdc08bb48761396c3af8dd5a41a085ab62acc9/confidence ``` -------------------------------- ### Create, Sign, and Send Bitcoin Transaction (Go) Source: https://www.blockcypher.com/dev/bitcoin/index Demonstrates the process of creating a new Bitcoin transaction, signing it locally using a private key, and then broadcasting it to the network using the BlockCypher API. This example utilizes the `gobcy` library. ```go package main import ( "fmt" "github.com/blockcypher/gobcy" ) func main() { //note the change to BlockCypher Testnet bcy := gobcy.API{"YOURTOKEN", "bcy", "test"} //generate two addresses addr1, err := bcy.GenAddrKeychain() addr2, err := bcy.GenAddrKeychain() //use faucet to fund first _, err = bcy.Faucet(addr1, 3e5) if err != nil { fmt.Println(err) } //Post New TXSkeleton skel, err := bcy.NewTX(gobcy.TempNewTX(addr1.Address, addr2.Address, *big.NewInt(2e5)), false) //Sign it locally err = skel.Sign([]string{addr1.Private}) if err != nil { fmt.Println(err) } //Send TXSkeleton skel, err = bcy.SendTX(skel) if err != nil { fmt.Println(err) } fmt.Printf("%+v\n", skel) } ``` -------------------------------- ### Get Metadata (Python) Source: https://www.blockcypher.com/dev/bitcoin/index Example using the Blockcypher Python client to fetch public and private metadata for an address. ```python >>> from blockcypher import get_metadata # Get Private Metadata (none set yet, returns empty) >>> get_metadata(address='1rundZJCMJhUiWQNFS5uT3BvisBuLxkAp', api_key='YOUR_TOKEN', private=True) {} # Get Public Metadata (set by you or anyone else) >>> get_metadata(address='1rundZJCMJhUiWQNFS5uT3BvisBuLxkAp', api_key='YOUR_TOKEN') { "name": "silkroad", "owner": "dpr" } ``` -------------------------------- ### Get Public and Private Metadata (cURL) Source: https://www.blockcypher.com/dev/bitcoin/index Examples using cURL to retrieve public and private metadata associated with a Bitcoin address. ```curl # Get Public Metadata (set by you or anyone else) curl https://api.blockcypher.com/v1/btc/main/addrs/1rundZJCMJhUiWQNFS5uT3BvisBuLxkAp/meta?token=YOURTOKEN {"name":"silkroad","owner":"dpr"} # Get Private Metadata (none set yet, returns empty) curl https://api.blockcypher.com/v1/btc/main/addrs/1rundZJCMJhUiWQNFS5uT3BvisBuLxkAp/meta?token=YOURTOKEN&private=true {} ``` -------------------------------- ### Create Forwarding Address (Go) Source: https://www.blockcypher.com/dev/bitcoin/index Example using the Blockcypher Go library to create a forwarding address. It initializes the API client and calls the `CreatePayFwd` method. ```Go package main import ( "fmt" "github.com/blockcypher/gobcy" ) func main() { btc := gobcy.API{"YOURTOKEN", "btc", "main"} payfwd, err := btc.CreatePayFwd(gobcy.PayFwd{Destination: "15qx9ug952GWGTNn7Uiv6vode4RcGrRemh", CallbackURL: "https://my.domain.com/callbacks/forwards"}) if err != nil { fmt.Println(err) } fmt.Printf("%+v\n", payfwd) } //Result from `go run`: //{ID:6fbe2b48-fe79-44a2-9cdc-8114bc4d5fcc Destination:15qx9ug952GWGTNn7Uiv6vode4RcGrRemh InputAddr:17Ri1Shdzo5G8kiUys1qoeM8w1PNj1eFAK ProcessAddr: ProcessPercent:0 ProcessValue:0 CallbackURL:https://my.domain.com/callbacks/forwards EnableConfirm:false MiningFees:0 TXHistory:[]} ``` -------------------------------- ### Get BlockCypher SDK Version (Python) Source: https://www.blockcypher.com/dev/bitcoin/index This snippet shows how to determine the installed version of the blockcypher Python SDK using the `pkg_resources` module. ```Python import pkg_resources print(pkg_resources.get_distribution("blockcypher")) ``` -------------------------------- ### Get Bitcoin Transaction Details with Blockcypher Python SDK Source: https://www.blockcypher.com/dev/bitcoin/index This example shows how to fetch Bitcoin transaction details using the Blockcypher Python SDK. It imports the `get_transaction_details` function and calls it with the transaction hash. ```python from blockcypher import get_transaction_details get_transaction_details('f854aebae95150b379cc1187d848d58225f3c4157fe992bcd166f58bd5063449') ``` -------------------------------- ### Get Bitcoin Block by Height (Go) Source: https://www.blockcypher.com/dev/bitcoin/index Demonstrates how to fetch Bitcoin block details using the Blockcypher API in Go. It shows how to set parameters like transaction start and limit, and how to handle potential errors. ```go params := make(map[string]string) params["txstart"] = "1" params["limit"] = "1" block, err := btc.GetBlock(671142, "", params) if err != nil { fmt.Println(err) } fmt.Printf("%+v\n", block) ``` -------------------------------- ### Create Normal Wallet (Go) Source: https://www.blockcypher.com/dev/bitcoin/index Creates a normal wallet using the blockcypher Go library. Initializes the API with a token, coin, and network. Then, it calls CreateWallet with a Wallet struct containing the wallet name and a list of public addresses. Handles potential errors and prints the wallet information. ```go package main import ( "fmt" "github.com/blockcypher/gobcy" ) func main() { btc := gobcy.API{"YOURTOKEN", "btc", "main"} //normal wallet alice, err := btc.CreateWallet(gobcy.Wallet{"alice", []string{"1JcX75oraJEmzXXHpDjRctw3BX6qDmFM8e"}}) if err != nil { fmt.Println(err) } fmt.Printf("Normal Wallet:%+v\n", alice) } ``` -------------------------------- ### Fetch Bitcoin Address Full Info using JavaScript (jQuery) Source: https://www.blockcypher.com/dev/bitcoin/index This example shows how to fetch full Bitcoin address details using JavaScript with the jQuery AJAX method. It makes a GET request to the BlockCypher API and logs the response to the console. ```javascript $.get('https://api.blockcypher.com/v1/btc/main/addrs/1DEP8i3QJCsomS4BSMY2RpU1upv62aGvhD/full?before=300000') .then(function(d) {console.log(d)}); ``` -------------------------------- ### Get Bitcoin Block by Hash with Transaction Filtering Source: https://www.blockcypher.com/dev/bitcoin/index Retrieves detailed information about a specific Bitcoin block using its hash. Supports filtering transactions within the block by a starting index and a maximum limit. The limit parameter has a maximum allowed value of 500. ```APIDOC /blocks/$BLOCK_HASH | GET | [Block](https://www.blockcypher.com/dev/bitcoin/#block) Parameters: txstart (integer): Filters response to only include transaction hashes after txstart in the block. limit (integer): Filters response to only include a maximum of limit transaction hashes in the block. Maximum value allowed is 500. Example Usage: https://api.blockcypher.com/v1/btc/main/blocks/00000000000000000003dc20b868d17121303308f6bba329302e75913f0790db?txstart=20&limit=20 BLOCK_HASH is a string representing the hash of the block you're interested in querying, for example: 0000000000000000189bba3564a63772107b5673c940c16f12662b3e8546b412 The returned object contains information about the block, including its height, the total amount of satoshis transacted within it, the number of transactions in it, transaction hashes listed in the canonical order in which they appear in the block, and more. For more detail on the data returned, check the [Block](https://www.blockcypher.com/dev/bitcoin/#block) object. ``` -------------------------------- ### Create Regular Wallet (Ruby) Source: https://www.blockcypher.com/dev/bitcoin/index Provides a Ruby example for creating a regular wallet using the Blockcypher gem. It demonstrates calling the `wallet_create` method with the wallet name and a list of addresses. ```Ruby block_cypher.wallet_create("alice",["1JcX75oraJEmzXXHpDjRctw3BX6qDmFM8e"]) ``` -------------------------------- ### Get Wallets (Go) Source: https://www.blockcypher.com/dev/bitcoin/index Demonstrates how to fetch both normal and HD wallets using the Blockcypher Go library. It initializes the API client with a token, coin, and network, then calls GetWallet and GetHDWallet. Error handling is included for API calls. ```go package main import ( "fmt" "github.com/blockcypher/gobcy" ) func main() { btc := gobcy.API{"YOURTOKEN", "btc", "main"} //normal wallet alice, err := btc.GetWallet("alice") //hdwallet bob, err := btc.GetHDWallet("bob") if err != nil { fmt.Println(err) } fmt.Printf("Normal Wallet: %v\nHDWallet: %v\n", alice, bob) } ``` -------------------------------- ### List Webhooks (Go) Source: https://www.blockcypher.com/dev/bitcoin/index This Go program demonstrates how to list webhooks using the gobcy library. It initializes the API client with your token and cryptocurrency details, then calls the ListHooks method. ```Go package main import ( "fmt" "github.com/blockcypher/gobcy" ) func main() { btc := gobcy.API{"YOURTOKEN", "btc", "main"} hooks, err := btc.ListHooks() if err != nil { fmt.Println(err) } fmt.Printf("%+v\n", hooks) } ``` -------------------------------- ### Create Wallet Endpoint Source: https://www.blockcypher.com/dev/bitcoin/index Demonstrates how to create a new wallet using the Blockcypher API. This includes examples for both standard wallets and Hierarchical Deterministic (HD) wallets, specifying the wallet name, associated addresses or extended public keys, and the target Bitcoin network. ```APIDOC POST /v1/{coin}/{chain}/wallets?token={token} Creates a new wallet. Request Body: - For normal wallets: { "name": "", "addresses": ["", "", ...] } - For HD wallets: { "name": "", "extended_public_key": "" } Parameters: - `coin`: The cryptocurrency (e.g., btc). - `chain`: The blockchain network (e.g., main, test3). - `token`: Your Blockcypher user token. Response Body (for normal wallet): { "token": "", "name": "", "addresses": ["", ...] } Response Body (for HD wallet): { "token": "", "name": "", "hd": true, "extended_public_key": "", "chains": [ { "chain_addresses": [ { "address": "", "path": "" }, ... ] }, ... ] } Example (normal wallet on Bitcoin Main): curl -d '{"name": "alice","addresses": ["1JcX75oraJEmzXXHpDjRctw3BX6qDmFM8e"]}' https://api.blockcypher.com/v1/btc/main/wallets?token=YOURTOKEN Example (HD wallet on Bitcoin Main): curl -d '{"name": "bob", "extended_public_key": "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8"}' https://api.blockcypher.com/v1/btc/main/wallets/hd?token=YOURTOKEN Example (HD wallet BIP84 on Bitcoin Testnet): curl -d '{"name": "charlie", "extended_public_key": "vpub5bJX9NkmSDP33H5PxJXmehqyV7aDaVWxudvzDW3kP4c5Z5KFEaUNtJ9CLebEiEssZJyZa7AE9zR5Q7nqPAmk6xgRpRvXRMKj6WPfBGBi3fR"}' https://api.blockcypher.com/v1/btc/test3/wallets/hd?token=YOURTOKEN ``` -------------------------------- ### Generate Address and Fund with Faucet (Go) Source: https://www.blockcypher.com/dev/bitcoin/index Generates a new address keychain and then funds it using the BlockCypher Go SDK. Includes error handling and prints the address and transaction hash. ```go package main import ( "fmt" "github.com/blockcypher/gobcy" ) func main() { bcy := gobcy.API{"YOURTOKEN", "bcy", "test"} //Generate new address pair, err := bcy.GenAddrKeychain() //Fund it with faucet txhash, err := bcy.Faucet(pair, 100000) if err != nil { fmt.Println(err) } fmt.Printf("Address: %v, Faucet TXHash: %v\n", pair.Address, txhash) } ``` -------------------------------- ### Signing Handled by SDK Source: https://www.blockcypher.com/dev/bitcoin/index A brief note indicating that the signing process is handled by the SDK in subsequent steps, implying that the provided code snippets are part of a larger workflow. ```bash # Signing is handled by our SDK in the next step ``` -------------------------------- ### Example API Request Source: https://www.blockcypher.com/dev/bitcoin/index Example cURL command to fetch transaction propagation information for a specific Bitcoin transaction hash. ```curl curl https://api.blockcypher.com/v1/btc/main/txs/5cad31bd8baf5d10ecdc275193f878226bb51f549c2357658f3dd0d7c5402a7b/propagation?token=YOURTOKEN ``` -------------------------------- ### Create and Send Custom Bitcoin Transaction (Go) Source: https://www.blockcypher.com/dev/bitcoin/index This Go example shows how to use the gobcy library to create a multisignature transaction skeleton. It initializes the BlockCypher API client for the testnet and uses `TempMultiTX` to set up the multisig transaction details before proceeding with the new/send process. ```Go package main import "github.com/blockcypher/gobcy" func main() { //note the change to BlockCypher Testnet bcy := gobcy.API{"YOURTOKEN", "bcy", "test"} //use TempMultiTX to set up multisig temptx := gobcy.TempMultiTX("", "destAddr", 25000, 2, []string{"pubkey1", "pubkey2", "pubkey3"}) //Then follow the New/Send two-step process with this temptx as the input } ``` -------------------------------- ### Get Bitcoin Address Details (jQuery) Source: https://www.blockcypher.com/dev/bitcoin/index Retrieves Bitcoin address details using a jQuery AJAX GET request to the Blockcypher API. Demonstrates handling the response in a JavaScript callback. ```javascript $.get('https://api.blockcypher.com/v1/btc/main/addrs/1DEP8i3QJCsomS4BSMY2RpU1upv62aGvhD') .then(function(d) {console.log(d)}); ``` -------------------------------- ### Push Bitcoin Transaction (Go) Source: https://www.blockcypher.com/dev/bitcoin/index This Go code snippet demonstrates how to push a Bitcoin transaction using the `gobcy` SDK. It initializes the BlockCypher API client for the testnet and uses the `PushTX` method with a provided transaction hex. Error handling and printing the transaction skeleton are included. ```go package main import ( "fmt" "github.com/blockcypher/gobcy" ) func main() { //note the change to BlockCypher Testnet bcy := gobcy.API{"YOURTOKEN", "bcy", "test"} skel, err := bcy.PushTX("01000000011fdd692992f3d3859d01762119313a655177a59226ede31adc0199b28c73c450000000006a4730440220298915c785165233e2f19192bbbb9b8c3fed6d064279cb8968af6698c783b875022037287134f9f0aaf84429ba9bb50f1efcb4cedcfbd34407c285134e068234432c012102b17f04f5fa1bd44315ef33f8759822a302a2ba7fa28c56a50fac0441a341b96affffffff02400d0300000000001976a91446c7681dcacaee1ea3f57eced37755d1d09e070188accc550100000000001976a91490d969679032cc1af6a69b4161778f12e90cb13588ac00000000") if err != nil { fmt.Println(err) } fmt.Printf("%+v\n", skel) } //Result from `go run`: ```