---
# System prepended metadata

title: RPC Scavenger Hunt

---

# RPC Scavenger Hunt

 RPC Scavenger Hunt is a task (the first task) at BOSS 2025 cohort, to prepare participant for open source development on Bitcoin and Lightning Network. The program was organised by Btrust Builders and Chaincode Labs.
 
 The hunt consist of ten tasks, and we are required to write bash script (that was my first time of writing a bash script, lol). Before then, I already set up Bitcoin core on my laptop, I have bitcoin-cli and some other requirements. We were given the rpc connect, username and password, and I had to install `jq - a lightweight and flexible command-line JSON processor.` on my laptop. In your editor, the file extension for your bash script is `.sh`, and you have to add `#!/bin/bash` at the beginning of the file. To make your script file executable, you run `chmod +x <file_name>`. I was given remote procedure call (rpc) parameters in my `.bitcoin` dir.
 
 ### TASK 1
 I was tasked to get the hash of block, given a block height. 
Fix; `echo $(bitcoin-cli getblockhash block_height)`. `echo` is used to display a line of text that is passed in as an argument.

### TASK 2
I was asked to verify the signature by an address over a message. 
Fix; `echo $(bitcoin-cli verifymessage $address $signature $message)`
Note: You can find all the methods [here](https://developer.bitcoin.org/reference/).

### TASK 3
I was tasked to calculate the total number of output(txs) by a block given the block height.
Fix; I used the block height to get the block hash, and with the hash I was able to get the block. In the block, I got the transaction array and get the vout (the ouput tx), find the number of each `vout` in the transaction array and added everything together.

### TASK 4
I was given an extended public key, and I was asked to use descriptor to compute taproot address at index 100. A **taproot address** is a specific bitcoin address format starting with `bc1p` and **descriptor** is a simple, human-readable strings that fully describe a set of Bitcoin addresses.
Fix; I computed the descriptor from the extended public key and index. I used the `getdescriptorinfo` method and `jq` to get the descriptor sumcheck, and used the `deriveaddresses` method to get the taproot address.

### TASK 5
I was tasked to create a 1-of-4 P2SH multisig address from the public keys in the four inputs of a tx id. `P2SH - (pay to script hash)` is a type of bitcoin transaction that allows the sender to commit to a script, or set of conditions, that must be met in order to spend the funds.
Fix; I got the transaction using `getrawtransaction` method and destructured `.vin[].txinwitness[1]` out. Then I used `createmultisig` to create the multisig and echoed the address.

### TASK 6
I was given a block height, and asked to find a tx that spends the coinbase output of another block. The coinbase transaction is always the first transaction in a block, as it is used by the miners to get the transaction fee.
Fix; I destructured the tx id from the target block and the coinbase block(this is just one tx). Ran a loop over the transactions in the target block, got the raw tx and destructured the `txid` from the `vin[]`. Then checked if the `txid` is the same as the `txid from the coinbase block`. Then echoed out the result.

### TASK 7
I was tasked to find the address that the unspent output `utxo` was sent to, in a block, given the block height.
Fix; Destructured the `txid` from the `tx[]`, ran a loop over the `txid`, got the raw transactions, and destructured the `.vout[].n`. Ran a nested loop over `.vout[].n`, using the `gettxout` method, and destructured `.scriptPubKey.address`. Any address that doesn't return an empty string is the correct utxo address.

### TASK 8
I was tasked to find the public key that signed input 0 in a transaction given the transaction id.
Fix; I had to analyse the witness script, as `asm` and `hex` in the scriptPubkey are empty strings. I destructured `.vin[].txinwitness[-1]` from the transaction (I used -1, to get the last item in the array). Then I sliced the witness script with `cut -c 5-70` and `cut -c 77-142` to get the two public keys. I got the control byte at the second index of the array using `.vin[].txinwitness[1]`, so as to know which pub key to pick. Then I echoed the output.

### TASK 9
I was tasked to find how many satoshi a transaction paid, given the transaction id.
Fix; Got the raw transaction, decoded the transaction, got the transaction id of each `vin` and `vout`, and got the value, then did the subtraction of `in` from `out`, then multiplied it by `100_000_000`. The output was in btc and had to convert it to satoshi, and `100_000_000 satoshi = 1 BTC`

### TASK 10
I was tasked to find the transction id of a transaction taht signalled opt-in BRF in a block, given the block height. `Opt-in BFR (Replace-by-Fee)` is a Bitcoin feature that allows users to flag transactions as replaceable until they are confirmed in a block. In a case where the transction fee is low and the miners are not picking the tx, you can add more transaction fee, so that the miners can mine it and add it to the block. In simple term, it is like `double spending`, but the protocol has prevented the abuse of it already.
Fix; Got the `.tx[]`, ran a loop over it, then get the raw transaction. Destructured `.vin[].sequence` from the raw transaction and check if it is `< 4294967294`. The transaction at the point is the tx that signals opt-in RBF.

The solution to these tasks can be found [here on github](https://github.com/BOSS-2025/rpc-scavenger-hunt-aagbotemi). NB; It is a private repo.
