If you’ve been P2P trading for a while, you have likely done many custodial trades, and if you’ve just started dabbling more in the non-custodial side of trading since the addition of it to LocalCoinSwap, you might be wondering how it works.
While bitcoin script can be quite a complicated topic, let’s explore some of the basics and see why non-custodial trading is the safest way to trade bitcoin.
What are the Benefits of Non-Custodial Trading?
Even though peer-to-peer (P2P) trading has significant benefits when it comes to privacy, security, and freedom compared to many types of bitcoin exchange, non-custodial trading allows you to take things further.
Security:
When trading using non-custodial bitcoin wallets and engaging in a non-custodial trade on LocalCoinSwap, the platform doesn’t have direct access to your funds. During a dispute, moderation staff can help moderate disagreements, but they couldn’t take your funds even if they wanted to.
Privacy:
One of the ways LocalCoinSwap sets itself apart from most other P2P exchanges is that we believe that access to cryptocurrencies is essential, and for a lot of people, this can only occur when there is a reasonable degree of privacy involved. Whether you suffer from financial exclusion, a lack of documentation, or live in an unstable region having access to cryptocurrency can be vital. If you want to register an account on LocalCoinSwap, you can do so with only an active email address.
Intermediaries:
When performing a non-custodial bitcoin trade on LocalCoinSwap, you don’t have third parties managing your cryptocurrency or holding your funds. If you are trading more substantial amounts and don’t want to rely on the platform to store your bitcoin, you don’t have to. One of the only downsides of non-custodial trading is waiting on a couple of blockchain confirmations, and in return, you get extra peace of mind making for a valid trade-off in many situations.
How is My Account Secure?
When you register an account on LocalCoinSwap, a mnemonic phrase is then generated. This phrase is only ever available to you and not something the platform or staff has access to at any point. Thanks to this, we cannot seize or control your funds without your knowledge, not that we ever want to do so in the first place. You’re likely familiar with mnemonic phrases if you’ve used any other popular bitcoin web wallets or, in some cases, even popular bitcoin mobile wallets. It’s crucial that your mnemonic phrase is secret and only shown to you as this is what your non-custodial wallets are derived from when using the platform.
With your mnemonic and private keys being available for export, you can import them into other wallets if you so choose, or store them in case you need or want to access your funds directly, without having to use the platform at all.
How Does All This Relate to Escrow?
Your private keys must be secure; otherwise, using the escrow system would involve trusting the platform and invalidate the point of non-custodial exchange. While we still offer custodial trading for bitcoin, if you don’t want to risk handing over control to your bitcoin even temporarily, non-custodial trading is the only way you’ll likely want to trade. It wouldn’t matter how good the escrow process was on LocalCoinSwap if we could access your private keys or account mnemonic.
Starting a Non-Custodial Bitcoin Trade
When you first enter a trade, you’ll be able to chat with the other trader before accepting the exchange; once you do so, it’s then time to move onto the next step, bitcoin escrow.
When you fund the escrow, you may assume that you are dealing with a multi-signature transaction; this is actually not the case. Avoiding the use of multi-signature transactions allows us to minimize the on-chain activity required to securely trade bitcoin, in-turn keeping fees low and trades as fast as possible.
There are three participants in the bitcoin escrow for non-custodial trades on LocalCoinSwap. You have the buyer, seller, and lastly, LocalCoinSwap, which acts purely as the arbitrator in case of disputes. When the bitcoin is placed into escrow, essentially what happens is a bitcoin script (represented by an address) controls how the bitcoin is “spent” or, to put it more casually, what can be done with the bitcoin while the script is in charge of it.
The bitcoin escrow script has a few terms, just as any good P2P trader does for their trades to go as smoothly as possible. Firstly, the funds can be released to the buyer by the seller at any time; this allows for your typical trade flow to progress naturally without intervention in a typical trade. If you receive payment, it’s quick and easy to release the escrow to the buyer. Secondly, the buyer can release the funds back to the seller at any point as well. In case they change their mind and decide to back out of a trade, just as an example. It is important to note that neither party can release the bitcoin to themselves in either case.
At the end of the day, all the escrow script wants is for everyone to be happy (metaphorically, of course). When both traders agree one way or another, the script can complete its job and release the bitcoin.
However, there is one more condition that the script allows covering all bases, disputes. Suppose neither trader agrees who should receive the bitcoin. In that case, the arbitrator (a moderator on the LocalCoinSwap team) can step in, look at the situation, and once it has been clarified, they can release the bitcoin to the correct party, but again never to themselves.
How Are Fees Collected?
As the platform requires revenue to operate and continue to provide P2P trading across the world, a small fee must be collected from completed trades. You may find yourself wondering how this is possible, given that the script doesn’t allow anyone to give the coin to themselves. There is a secondary script designed to manage this part of the process. It works similarly to the escrow script to ensure that only the correct fees are collected and given to the platform and only under the right conditions (a completed trade).
Passing Secrets Not Keys
Now, this is where things get a little more interesting. During the construction of the trade, each of the three parties involved (buyer, seller, arbitrator) generates “secrets.” As the arbitrator’s role is a little more complicated than the buyer or the seller (at least regarding how the bitcoin script operates), the arbitrator generates two secrets.
To spend the bitcoin in the escrow script, you require access to two of the three secrets involved, and while this sounds a little like a multisig transaction, it is different. When the escrow is funded, hashed versions of all these secrets are available to the script allowing it to verify that secrets passed to it are genuine while not being available for just anyone to see either.
This is interesting because you can effectively complete a trade by merely giving your secret to the relevant party. Something we are excited to explore in regards to this is the ability to trade in areas with unstable internet and even volatile access to electricity. Trades could effectively be completed offline, while still benefiting from the escrow and flexibility of P2P trading.
What Happens Once a Trade is Completed?
Unlike non-custodial ethereum trading, where you would have to perform a secondary transaction on-chain to release the bitcoin (and incurring extra fees and delays), this isn’t necessary here. The scripts are compiled into addresses that the bitcoin runtime can interpret, allowing the network to allow the selected user to spend the bitcoin.
With the ability of SegWit addresses to reduce fees for users, these are used when compiling the scripts used by LocalCoinSwap. On a more technical level, instead of generating a P2SH, we create a P2SH(P2WSH) bitcoin address. At the end of the process, once everyone is satisfied, the result is a bitcoin SegWit transaction that is a combination of various inputs, outputs, and other relevant information required by the bitcoin network to process it.
How Do I Trust this is How Everything Works?
The great thing about non-custodial trading (well, one of the many) is that you don’t have to trust us; you can verify it yourself. We have published example bitcoin scripts over on GitHub that document and provide examples of the entire bitcoin escrow and non-custodial bitcoin trading process we use. If you want to get your hands a little dirty, or just better understand how your trades work, head on over and check it out here. Even if you’re more of a casual or hobbyist coder, just someone interested in blockchain development, or bitcoin scripts with a little time, you’ll be able to see how non-custodial P2P trading really works.
What Now?
If all this has got you itching to do some bitcoin trading, head on over to LocalCoinSwap and try out the most popular non-custodial P2P marketplace for yourself. If you’re waiting for just the right time to do some trading, head over to our blog and find LocalCoinSwap updates and more cryptocurrency content just like this.