Prepin
Log in

Verify Bitcoin Transactions

Approach / Explanation

In this question, the interviewer is seeking to assess your knowledge and comprehension of Bitcoin transactions and their validation through SQL. You are expected to explain how to confirm the occurrence of a Bitcoin transaction by searching for its record in a database using SQL commands. Here are some important points to keep in mind: Awareness of what constitutes a Bitcoin transaction Understanding of the data structure associated with Bitcoin transactions Proficiency in SQL, including the ability to create queries to retrieve data from a database

Suggested Answer

A Bitcoin transaction is made up of inputs and outputs. Inputs are linked to the outputs of previous transactions, while outputs include a specific amount and a cryptographic key. When we refer to 'validating a Bitcoin transaction,' we mean verifying whether the inputs are unspent and the signatures are authentic. Here’s an example of a SQL query that uses sample tables to illustrate Bitcoin transaction data: SELECT * FROM Bitcoin_Transactions WHERE Inputs IN ( SELECT Output_ID FROM Bitcoin_Transaction_Outputs WHERE Is_Spent = 0 ) AND Transaction_Signature IS VALID; In the SQL query above, the Bitcoin_Transactions table represents the complete set of transactions, while the Bitcoin_Transaction_Outputs table contains the outputs from earlier transactions. The Output_ID serves as the unique identifier for each output, and Is_Spent is a flag that shows whether the output has been used or not. Additionally, Transaction_Signature signifies the cryptographic proof of the spender's authorization to execute the transaction, which also needs to be verified.

Alternative Answer

If the database design is more intricate and includes additional tables to represent inputs and outputs for each transaction, the SQL query might be structured as follows: SELECT BT.Transaction_ID FROM Bitcoin_Transactions BT JOIN Transaction_Inputs TI ON BT.Transaction_ID = TI.Transaction_ID JOIN Transaction_Outputs TO ON TO.Output_ID = TI.Output_ID WHERE TO.Is_Spent = 0 AND BT.Transaction_Signature IS VALID; In this SQL example, the tables Transaction_Inputs and Transaction_Outputs are utilized to denote the inputs and outputs for each transaction, respectively. The query connects these tables based on the relationship between transactions and their respective inputs and outputs to check if the inputs are unspent and whether the transaction signature is valid.

Question Details

Difficulty & Category

Medium
sql

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin LLC · Philadelphia, PA · All rights reserved.