<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bamidele Oluwatobi on Medium]]></title>
        <description><![CDATA[Stories by Bamidele Oluwatobi on Medium]]></description>
        <link>https://medium.com/@teebams49?source=rss-7860ef80bf9a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VZKrOPYongPyYa2nZqtVJg.jpeg</url>
            <title>Stories by Bamidele Oluwatobi on Medium</title>
            <link>https://medium.com/@teebams49?source=rss-7860ef80bf9a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 19:51:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@teebams49/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Creating BIP21 Invoice with NodeJS]]></title>
            <link>https://medium.com/@teebams49/creating-bip21-invoice-with-nodejs-52eb3e6f8019?source=rss-7860ef80bf9a------2</link>
            <guid isPermaLink="false">https://medium.com/p/52eb3e6f8019</guid>
            <dc:creator><![CDATA[Bamidele Oluwatobi]]></dc:creator>
            <pubDate>Fri, 10 Jun 2022 09:54:54 GMT</pubDate>
            <atom:updated>2022-06-10T09:54:54.345Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever tried paying using bitcoin and you are faced with a UI toggle telling you to choose either an on-chain or a Lightning transaction? This is not always a nice approach as it can lead to confusion for users who are new to the Bitcoin ecosystem. What if we could create one QR code that is backward compatible, where we have both the Bitcoin address and the BOLT 11 invoice all in one QR code?</p><p>The great news here is that it is very possible with the help of <a href="https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki">BIP21</a>. When BIP21 was created, the developers made sure there where room for additional query keys that could be used in the future, as we would be able to use one of these for a Lighting Network invoice. With BIP21, wallets that only support on-chain Bitcoin transactions would scan the QR code and be able to process the Bitcoin payment, wallets that support only Lightning transactions can also scan the same QR code and process the payment, while wallets that support both could scan the same QR code then prompt the user to select what protocol they want to use in processing the payment. The wallet can also make automatic choices e.g. based on payment size.</p><p>User Experience (UX) is greatly improved with these unified payment instructions for both new and experienced users. In the below example we will build a BIP21 QR code that supports both on-chain and lightning transactions using NodeJS.</p><p><strong>Project Setup</strong></p><p><strong>Requirements</strong></p><ul><li>Basic knowledge of JavaScript.</li><li><a href="https://nodejs.org/en/">NodeJs</a> is installed on your local machine.</li><li>Basic knowledge of Bitcoin.</li></ul><p><strong>Setup Environment</strong></p><ul><li>Packages: <a href="https://github.com/bitcoinjs/bip21">bip21</a></li></ul><p><strong><em>Note:</em></strong><em> Packages (or dependencies) are 3rd party javascript code we will utilize in our application.</em></p><p>The code below creates a directory on your computer, in your terminal enter the code as seen below.</p><pre>mkdir bip21<br>cd bip21</pre><p>Initialize a new Node.js application by entering the code below which would create a package.json file, in which we can specify a start script and other details for our application.</p><pre>npm init -y</pre><p>Next, we will create an index.js file and specify it as our point of entry into our application.</p><p>In the package.json file add the line &quot;start&quot;: &quot;node index.js&quot; to the scripts object. You can replace the default &quot;test&quot; command, which we won&#39;t be using.</p><p>Your package.json file should look like what’s below</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ab48196e546f23d99ba0cb9c2df0632/href">https://medium.com/media/1ab48196e546f23d99ba0cb9c2df0632/href</a></iframe><p>Run the command below on your terminal to generate an index.js file.</p><pre>touch index.js</pre><p>Next, we can install the additional javascript package we’ll be using. Install the needed dependencies with the following commands</p><pre>npm install bip21</pre><p><a href="https://github.com/bitcoinjs/bip21">bip21</a>: This is a library that helps us encode our payment information into a URI.</p><p><strong>Getting Started with code</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/851212873dd533bb50bd0f28e1044ff9/href">https://medium.com/media/851212873dd533bb50bd0f28e1044ff9/href</a></iframe><p>The code above is, first of all, importing the <a href="https://github.com/bitcoinjs/bip21">BIP21</a> library, after that, we declared a bitcoin address, then an object variable that holds the following keys:<br>label: Label for that address (e.g. name of receiver).<br>message: The description for the transaction.<br>amount: the amount that’s required to be paid to the address (in BTC)<br>lightning: This is the lightning invoice that is being generated for the said transaction, this is what wallets that support only lighting or both Lightning and on-chain transactions would use to get the lightning invoice they are expected to pay.</p><p>Line 13 of the code above is where we are using the data we declared above to generate a valid URI. The BIP21 library’s encode method takes two parameters. The first is the on-chain address to where payment is to be made and the second parameter takes in the options object which has the label, amount, message, and lightning invoice.</p><p>Run the line of code below to see the result the BIP21 library will return.</p><pre>npm run start</pre><p>After running this you should see a result like what’s below in your terminal.</p><pre>bitcoin:bc1q0gf7ygdcwjxtfgmzlaqqtxn3s7sdamyw5v48a5?label=Buy%20me%20Coffee&amp;message=Let%27s%20test%20BIP21&amp;amount=0.0005&amp;lightning=lnbc10u1p3pj257pp5yztkwjcz5ftl5laxkav23zmzekaw37zk6kmv80pk4xaev5qhtz7qdpdwd3xger9wd5kwm36yprx7u3qd36kucmgyp282etnv3shjcqzpgxqyz5vqsp5usyc4lk9chsfp53kvcnvq456ganh60d89reykdngsmtj6yw3nhvq9qyyssqjcewm5cjwz4a6rfjx77c490yced6pemk0upkxhy89cmm7sct66k8gneanwykzgdrwrfje69h9u5u0w57rrcsysas7gadwmzxc8c6t0spjazup6</pre><p>You could generate a QR code with the URI above, I used the <a href="https://www.qr-code-generator.com/">QR-code-Generator website</a> and I got the QR code below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*WwJ5dOygnlbv8wpW6ObP1A.png" /></figure><p>Scan the QR code above using <a href="https://bluewallet.io/">Blue Wallet</a> or any other wallet that supports BIP21 for both Lightning and on-chain and you would get the result below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*p2z5PXo-5AUh892yhiNYuA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*oh_AAw045ej8cXj9xXlefA.jpeg" /><figcaption>Bitcoin and Lightning Wallet</figcaption></figure><p><strong>Note</strong>: The lightning invoice I used for this example has expired.</p><p><strong>Major Concern</strong></p><p>My main concern is for wallet developers to adopt this and implement it on their wallets because as per the time of writing of this article, not all wallets could successfully scan the QR code above which is not a good experience for the user. Wallets that support the BIP 21 QR code are:</p><ul><li><a href="https://bluewallet.io/">Blue Wallet</a> (On-chain and Lightning Wallet)</li><li><a href="https://blixtwallet.github.io/">Blixt Wallet</a> (Lightning Wallet)</li></ul><p><strong>Resources</strong></p><ul><li><a href="https://bitcoinmagazine.com/technical/bitcoin-improvement-proposal-21-helps-users">Bitcoin Improvement Proposal 21 Helps Users</a></li><li><a href="https://bitcoinqr.dev/">Unified QRs for Bitcoin</a></li><li><a href="https://github.com/sbddesign/bip21-lightning">GitHub - sbddesign/bip21-lightning</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52eb3e6f8019" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bitcoin Time locks]]></title>
            <link>https://medium.com/@teebams49/bitcoin-time-locks-e373bad4c0fa?source=rss-7860ef80bf9a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e373bad4c0fa</guid>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[bitcoin-time-locks]]></category>
            <category><![CDATA[time-lock]]></category>
            <dc:creator><![CDATA[Bamidele Oluwatobi]]></dc:creator>
            <pubDate>Thu, 19 May 2022 09:39:34 GMT</pubDate>
            <atom:updated>2022-05-19T09:39:34.868Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fPhwRwG-viit0_OdskHVfg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@moneyphotos?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">olieman.eth</a> on <a href="https://unsplash.com/s/photos/bitcoin?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Last week at <a href="https://qala.dev/">Qala Africa</a> we were tasked with picking a topic from a collection of topics, researching it, and then presenting it. I picked <strong>Time locks </strong>and was paired with <a href="https://twitter.com/rukundo__">Collin</a>. I choose time locks because that was a concept I didn’t quite understand at the time, this gave me the opportunity to research properly; I learned a lot and I will be sharing what I learned with you.</p><p><strong>What are Time locks in Bitcoin?</strong></p><p>A time lock is a locking mechanism that restricts the spending of Bitcoins until a particular time or block height in the future. This means that you can lock some Satoshis and specify some time in the future when those Satoshis could be spent. Just like a father sending some Satoshis to his child now (2022) but specifying in the transaction that the child can only spend the satoshis in the year 2040.</p><p><strong>Classifying Time locks</strong></p><p>Time locks can be classified using three basic attributes: Location, Target, and Unit.</p><p><strong>Location</strong>: This is the place in which time lock is applied; it could be applied at the transaction level, that’s locking the whole transaction, or it could be applied at the script level whereby a particular UTXO or Output is locked until a particular time or block height in the future.</p><p><strong>Target</strong>: This refers to the time in which the time lock is meant to expire, i.e. the coin will be available for spending. This could be an <strong>Absolute</strong> or <strong>Relative</strong> time. Absolute time is a definite time, for example, “The meeting would end by 04:00 pm” is an absolute time specifying that the meeting definitely ends by that time, but the relative time depends on other conditions to get the time, for example, “The meeting would last for 3 hours” this means that no matter when the meeting starts the meeting would be ending after 3 hours. In relation to Bitcoin, this means that a coin can be locked to an absolute time in the future and it can be locked relative to when the transaction or UTXO is mined into a block.</p><p><strong>Units:</strong> This refers to the unit of measurement the timelock uses. In Bitcoin, they can be measured based on the number of blocks or the number of seconds.</p><h3><strong>Bitcoin Time locks</strong></h3><p>There are currently four locks at the time of writing this article, they are nLocktime, nSequence, OP_CHECKLOCKTIMEVERIFY(OP_CLTV), and OP_CHECKSEQUENCEVERIFY(OP_CSV). Two of them are script-level locks and two are transaction-level locks.</p><p><strong>nLocktime</strong></p><p>This is a <strong>transaction</strong> level and an absolute time lock. This was the initial time lock that was shipped with the First Bitcoin core client that was written by Satoshi. A transaction has the lock_time field by default and the current Bitcoin Core reference sets the value to the &lt;Current Block Height + 1&gt; to prevent fee sniping. The nLocktime locks a transaction until a particular time in the future, which means the transaction would not be a valid transaction and cannot be propagated until the specified time, this has a major drawback. Imagine I construct a transaction with a particular <strong>Unspent Transaction Output</strong> (UTXO) from a previous transaction and set the nlocktime to a time in the future, I can only send that transaction to you but cannot share it across the network because it would be regarded as an invalid transaction. The drawback is you could keep holding to that transaction waiting for when it would be valid, but from my end, I can (double) spend the UTXO I used in that transaction in another transaction and if that gets mined into a block, the transaction I sent to you becomes invalid and you lose the funds tired to that transaction, a solution to this is the OP_CHECKLOCKTIMEVERIFY.</p><p><strong>CLTV</strong></p><p>OP_CHECKLOCKTIMEVERIFY is a <strong>script</strong> level and <strong>absolute</strong> time lock. This was introduced as a Soft fork into Bitcoin in <a href="https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki"><strong>BIP 65</strong></a><strong>,</strong> this is used to lock UTXOs instead of the whole transaction. What this means is, continuing from our previous example, instead of locking the whole transaction this time I only lock the output I am sending to you until a particular time in the future. This protects you from me double-spending the UTXO I used in constructing the transaction for you as it is eligible to be mined immediately, it just cannot be spent immediately. Another thing to be careful about is locking UTXO to some time far in the future as that would keep your funds locked up and you can’t use it.</p><p>How this works is that the transaction you are creating to spend an output locked by CLTV must have a nlocktime greater than or equal to the lock-time specified in the output. The script checks to compare the nlocktime of the transaction and that of the output, if nlocktime is less than the CLTV value the transaction is invalid, if it is equal or greater the transaction is valid, and remember a transaction with nlocktime is valid only when the current block height or time is equal to or greater than the nlocktime value.</p><p>I would like to bring your attention to the fact that although CLTV is a script-level transaction it still relies on the nLocktime value as its time source, that&#39;s the same nLocktime that’s used for transaction-level lock. Although, both locks use the nLocktime value, however the script-level CLTV enables the locking transaction to be valid (and therefore mined) immediately.</p><p><strong>Note:</strong> If the Script is locked in seconds then the nlocktime must be in seconds and if locked in block height the nlocktime must be in block height or else the transaction is invalid.</p><pre><br>|           |**Locking tx**          | **Spending tx**        |<br>|-----------|------------------------|------------------------|<br>| nLocktime | invalid until timelock | invalid until timelock |<br>| CLTV      | valid immediately      | nvalid until timelock  |</pre><p><strong>nSequence</strong></p><p>This is a <strong>transaction</strong> level and <strong>relative</strong> time lock. This was introduced in <a href="https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki"><strong>BIP 68</strong></a> and was activated as a soft fork in mid-2016. This helps lock the whole transaction relative to when the UTXO you are trying to spend was mined into a block, and this is specified in every input but it is a transaction-level lock.</p><p><strong>Note:</strong> All nSequence value in transaction input must be less than or equal to the time it is relative to, in order for the transaction to be valid.</p><p><strong>CSV</strong></p><p>OP_CHECKSEQUENCEVERIFY is a <strong>script </strong>level and <strong>relative</strong> time lock. This was described in BIP 112 and was soft-forked in mid-2016. It is very similar to CLTV as they both lock UTXOs and they work in the same way ensuring UTXOs are not being spent until the time specified in the future, just that this is a relative time lock.</p><p>How it works is, when creating a transaction just like in the case of CLTV, the nSequence value should be equal to or greater than the CSV value. The script checks that the nSequence value is greater or equal to the CSV value to make the transaction valid. If that’s not the case, the transaction is considered invalid.</p><p>A Simple Summary Table</p><pre>|           | **Location** | **Target** | **Units**    |<br>|-----------|--------------|------------|--------------|<br>| nLocktime | Transaction  | Absolute   | Block | Time |<br>| CLTV      | Script       | Absolute   | Block | Time |<br>| nSequence | Transaction  | Relative   | Block | Time |<br>| CSV       | Script       | Relative   | Block | Time |<br></pre><p><strong>Use cases for time lock today</strong></p><p><strong>Prevent Fee sniping:</strong> Fee sniping is when a miner tries to steal the fees for a transaction by trying to re-mine one or more previous blocks in order to steal fees from miners who have previously mined that block. Currently, it’s still theoretical because of the available block subsidy, but this might be an issue when the block subsidy runs out/is severely reduced. To prevent this, lock_times are set to &lt;Current Block Height + 1&gt;. This can combat fee-sniping because the transaction would be invalid in an earlier block that a miner might try to re-mine, as the transaction is only valid for the next block that is to be created.</p><p><strong>Lightning Network HTLC</strong>: HTLC stands for Hash Time-Locked Contracts, this is how payments are made between channels in the Lightning network. Time locks help to ensure that HTLC does not last forever; if the payment has not been settled within the timeout, the HTLC can be claimed back by the sender.</p><p><strong>Degrading Multi-Sig Transactions</strong>: Timelocks can also be useful for multi-Sig transactions. A typical example is a company creates a multi-sig transaction and specifies that 2 private keys of specific Managers should be able to spend the funds immediately at any point in time, but a second clause could allow the company lawyer to spend the funds after 2 months if the funds have not been spent as a backup.</p><p><strong>Conclusion</strong></p><p>Thanks for reading through, I hope you had a great time reading about Bitcoin Time locks, they are so interesting😊😊. I will write an article soon on how to create time-locked transactions with Node JS. Cheers🥂</p><p><strong>References</strong></p><p><em>Bitcoin’s Time locks: </em><a href="https://medium.com/summa-technology/bitcoins-time-locks-27e0c362d7a1"><em>https://medium.com/summa-technology/bitcoins-time-locks-27e0c362d7a1</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e373bad4c0fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making JSON Remote Procedure Call (RPC) with Axios to Bitcoin-Core in Node JS]]></title>
            <link>https://medium.com/@teebams49/making-json-remote-procedure-call-rpc-with-axios-to-bitcoin-core-in-node-js-5eb889745f93?source=rss-7860ef80bf9a------2</link>
            <guid isPermaLink="false">https://medium.com/p/5eb889745f93</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[json-rpc]]></category>
            <category><![CDATA[bitcoin]]></category>
            <dc:creator><![CDATA[Bamidele Oluwatobi]]></dc:creator>
            <pubDate>Mon, 25 Apr 2022 10:08:34 GMT</pubDate>
            <atom:updated>2022-04-25T11:23:57.929Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I_oSyfE0Da4xpVX6eLmJnw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@unarchive?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jeremy Bezanger</a> on <a href="https://unsplash.com/s/photos/bitcoin?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Making JSON-RPC to Bitcoin-core with Axios is very easy but was very difficult for me the first time I tried it out because I could not place my hand on any article or video that help explain it out or better still gave me a guide to follow🤦‍♂️. I made up my mind that when i am able to figure it out, i would definitely write about it and here we are.🥳</p><p>Together we would write code to make request to Bitcoin-Core in this article. Before we move forward you can read about what RPC is <a href="https://www.techtarget.com/searchapparchitecture/definition/Remote-Procedure-Call-RPC">here</a> and also checkout the JSON-RPC <a href="https://www.jsonrpc.org/specification_v1">documentation here</a>. A simple definition of Axios can be seen below.</p><blockquote>Axios is a Javascript library used to make HTTP requests from node js or XMLHttpRequests from the browser and it supports the Promise API that is native to JS ES6</blockquote><p>Let Setup our Project, in your terminal type in the following commands, please ensure you know the current directory your terminal is before entering the command below.</p><pre>mkdir json-rpc<br>cd json-rpc<br>npm init -y<br>touch index.js</pre><p>The code above would create a new directory called json-rpc, a package.json file which we can specify a start script and other details for our application and an index.js file which would serve as our entry point into our Application.</p><p>Add the line &quot;start&quot;: &quot;node index.js&quot; into the scripts object. You can replace the default &quot;test&quot; command, which we won&#39;t be using.</p><p>Your package.json file should look like what’s below 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9fdb227f3879c90788c5d2ceb073063d/href">https://medium.com/media/9fdb227f3879c90788c5d2ceb073063d/href</a></iframe><p>Next let’s install Axios as that’s the package we would use for making the request.</p><pre>npm install axios</pre><pre>or</pre><pre>yarn add axios</pre><p>Next we would get into the fun part of the article which is making request with axios, in the index.js file we created earlier paste the code you see below and we would walk through it together as i explain what each part of the code does.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1906e83c401471b730434c8f13b68e05/href">https://medium.com/media/1906e83c401471b730434c8f13b68e05/href</a></iframe><p>Before we proceed please ensure you have Bitcoin-Core running and a wallet loaded already, for this article we would be using the Signet Network you can choose any network of your choice but please ensure you replace line 10 of the code above with the corresponding port number of the network you are running on.</p><p>Line 1 of the code above is just us importing axios to our application, so we could use it for our request.</p><p>Next you can see the GetBalance function which is a function that would help us get the balance of the current wallet that is loaded. The first variable you can see there is the body which is an object that houses parameters to help make our request. We would take them one at a time</p><p>jsonrpc: This is the version of the JSON-RPC we are using, as of the time of writing this article we basically have two versions ‘1.0’ and ‘2.0’.</p><p>method: This is the command we want Bitcoin-Core to execute for us, you could find more of this commands <a href="https://developer.bitcoin.org/reference/rpc/index.html">here</a>. You could also run this command bitcoin-cli -signet help to get more methods you could use, where -signet represent the current network our Bitcoin Client is running on.</p><p>id: This is an identifier established by us (Client), it could be any string or number, the server (Bitcoin-Core) would respond with this id.</p><p>parameter: This is an array of values that some method above would need in order to execute the command correctly.</p><p>Next, we make our request inside a try catch block so has to handle our error incase where there are any, <strong>Note: when making JSON-RPC request we always use </strong><strong>axios </strong><strong>post method, as the </strong><strong>get method does not allow us pass a body.</strong></p><p>A very important thing to note is that axios post method takes in a third optional parameter which is the config parameter, in our case we configured the auth object with our RPC username and password, you can configure your PRC username and password in the Bitcoin .conf file on your PC.</p><p><strong>Conclusion</strong></p><p>With this we are done, you could log your response out as in our case or use the response for your specific need. Thanks for reading.😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5eb889745f93" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Partially Signed Bitcoin Transactions (PSBTs) with Bitcoin Core and Node Js]]></title>
            <link>https://medium.com/@teebams49/creating-partially-signed-bitcoin-transactions-psbts-with-bitcoin-core-and-node-js-bbb066c041b7?source=rss-7860ef80bf9a------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbb066c041b7</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[psbt]]></category>
            <category><![CDATA[bitcoin-core]]></category>
            <dc:creator><![CDATA[Bamidele Oluwatobi]]></dc:creator>
            <pubDate>Wed, 20 Apr 2022 13:26:08 GMT</pubDate>
            <atom:updated>2022-04-20T13:26:08.895Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j0PHCG3SD-B_FPNYSNm2GQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@wildbook?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Dmitry Demidko</a> on <a href="https://unsplash.com/s/photos/bitcoin?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3><strong>What are Partially Signed Bitcoin Transactions (PSBTs)</strong></h3><p>PSBTs are data format that allows wallets and other tools to exchange information about a Bitcoin transaction and the signatures necessary to complete it.</p><p>Let’s Setup our project</p><p>Create a directory on your computer, in your terminal enter the code below</p><pre>mkdir psbt<br>cd psbt</pre><p>Then initialize a new node application by entering</p><pre>npm init -y</pre><p>The code above would create a package.json file, which we can specify a start script and other details for our application.</p><p>Next we would create an index.js file and specify it as our point of entry into our application.</p><p>Add the line &quot;start&quot;: &quot;node index.js&quot; into the scripts object. You can replace the default &quot;test&quot; command, which we won&#39;t be using.</p><p>Your package.json file should look like what’s below</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f44cbc800db4547f65003d58bce4ec21/href">https://medium.com/media/f44cbc800db4547f65003d58bce4ec21/href</a></iframe><p>Next, lets build out our project structure and files. In the project directory add an index.js file for our server and .env file to store our bitcoin credentials. Next, add a util folder with index.js also create the .gitignorefile, to avoid pushing our .envfile and node_modules folder to GitHub. The following commands, will do this in the command line:</p><pre>touch index.js<br>touch .env<br>mkdir util<br>cd util<br>touch index.js<br>cd ..<br>touch .gitignore</pre><p>Next we can install the additional javascript packages we’ll be using. Packages (or dependencies) are 3rd party javascript code we will utilize in our application. Install the needed dependencies with the following commands</p><pre>npm install axios dotenv</pre><p>dotenv - helps us read our credentials from the .env file<br>axios - helps us make http call to the Bitcoin Client</p><p><strong>Getting Started with Code</strong></p><p>Firstly, you have to ensure Bitcoin core is running on your machine. Let’s setup our .env file, we will be needing the RPC Username and Password for your Bitcoin core running on your machine, also we need the Port number of the network your Bitcoin Core is running on, either Signet, Regtest, Testnet or Mainnet. Your .env file should look like what’s below.</p><pre>RPC_USER=username<br>RPC_PASSWORD=password<br>SIGNET_PORT=38332<br></pre><p>I added the Signet port number, because that’s what i would be using for this article, but you can always choose what ever network your Bitcoin Core is running on and insert the appropriate number. Next, let’s create a RPC wrapper function that helps us make request to the Bitcoin client using Axios, we would be doing this in the util folder, the index.js file. Below is how the code would look like and i would explain in the next section.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28cd3b9ee8d92695a31c393322f3e6ae/href">https://medium.com/media/28cd3b9ee8d92695a31c393322f3e6ae/href</a></iframe><p>The Axios function receives to parameter, the first is the method parameter ( <a href="https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list">you could check here for more methods</a>)which is use to pass a command to the Bitcoin Client, the second Parameter is an Array, which contains parameters that the method we are calling requires. we would see how to use this in the next section when making our first call to the Bitcoin Client.</p><p>Let’s make our first call to the Bitcoin client by getting all our unspent transactions (UTXOs) which we would use later as input for creating a psbt transaction. In the index.js file in the root directory write the code below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a15f329141a4612f5e7310be9717ede2/href">https://medium.com/media/a15f329141a4612f5e7310be9717ede2/href</a></iframe><p>The output should look like this:</p><pre>[<br>  {<br>    txid: &#39;e0810d049284c8c36fb680cecb2c338de5708c9608e4fc5b27d108f3037c6329&#39;,<br>    vout: 1,<br>    address: &#39;tb1qkjpw77z3eg46em94deudaajzqw4nn6v3jxtumu&#39;,<br>    scriptPubKey: &#39;0014b482ef7851ca2bacecb56e78def64203ab39e991&#39;,<br>    amount: 0.00037452,<br>    confirmations: 42,<br>    spendable: true,<br>    solvable: true,<br>    desc: &quot;wpkh([b79bd340/84&#39;/1&#39;/0&#39;/1/91]020ddea8c5575e6cb7e508750b5e27a7a2f555d178267de32f654b07c7ce2ea651)#jsnh98mc&quot;,<br>    safe: true<br>  },<br>...<br>]</pre><p>The above snippet shows how we basically use the Axios function, in this case the listunspent method do not have parameter that’s why a second parameter was not passed.</p><p><strong>Creating a PSBT Transaction</strong></p><p>Creating a psbt transaction is very similar to creating a raw transaction, and we would explore how to use it, to create it we will use the walletcreatefundedpsbt method which takes in two basic parameters and other optional parameter which i won’t cover in this article, you could see more details <a href="https://bitcoincore.org/en/doc/0.19.0/rpc/wallet/walletcreatefundedpsbt/">here</a>.</p><p>The first parameter is an array of input’s you want to spend in that transaction. Inputs are basically unspent UTXO’s, you reference the transaction_id and the output index the particular UTXO is in that transaction.</p><p>The second parameter is also an array of output’s, that’s basically the address of the user you are sending BTC to and the amount, it’s an object with the key being the address and the amount being the value.</p><p>This method helps calculate the fee for the transaction and also helps to insert a change back to one of your address. This method returns a base 64 string value which we would use for signing the transaction, it would also return the fee for the particular transaction.</p><p>I would write a simple helper function that helps me select UTXOs to use as inputs in a transaction, <strong>please this is not a standard method of selecting UTXOs don’t use in production🙏🙏.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1fb21e7dd1c5a0387c1e52a008869f28/href">https://medium.com/media/1fb21e7dd1c5a0387c1e52a008869f28/href</a></iframe><p>Result</p><pre>[<br>  {<br>    txid: &#39;e0810d049284c8c36fb680cecb2c338de5708c9608e4fc5b27d108f3037c6329&#39;,<br>    vout: 1<br>  }<br>]</pre><p>The function above takes in the amount you would like to send and returns the possible UTXOs you could use in the transaction, please remember you shouldn’t use this in a real application, because you have to put in some basic checks like do i have enough BTC to send and stuffs like that.</p><p>Lets’s Create our PSBT transaction</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f2cfdcf3085dd7a3646bdf0badaad9b/href">https://medium.com/media/7f2cfdcf3085dd7a3646bdf0badaad9b/href</a></iframe><p>Result</p><pre>result: {<br>    psbt: &#39;cHNidP8BAHECAAAAASljfAPzCNEnW/zkCJaMcOWNMyzLzoC2b8PIhJIEDYHgAQAAAAD....&#39;,<br>    fee: 0.00000141,<br>    changepos: 0<br>  },</pre><p>The psbt is a 64 string that we would use to sign this transaction, fee is the fee that would be charged for this transaction, and the changepos is the position of the change that’s being paid to my address in the output of this transaction.</p><p>Let proceed to sign this transaction, to sign this transaction we would use the walletprocesspsbt method which takes the psbt from the function we have above, you could see more info <a href="https://bitcoincore.org/en/doc/0.17.0/rpc/wallet/walletprocesspsbt/">here</a>. This method signs all the input your wallet keys can sign and returns a base 64 string psbt.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd5c9c001c7950b529917aa6f1a3ad1b/href">https://medium.com/media/fd5c9c001c7950b529917aa6f1a3ad1b/href</a></iframe><p>Result</p><pre>result: {<br>    psbt: &#39;cHNidP8BAHECAAAAASljfAPzCNEnW/zkCJaMcOWNMyzLzoC2b8PIhJIEDYHgAQAAAAD...&#39;,<br>    complete: true<br>  },</pre><p>The psbt is a base 64 string value we would use to finalize this transaction, to finalize this transaction we would use the finalizepsbt method which requires the psbt value we got from the result above. It returns a psbt value if the transaction is partially signed and a hex value if the transaction is fully signed, the complete value could either be true or false depending if the transaction is fully signed, you can read more about it <a href="https://bitcoincore.org/en/doc/0.17.0/rpc/rawtransactions/finalizepsbt/">here</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ece5fbbbedcee808a27be5814a4bea17/href">https://medium.com/media/ece5fbbbedcee808a27be5814a4bea17/href</a></iframe><p>Result</p><pre>result: {<br>    hex: &#39;0200000000010129637c03f308d1275bfce408968c70e58d332ccbce80b66fc3c88492040d81e00100000000ffffffff0210270000000000001600140b12fbdd49df0e10c7767398189f334b96da46a1af6a000000000000160014ceeea3eb8ce74cb929c7b79e059f9793317c4f4f0247304402205f239dc786333c3ab01b2d0ea81dc89d62443957c2543e19c94eb6004f0ded6602207c0534bcaf8d099bb39716c8852450be21bac4a61c31d76175b81fa42d0edf5f0121020ddea8c5575e6cb7e508750b5e27a7a2f555d178267de32f654b07c7ce2ea65100000000&#39;,<br>    complete: true<br>  }</pre><p>Because our transaction is fully signed we got a hex value, if it’s not fully signed we would get psbt value, now that we have successfully created and signed a PSBT transaction, it would be nice if we could broadcast it to the network and to do that we would use the sendrawtransaction method which take the hex we got from the result above as it’s parameter and returns a transaction id. See more details <a href="https://developer.bitcoin.org/reference/rpc/sendrawtransaction.html">here</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df52bfa8c9b2633a8a01728f190dc369/href">https://medium.com/media/df52bfa8c9b2633a8a01728f190dc369/href</a></iframe><p>Result</p><pre>{<br>  result: &#39;20b32efb5af9d23e010f4eb28fff8981cfb829a80054e6c7fceba97c58a71e62&#39;,<br>  error: null,<br>  id: &#39;curltext&#39;<br>}</pre><p>The result value is the transaction id for this transaction and you can always check it out on any explorer. With this we’ve successfully created and broadcasted a PSBT.🥳🥳</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbb066c041b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Qala/Bitcoin Journey]]></title>
            <link>https://medium.com/@teebams49/my-qala-bitcoin-journey-3260132f5b69?source=rss-7860ef80bf9a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3260132f5b69</guid>
            <dc:creator><![CDATA[Bamidele Oluwatobi]]></dc:creator>
            <pubDate>Mon, 11 Apr 2022 09:06:48 GMT</pubDate>
            <atom:updated>2022-04-11T09:06:48.230Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UHDwlVbYw0lWjNG3Knqj1A.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@foxxmd?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Matt Duncan</a> on <a href="https://unsplash.com/s/photos/journey?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><strong>How it Started….</strong></p><p>I was randomly strolling through my Twitter timeline sometime in the year 2020 can’t remember the month and day vividly when i saw a tweet from <a href="https://www.linkedin.com/in/bernard-parah-22437386">Bernard</a> calling unto African developers to come learn Lightning and Bitcoin development with <a href="https://twitter.com/QalaAfrica">Qala</a> full-time, i was a bit sceptical to apply because he specifically stated that the Program is not for junior developers and at the time i had not work full-time yet i was majorly freelancing so i still had the feeling that i was a developer and could not apply, i was still going through my timeline when <a href="https://twitter.com/asemota">Asemota</a> quoted the tweet still calling out to African developers to apply, with that i applied expecting not to be contacted at all.</p><p>On a faithful evening i was going through my Promotion Tab on Gmail, when i saw a mail from Qala requesting i take technical test, i was a bit scared but i cleared out time on my calendar to take the test. I took the test in the morning and by evening i got a congratulatory message from Qala saying i have successfully moved on to the next step which is to have 10 mins call with a Qala representative and that happened to be <a href="https://www.linkedin.com/in/bernard-parah-22437386">Bernard</a>, that was my first video call with an interviewer and it really went well, Bernard was such a cool person to talk to.</p><p><strong>Next Step</strong></p><p>Few days later, i got a congratulatory mail from Qala saying i have successfully moved on to the next stage which was the Study group stage where we where tasked to read 2 chapters of the <a href="https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch01.asciidoc">Mastering Bitcoin Book</a> per week which would last for 6 weeks.</p><p><strong>Study group structure</strong></p><p>Every week we had discussion questions to answer and ensure we submitted them before our weekly call. We have weekly calls on Thursdays where we are divided into breakout groups, in the breakout groups we are all assigned questions from the discussion questions and we discuss the questions among ourselves before we go to the main group and discuss any pending question we had from our breakout groups and have our summary.</p><p>We did this for six consecutive weeks and this was my very introduction to what Bitcoin really is, what nodes are, how transaction works in Bitcoin, Bitcoin addresses, Wallets, The Bitcoin Network, Bitcoin Blockchain, Mining in Bitcoin, a brief introduction to Lightning. Would be writing more on this in the coming week.</p><p><strong>Next Step</strong></p><p>After the six weeks of the study group we had another 5 weeks of seminar, where we did had another deep dive into more interesting stuffs in Bitcoin. After this i had calls with <a href="https://www.linkedin.com/in/ajonas/">Jonas</a> and Bernard, then had a final code test in order to get into the Qala fellowship program.</p><p><strong>Finally!</strong></p><p>On the 7th March, 2022 i got my congratulatory message for my admission into the Qala Program i was so excited and nervous. And the program officially kickstarted on the 4th April, 2022.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3260132f5b69" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>