Skip to main content

Liquid Bitcoin peg-in(s) in the browser!

· 2 min read
Marco Argentieri

Any wallet developer can integrate trustless Liquid Bitcoin peg-in features in their own application, even in the browser!

npm install --save pegin# or with yarnyarn add pegin

Then in your JavaScript or TypeScript project


import ElementsPegin from 'pegin';
// initialize the moduleconst peginModule = new ElementsPegin(  await ElementsPegin.withGoElements(),  await ElementsPegin.withLibwally(),);
// get a pegin address to deposit Bitcoinconst peginAddress = await peginModule.getMainchainAddress(  claimScript // Liquid scriptpubkey);

// deposit funds to the Bitcoin addressconsole.log(peginAddress); 
// retrieve the raw bitcoin transaction hex encoded and the merkle block proof, pass them along the Liquid script used to generate the pegin addresslet claimTx = await peginModule.claimTx(    btcTxHex,    btcTxOutProof,    claimScript);
// Now you can broadcast the transaction to the Liquid Network

What's a peg-in?#

Liquid Network allows anyone to "convert" BTC into L-BTC, the sidechain native asset, with a process called peg-in: it consists in sending Bitcoin to the Liquid federation multisignature script tweaked with the user's Liquid script.

After 102 Bitcoin mainchain blocks, the user can claim his Liquid bitcoins creating a special Liquid transaction and broadcast it to the Liquid Network.

How a user can peg-in?#

At the moment the process is quite cumbersome and requires the user to use an Elements node via command line interface. This basically forced the majority of users to use centralized exchanges, involving a custodial process and counterparty risks.

Trustless peg-in in the browser#

TDEX allows anyone to trade Liquid assets freely without being custodian of funds and the major road block to increase TDEX and Liquid Network usage is to let people to get Liquid Bitcoin with their mainchain Bitcoin.

Browsers and mobile apps built with web technologies such as React Native or Cordova can now use the npm pegin module and integrate this in few lines of code.

Try now!#

Try the pegin feature, now live in the TDEX mobile app!