<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: OPCAT Maxi</title>
    <description>The latest articles on DEV Community by OPCAT Maxi (@opcat).</description>
    <link>https://dev.to/opcat</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1379475%2F806a73e7-40e5-4ee8-88ca-f1330ba78c49.png</url>
      <title>DEV Community: OPCAT Maxi</title>
      <link>https://dev.to/opcat</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/opcat"/>
    <language>en</language>
    <item>
      <title>[Boost]</title>
      <dc:creator>OPCAT Maxi</dc:creator>
      <pubDate>Sun, 14 Jun 2026 16:55:14 +0000</pubDate>
      <link>https://dev.to/opcat/-28oh</link>
      <guid>https://dev.to/opcat/-28oh</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/opcat/cat-protocol-how-bitcoin-finally-got-native-smart-tokens-bbf" class="crayons-story__hidden-navigation-link"&gt;CAT Protocol: How Bitcoin Finally Got Native Smart Tokens&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/opcat" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1379475%2F806a73e7-40e5-4ee8-88ca-f1330ba78c49.png" alt="opcat profile" class="crayons-avatar__image" width="512" height="515"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/opcat" class="crayons-story__secondary fw-medium m:hidden"&gt;
              OPCAT Maxi
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                OPCAT Maxi
                
              
              &lt;div id="story-author-preview-content-3899962" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/opcat" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1379475%2F806a73e7-40e5-4ee8-88ca-f1330ba78c49.png" class="crayons-avatar__image" alt="" width="512" height="515"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;OPCAT Maxi&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/opcat/cat-protocol-how-bitcoin-finally-got-native-smart-tokens-bbf" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jun 14&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/opcat/cat-protocol-how-bitcoin-finally-got-native-smart-tokens-bbf" id="article-link-3899962"&gt;
          CAT Protocol: How Bitcoin Finally Got Native Smart Tokens
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/bitcoin"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;bitcoin&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/opcat"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;opcat&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/blockchain"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;blockchain&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ai"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ai&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/opcat/cat-protocol-how-bitcoin-finally-got-native-smart-tokens-bbf" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/exploding-head-daceb38d627e6ae9b730f36a1e390fca556a4289d5a41abb2c35068ad3e2c4b5.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;5&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/opcat/cat-protocol-how-bitcoin-finally-got-native-smart-tokens-bbf#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              &lt;span class="hidden s:inline"&gt;Add&amp;nbsp;Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            12 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
    </item>
    <item>
      <title>CAT Protocol: How Bitcoin Finally Got Native Smart Tokens</title>
      <dc:creator>OPCAT Maxi</dc:creator>
      <pubDate>Sun, 14 Jun 2026 16:49:34 +0000</pubDate>
      <link>https://dev.to/opcat/cat-protocol-how-bitcoin-finally-got-native-smart-tokens-bbf</link>
      <guid>https://dev.to/opcat/cat-protocol-how-bitcoin-finally-got-native-smart-tokens-bbf</guid>
      <description>&lt;p&gt;&lt;strong&gt;Forget indexers. Forget trust assumptions. This is what covenant-enforced token programmability actually looks like.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There is a recurring argument in Bitcoin discourse that goes something like this, Bitcoin doesn’t need tokens. It’s digital gold. Store of value. Leave the programmability to Ethereum.&lt;/p&gt;

&lt;p&gt;That argument is getting harder to make.&lt;/p&gt;

&lt;p&gt;Not because of hype, and not because of marketing. Because of cryptography, UTXO mechanics, and a carefully designed covenant protocol that puts token logic directly inside Bitcoin Script where miners validate it, consensus enforces it, and no third party can corrupt it.&lt;/p&gt;

&lt;p&gt;That protocol is &lt;strong&gt;Covenant Attested Token (CAT)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuwnktk3j1t3utbuonmrj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuwnktk3j1t3utbuonmrj.png" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Press enter or click to view image in full size&lt;/p&gt;

&lt;p&gt;And understanding it requires unlearning almost everything you think you know about how Bitcoin tokens work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem with Every Other Bitcoin Token Protocol&lt;/strong&gt;&lt;br&gt;
Before we can appreciate what CAT does differently, we need to understand with what came before it.&lt;/p&gt;

&lt;p&gt;BRC-20 tokens, Runes, Ordinals-based assets. Colored coins in their many forms. Every major Bitcoin token standard shares a common architectural flaw, they depend on off-chain indexers to determine whether a token transfer is valid.&lt;/p&gt;

&lt;p&gt;Here’s what that actually means in practice.&lt;/p&gt;

&lt;p&gt;When you send a BRC-20 token, the Bitcoin network itself has no idea what you’re doing. Miners see a standard transaction. The “token logic” lives entirely in the interpretation layer a separate piece of software that reads transaction data and decides whether a transfer is legitimate. Change the indexer, run a different implementation, or introduce a bug, and you get a different answer about who owns what.&lt;/p&gt;

&lt;p&gt;This is not a minor implementation detail. It’s a fundamental trust assumption embedded in the protocol. You’re not trusting Bitcoin. You’re trusting whoever runs and maintains the indexer. And with multiple competing indexer implementations, disagreements about token balances are not theoretical they have happened.&lt;/p&gt;

&lt;p&gt;There’s a deeper problem too. Because miners don’t understand these token rules, they happily mine invalid transfers. The network will never reject an “over-mint” transaction under an indexer-based model. Someone has to catch it after the fact. That someone is always a centralized party.&lt;/p&gt;

&lt;p&gt;CAT Protocol was designed from the ground up to eliminate this class of problem entirely.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What CAT Protocol Actually Is&lt;/strong&gt;&lt;br&gt;
CAT stands for Covenant Attested Token. The name is precise these tokens are attested, validated by covenants. Not by indexers. Not by servers. By the Bitcoin consensus mechanism itself.&lt;/p&gt;

&lt;p&gt;At its core, CAT is a UTXO-based token protocol that uses Bitcoin smart contracts specifically, covenant logic to enforce token rules at Layer 1. Every minting rule, every transfer constraint, every balance preservation requirement is embedded in Bitcoin Script and executed by miners when they validate transactions.&lt;/p&gt;

&lt;p&gt;If a transaction violates the rules of a CAT token, the network rejects it, it doesn’t get mined.&lt;/p&gt;

&lt;p&gt;This is the architectural breakthrough. Token validity is no longer a matter of interpretation. It’s a matter of consensus.&lt;/p&gt;

&lt;p&gt;The protocol is built on the OP_CAT Layer, an extension to Bitcoin that enables the covenant mechanics necessary for this kind of programmability. The token state ownership, amount, lineage back to the genesis transaction is stored on-chain in UTXO contract state fields, verifiable by anyone with access to the blockchain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why CAT Is Fundamentally Different&lt;/strong&gt;&lt;br&gt;
Let’s be specific about what this architecture buys you.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;No indexer required&lt;/em&gt;. The token ruleset is guaranteed by Bitcoin consensus. Both token data and logic reside on-chain. There is no off-chain third party involved in determining validity. The risk of indexer centralization, inconsistency, or manipulation simply does not exist.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Miner validation&lt;/em&gt;. When a transaction attempts to violate token rules say, minting beyond the allowed supply miners reject it. The invalid transaction never makes it into a block. This is the same security guarantee Bitcoin provides for BTC transfers, now extended to tokens.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Full on-chain state&lt;/em&gt;. Token balances, ownership records, minting history, and lineage back to the genesis transaction all live on-chain. Light clients can verify all of this independently.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Native Bitcoin security&lt;/em&gt;. CAT tokens inherit Bitcoin’s proof-of-work security model directly. There is no separate consensus mechanism, no additional validator set, no bridging trust assumption introduced by the token layer itself.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;SPV compatibility&lt;/em&gt;. A CAT token transaction that is sufficiently deep in the blockchain can be verified by a light client a mobile wallet, for instance without trusting a full node or a centralized server. This mirrors how Bitcoin itself handles SPV verification. The implications for mobile-native Bitcoin applications are significant.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Cross-chain interoperability&lt;/em&gt;. The CAT protocol enables trust-minimized asset movement between blockchains, where users trust only the underlying chains themselves not bridges, not custodians, not multisig federations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CAT20: Fungible Tokens with Programmable Minting&lt;/strong&gt;&lt;br&gt;
CAT20 is the fungible token standard within the CAT Protocol. Think of it as Bitcoin’s answer to ERC-20, but with a critical difference, the minting rules are not enforced by an indexer they’re enforced by a smart contract that miners execute.&lt;/p&gt;

&lt;p&gt;Deploying a CAT20 token requires two transactions. The first is the genesis transaction, which embeds token metadata (name, symbol, decimals) in a CAT envelope using a specific byte sequence (0x636174 the ASCII encoding of "cat") that signals CAT Protocol participation. The second is the deploy transaction, which establishes the initial minter UTXOs.&lt;/p&gt;

&lt;p&gt;Those minter UTXOs are the keys to the entire minting architecture. New tokens can only be created by spending a minter UTXO. The minter UTXO can generate additional minter UTXOs, enabling recursive minting. But crucially, the rules governing this process are programmed into the minter smart contract not into the protocol itself and not into an indexer.&lt;/p&gt;

&lt;p&gt;This distinction creates extraordinary flexibility.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Open minting&lt;/em&gt; allows anyone to participate the contract specifies total supply and per-transaction limits, and enforces them without any permissioned party. &lt;em&gt;Closed minting&lt;/em&gt; restricts issuance behind a signature requirement. &lt;em&gt;Premine&lt;/em&gt; support lets issuers allocate initial tokens before opening minting to the public, by requiring issuer signatures only for the first mints and then removing that constraint. &lt;em&gt;Fixed supply&lt;/em&gt; is achieved by ensuring the final mint transaction creates no new minter UTXOs once they’re gone, minting is provably terminated.&lt;/p&gt;

&lt;p&gt;Parallel minting deserves special attention. In open minting scenarios, contention for a single minter UTXO would cause most mint transactions to fail. CAT20 addresses this by allowing a mint transaction to create multiple minter UTXOs a “concurrency” parameter. If N = 2, each mint doubles the number of available minter UTXOs, forming a tree structure rather than a chain. Contention drops dramatically as supply propagates.&lt;/p&gt;

&lt;p&gt;Beyond the standard patterns, CAT20 supports arbitrary custom minting logic. Consider what becomes possible:&lt;/p&gt;

&lt;p&gt;Tokens mintable only upon paying a specified amount of BTC to a given address&lt;br&gt;
Tokens mintable only after a certain block height or timestamp&lt;br&gt;
Proof-of-work minting require a computational puzzle solution, effectively mining the token&lt;br&gt;
Tokens mintable only by holders of a different CAT token&lt;br&gt;
Bitcoin-backed issuance the more BTC time-locked, the more tokens earned&lt;br&gt;
None of these require protocol changes. None require a new indexer deployment. They’re just smart contract code, validated on-chain.&lt;/p&gt;

&lt;p&gt;Transfer in CAT20 is equally principled multiple token inputs can be merged, single inputs can be split, and multiple token types can be transferred in a single transaction. The balance preservation invariant inputs must equal outputs is enforced by miners at the protocol level.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CAT721: NFTs That Actually Live on Bitcoin&lt;/strong&gt;&lt;br&gt;
CAT721 is the non-fungible token standard. Unlike CAT20, CAT721 tokens cannot be subdivided. Each token is unique, non-interchangeable, and this is the part that matters stores its full data on-chain immutably in Bitcoin transactions.&lt;/p&gt;

&lt;p&gt;Read that again. Not a hash pointing to an IPFS URL. Not a reference to a centralized metadata server. The actual content.&lt;/p&gt;

&lt;p&gt;Deploying a CAT721 collection uses the same two-transaction pattern as CAT20 genesis transaction embeds collection metadata, deploy transaction establishes minter UTXOs. The collection ID is derived from the genesis outpoint, giving every NFT in the collection an unambiguous cryptographic lineage to a single on-chain event.&lt;/p&gt;

&lt;p&gt;When an individual NFT is minted, it receives its own CAT envelope containing all its metadata content, MIME type, encoding, and optional delegate fields. Each NFT within a collection is assigned a local ID unique within that collection. The global identifier takes the form collectionId:localId, constructed entirely from on-chain transaction data.&lt;/p&gt;

&lt;p&gt;This architecture means provenance is in the protocol. It doesn’t rely on off-chain data. Any party present or future can independently verify which NFTs belong to which collection, who minted them, and what their content is, purely from the Bitcoin transaction history.&lt;/p&gt;

&lt;p&gt;Compare this to the dominant NFT infrastructure of today, where “ownership” frequently means owning a token that points to a URL that may or may not still resolve in ten years. CAT721 is a fundamentally different claim: the content exists on Bitcoin, and Bitcoin’s permanence is its permanence.&lt;/p&gt;

&lt;p&gt;Royalties are supported at the metadata level collection creators can specify a receiver address and percentage though enforcement is voluntary in the marketplace ecosystem rather than protocol-mandated.&lt;/p&gt;

&lt;p&gt;Batch transfers allow multiple NFTs, across different collections, to be moved in a single transaction. The set of NFT inputs must equal the set of NFT outputs. The protocol maintains strict accounting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Contract-Owned Tokens: The Composability Primitive&lt;/strong&gt;&lt;br&gt;
This section is worth slowing down for, because it’s where CAT Protocol’s potential compounds dramatically.&lt;/p&gt;

&lt;p&gt;In standard CAT token usage, each token UTXO has an owner address corresponding to a private key. Spending the token requires a signature, exactly as with standard Bitcoin P2PKH outputs. Clean, familiar, simple.&lt;/p&gt;

&lt;p&gt;But there’s a second ownership model &lt;em&gt;contract hash ownership.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A token UTXO can be deposited to a contract hash the SHA256 hash of an output script. No private key corresponds to this address. No individual controls it. The contract controls it.&lt;/p&gt;

&lt;p&gt;To transfer tokens locked in a contract, the transaction must include a neighboring input that spends a UTXO at the owner contract address. The contract, through covenant logic, can then inspect the entire transaction and enforce whatever rules it specifies before approving the token movement.&lt;/p&gt;

&lt;p&gt;This is composability. And it’s the same primitive that made ERC-20 ecosystem so explosive.&lt;/p&gt;

&lt;p&gt;Before ERC-20 contracts could own tokens, Ethereum had wallets. After, it had Uniswap, Compound, Aave, and every DeFi protocol that followed. The ability for contracts to programmatically custody and transfer tokens without human key management is not a marginal feature it’s what makes an entire class of applications possible.&lt;/p&gt;

&lt;p&gt;CAT Protocol brings this to Bitcoin.&lt;/p&gt;

&lt;p&gt;Consider what becomes buildable:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Automated Market Makers&lt;/em&gt; : liquidity pools holding two CAT20 tokens, with covenant logic enforcing price curves and balance invariants on every swap transaction.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Decentralized exchanges&lt;/em&gt; : order books or pool-based, where the protocol itself holds token custody and enforces settlement.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Lending protocols&lt;/em&gt; : smart contracts that accept CAT tokens as collateral, issue loan positions, and enforce liquidation when collateral ratios drop.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Staking contracts&lt;/em&gt; : token vaults that accept deposits, track time-weighted positions, and release rewards according to programmed schedules.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Escrow systems&lt;/em&gt; : two-party agreements where tokens are held by a contract until conditions are met, releasing to either party based on on-chain verification.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Treasury contracts&lt;/em&gt; : DAO treasuries that hold tokens and require multisig or governance vote to release them.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;On-chain game economies&lt;/em&gt;: contracts that mint, distribute, and verify in-game asset ownership with Bitcoin-grade security.&lt;/p&gt;

&lt;p&gt;Critically, CAT tokens do not need to know about the application contracts that will eventually use them. A token deployed today can be deposited into a contract developed years later by a completely different team. The documentation captures this precisely: CAT tokens are “infinitely extensible and interoperable with decentralized applications.” The contract doesn’t have to be known at mint time.&lt;/p&gt;

&lt;p&gt;This is open-ended composability, native to Bitcoin.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Guard Architecture: The Engineering Layer Under the Composability&lt;/strong&gt;&lt;br&gt;
CAT Protocol implements a system of &lt;em&gt;guard contracts&lt;/em&gt; that act as programmable transfer validators. Every token transfer passes through a guard contract that verifies the transaction satisfies the balance preservation requirements and other protocol rules.&lt;/p&gt;

&lt;p&gt;Understanding guards matters because they represent a deliberate engineering trade-off between transaction complexity and transaction cost. CAT provides four guard variants, parameterized by three values:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TI_COUNT&lt;/strong&gt;: maximum inputs the guard handles&lt;br&gt;
&lt;strong&gt;TO_COUNT&lt;/strong&gt;: maximum outputs the guard handles&lt;br&gt;
&lt;strong&gt;GTT_COUNT&lt;/strong&gt;: maximum distinct token types in a single transaction&lt;br&gt;
The four variants map cleanly to use cases:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;6_6_2–6 inputs, 6 outputs&lt;/em&gt;, 2 token types. The minimal footprint guard. Optimized for peer-to-peer transfers, simple swaps, and any scenario where minimizing fees matters most. Start here.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;6_6_4–6 inputs, 6 outputs&lt;/em&gt;, 4 token types. Slightly larger, supports more complex multi-token swaps and simple DEX operations without blowing up transaction size.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;12_12_2–12 inputs, 12 outputs&lt;/em&gt;, 2 token types. Scaled for batch operations airdrops, UTXO consolidation, payment splitters, multi-party transactions involving one or two token types.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;12_12_4–12 inputs, 12 outputs&lt;/em&gt;, 4 token types. Maximum flexibility for complex DeFi scenarios where multiple token pools and contract interactions need to happen in a single transaction.&lt;/p&gt;

&lt;p&gt;Both CAT20 and CAT721 support all four variants. The guard selection happens at the contract level when deploying. For developers using the SDK’s high-level functions, guard selection is handled automatically based on transaction requirements.&lt;/p&gt;

&lt;p&gt;The principle is sound always use the smallest guard that satisfies your requirements. Over-engineering your guard selection inflates fees unnecessarily. Under-engineering it means transactions fail.&lt;/p&gt;

&lt;p&gt;This modular guard architecture is an important design decision. By decoupling the balance validation logic from the token contract itself and offering it in configurable sizes, CAT Protocol avoids a common trap in smart contract design — forcing every user to pay for the worst-case transaction complexity. You pay for what you need.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Developers Should Care Now&lt;/strong&gt;&lt;br&gt;
The combination of properties described above amounts to something that hasn’t existed on Bitcoin before, a programmable economic substrate where token logic, ownership, validation, and composability are all native to the chain.&lt;/p&gt;

&lt;p&gt;Consider the development surface that opens up.&lt;/p&gt;

&lt;p&gt;Stablecoin protocols can issue CAT20 tokens backed by BTC collateral, with the peg mechanism enforced by minter contracts. No trusted oracle required for basic mechanics the on-chain BTC collateral is directly visible to the covenant.&lt;/p&gt;

&lt;p&gt;Real-world asset tokenization can anchor asset ownership in Bitcoin’s security model. A tokenized treasury bond, a property deed, a trade finance instrument the token’s validity doesn’t depend on a startup’s servers staying online.&lt;/p&gt;

&lt;p&gt;Bitcoin-native DeFi becomes buildable without the trust compromises that plague current Bitcoin DeFi approaches. Bridged assets, wrapped tokens, and custodial intermediaries introduce risk at every layer. CAT tokens skip those layers entirely.&lt;/p&gt;

&lt;p&gt;Gaming economies with genuine digital scarcity where item ownership is verified by Bitcoin miners, not game company servers become architecturally sound rather than aspirational.&lt;/p&gt;

&lt;p&gt;Social applications where content ownership, reputation scores, and membership credentials are held as CAT tokens gain the same security properties as Bitcoin itself.&lt;/p&gt;

&lt;p&gt;The SPV compatibility of CAT tokens means mobile applications don’t require full node infrastructure to verify token authenticity. The verification path is the same one Bitcoin has used for light clients since Satoshi described it in the original whitepaper.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-World Trajectories&lt;/strong&gt;&lt;br&gt;
The applications closest to production viability are those that map most directly to existing financial infrastructure:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Decentralized exchanges&lt;/em&gt; are a natural first target. The guard architecture and contract-owned token model provide the core primitives needed for AMM pool contracts and token swaps. Developers building on CAT today are likely building DEX infrastructure.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Lending markets&lt;/em&gt; follow directly from the ability for contracts to hold collateral and enforce liquidation conditions. CAT20 tokens as collateral against BTC loans, with covenants enforcing the liquidation trigger, is technically within reach.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Prediction markets&lt;/em&gt; benefit from Bitcoin’s finality guarantees and the ability to encode outcome resolution logic in covenant contracts.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Cross-chain liquidity&lt;/em&gt; becomes more tractable with CAT’s trust-minimized bridge architecture. Moving assets between chains without custodial intermediaries, trusting only the chains themselves, is a qualitatively different security model than what most bridges offer today.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;NFT-based access systems&lt;/em&gt; where CAT721 token ownership gates content, services, or community membership benefit from the permanence of on-chain metadata. The access credential doesn’t expire because a server went offline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Horizon&lt;/strong&gt;&lt;br&gt;
Bitcoin has spent fifteen years as an extraordinarily reliable, extraordinarily conservative store of value. That conservatism is a feature, not a bug the protocol’s stability is precisely what makes it trustworthy.&lt;/p&gt;

&lt;p&gt;CAT Protocol doesn’t ask Bitcoin to become something else. It extends what Bitcoin already does UTXO validation, Script execution, proof-of-work consensus into the domain of programmable tokens and composable applications. The security guarantees don’t change. The trust model doesn’t change. What changes is the surface area of what you can build on top of it.&lt;/p&gt;

&lt;p&gt;The guard architecture enables fee optimization without sacrificing programmability. The contract-owned token model enables DeFi composability without trusting intermediaries. The covenant-enforced minting rules enable arbitrary issuance logic without indexer gatekeepers. The SPV compatibility enables mobile-native applications without full node infrastructure.&lt;/p&gt;

&lt;p&gt;Each of these is a solved problem in the CAT design. Not a roadmap item. Implemented, documented, and available to developers today.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
The most important question is no longer whether Bitcoin can support tokens and sophisticated applications. CAT Protocol demonstrates that the real question is how far Bitcoin programmability can go when token logic, ownership, and validation become native properties of the chain itself enforced by miners, verifiable by light clients, composable by any contract that cares to interact with them.&lt;/p&gt;

&lt;p&gt;Every UTXO with a CAT token in it is a programmable unit of value that inherits Bitcoin’s security guarantees and can be unlocked by covenant logic rather than just a private key. Every minter contract is a programmable policy engine that miners enforce without needing to understand token semantics. Every guard variant is a configurable transaction validator that optimizes for cost without sacrificing correctness.&lt;/p&gt;

&lt;p&gt;Bitcoin protocol engineering has a long history of doing more with less. CAT Protocol follows that tradition. The primitives are minimal. The implications are not.&lt;/p&gt;

&lt;p&gt;Technical references: &lt;a href="https://docs.opcatlabs.io/core-concepts/token-standards/overview" rel="noopener noreferrer"&gt;CAT Protocol Overview&lt;/a&gt; · &lt;a href="https://docs.opcatlabs.io/core-concepts/token-standards/cat20" rel="noopener noreferrer"&gt;CAT20 Specification&lt;/a&gt; · &lt;a href="https://docs.opcatlabs.io/core-concepts/token-standards/cat721" rel="noopener noreferrer"&gt;CAT721 Specification&lt;/a&gt; · &lt;a href="https://docs.opcatlabs.io/dapp-development/cat-token-integration/contract-owned-token" rel="noopener noreferrer"&gt;Contract-Owned Tokens&lt;/a&gt; · &lt;a href="https://docs.opcatlabs.io/dapp-development/cat-token-integration/guard-variants" rel="noopener noreferrer"&gt;Guard Variants&lt;/a&gt; · &lt;a href="https://docs.opcatlabs.io/dapp-development/cat-token-integration/SDK/overview" rel="noopener noreferrer"&gt;SDK Documentation&lt;/a&gt;&lt;/p&gt;

</description>
      <category>bitcoin</category>
      <category>opcat</category>
      <category>blockchain</category>
      <category>ai</category>
    </item>
    <item>
      <title>Bitcoin OP_CAT Use Cases Series #2: Merkle Trees</title>
      <dc:creator>OPCAT Maxi</dc:creator>
      <pubDate>Sun, 23 Jun 2024 07:25:35 +0000</pubDate>
      <link>https://dev.to/opcat/bitcoin-opcat-use-cases-series-2-merkle-trees-447c</link>
      <guid>https://dev.to/opcat/bitcoin-opcat-use-cases-series-2-merkle-trees-447c</guid>
      <description>&lt;p&gt;Following our &lt;a href="https://scryptplatform.medium.com/trustless-ordinal-sales-using-op-cat-enabled-covenants-on-bitcoin-0318052f02b2" rel="noopener noreferrer"&gt;series #1&lt;/a&gt;, we demonstrate how to construct and verify Merkle trees using OP_CAT.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpyuoojlly8tsedqu6k31.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpyuoojlly8tsedqu6k31.png" alt=" " width="720" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Bitcoin, Merkle trees are utilized as the data structure for verifying data, synchronization, and effectively linking the blockchain’s transactions and blocks together. The OP_CAT opcode, which allows for the concatenation of two stack variables, can be used with SHA256 hashes of public keys to streamline the Merkle tree verification process within Bitcoin Script. OP_CAT uniquely allows for the creation and opening of entries in Merkle trees, as the fundamental operation for building and verifying Merkle trees involves concatenating two values and then hashing them.&lt;/p&gt;

&lt;p&gt;There are numerous applications for Merkle trees. We list a few prominent examples below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Merkle proof&lt;/strong&gt;&lt;br&gt;
A Merkle proof is a cryptographic method used to verify that a specific transaction is included in a Merkle tree without needing to download the entire blockchain. This is particularly useful for lightweight clients and enhancing the efficiency of data verification.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxexjajmt2x41zgncivjd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxexjajmt2x41zgncivjd.png" alt=" " width="710" height="557"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Tree signature&lt;br&gt;
A &lt;a href="https://scryptplatform.medium.com/tree-signatures-8d03a8dd3077" rel="noopener noreferrer"&gt;tree signature&lt;/a&gt; is a cryptographic method that enhances the security and efficiency of digital signatures using tree structures, particularly Merkle trees. Compared to regular Multisig, this approach is used to generate a more compact and private proof that a message or a set of messages has been signed by a specific key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Zero-Knowledge Proof&lt;/strong&gt;&lt;br&gt;
STARK (Succinct Transparent Arguments of Knowledge) is a type of zero-knowledge proof system. STARKs are designed to allow a prover to demonstrate the validity of a computation to a verifier without revealing any sensitive information about the computation itself. If OP_CAT were to be added to Bitcoin, it could potentially enable the implementation of a &lt;a href="https://starkware.co/scaling-bitcoin-for-mass-use" rel="noopener noreferrer"&gt;STARK verifier&lt;/a&gt; in Bitcoin Script, with &lt;a href="https://github.com/Bitcoin-Wildlife-Sanctuary/bitcoin-circle-stark/" rel="noopener noreferrer"&gt;work already ongoing&lt;/a&gt;. This would allow for secure and private transactions on the Bitcoin network. Compared to pairing-based proof systems such as SNARK, STARK is considered to be &lt;a href="https://hackmd.io/@l2iterative/bitcoin-polyhedra" rel="noopener noreferrer"&gt;more Bitcoin-friendly&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;br&gt;
The implementation of the merkle tree using sCrypt is trivial. The following code calculates the root hash of a merkle tree, given a leaf and its merkle path, commonly used in verifying a merkle proof.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * According to the given leaf node and merkle path, calculate the hash of the root node of the merkle tree.
*/
@method()
static calcMerkleRoot(
    leaf: Sha256,
    merkleProof: MerkleProof
): Sha256 {
    let root = leaf

    for (let i = 0; i &amp;lt; MERKLE_PROOF_MAX_DEPTH; i++) {
        const node = merkleProof[i]
        if (node.pos != NodePos.Invalid) {
            // s is valid
            root =
                node.pos == NodePos.Left
                    ? Sha256(hash256(node.hash + root))
                    : Sha256(hash256(root + node.hash))
        }
    }

    return root
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Full code is at &lt;a href="https://github.com/sCrypt-Inc/scrypt-btc-merkle" rel="noopener noreferrer"&gt;https://github.com/sCrypt-Inc/scrypt-btc-merkle&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A single run results in the following transactions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Deploying Transaction ID:&lt;br&gt;
&lt;a href="https://mempool.space/signet/tx/c9c421b556458e0be9ec4043e1804d951011047b4cc75c991842b91b11bae006?source=post_page-----8e7c3f7afe8d--------------------------------" rel="noopener noreferrer"&gt;https://mempool.space/signet/tx/c9c421b556458e0be9ec4043e1804d951011047b4cc75c991842b91b11bae006?source=post_page-----8e7c3f7afe8d--------------------------------&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Spending Transaction ID:&lt;br&gt;
&lt;a href="https://mempool.space/signet/tx/e9ac5444d7d20a20011f6dcac04419e2c5581e79bf0692ccd2dc4bbb9bd74e28?source=post_page-----8e7c3f7afe8d--------------------------------" rel="noopener noreferrer"&gt;https://mempool.space/signet/tx/e9ac5444d7d20a20011f6dcac04419e2c5581e79bf0692ccd2dc4bbb9bd74e28?source=post_page-----8e7c3f7afe8d--------------------------------&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fycucsexc22zmbqn98dl7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fycucsexc22zmbqn98dl7.png" alt=" " width="488" height="1808"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Script versions&lt;/strong&gt;&lt;br&gt;
There are alternative implementations in bare scripts, like the one below. One significant advantage of using sCrypt for implementing merkle trees is its readability and maintainability. Scripts are often extremely hard to read and work on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OP_TOALTSTACK
OP_CAT
OP_CAT
OP_TOALTSTACK
OP_CAT
OP_TOALTSTACK

&amp;lt;0x8743daaedb34ef07d3296d279003603c45af71018431fd26e4957e772df122cb&amp;gt;
OP_CAT
OP_CAT
OP_HASH256

OP_DEPTH
OP_1SUB
OP_NOT
OP_NOTIF
OP_SWAP
OP_CAT
OP_CAT
OP_HASH256

OP_DEPTH
OP_1SUB
OP_NOT
OP_NOTIF
OP_SWAP
OP_CAT
OP_CAT
OP_HASH256

OP_DEPTH
OP_1SUB
OP_NOT
OP_NOTIF
OP_SWAP
OP_CAT
OP_CAT
OP_HASH256

OP_DEPTH
OP_1SUB
OP_NOT
OP_NOTIF
OP_SWAP
OP_CAT
OP_CAT
OP_HASH256

OP_DEPTH
OP_1SUB
OP_NOT
OP_NOTIF
OP_SWAP
OP_CAT
OP_CAT
OP_HASH256

...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stay tuned for more OP_CAT use cases.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Smart Contract Programming Languages: sCrypt vs. Solidity</title>
      <dc:creator>OPCAT Maxi</dc:creator>
      <pubDate>Fri, 05 Apr 2024 21:17:23 +0000</pubDate>
      <link>https://dev.to/opcat/smart-contract-programming-languages-scrypt-vs-solidity-57m3</link>
      <guid>https://dev.to/opcat/smart-contract-programming-languages-scrypt-vs-solidity-57m3</guid>
      <description>&lt;p&gt;This article offers a comparison between two Web3 smart contract programming languages, sCrypt and Solidity, to help you decide which one you should use for building smart contracts in the Bitcoin or Ethereum Virtual Machine ecosystems, respectively.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyrflqv2kik1zdxxrbidw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyrflqv2kik1zdxxrbidw.png" alt=" " width="720" height="508"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solidity&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://soliditylang.org/" rel="noopener noreferrer"&gt;Solidity&lt;/a&gt; emerged as the first-ever programming language for smart contracts and remains the most extensively utilized language in the Web3 space due to its first-mover advantage. It serves as the primary language for developing applications today on Ethereum and&lt;br&gt;
Ethereum Virtual Machine (EVM) compatible blockchains, including &lt;a href="https://www.bnbchain.org/en/bnb-smart-chain" rel="noopener noreferrer"&gt;Binance Smart Chain&lt;/a&gt; and &lt;a href="https://tron.network/" rel="noopener noreferrer"&gt;Tron&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;sCrypt&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://docs.scrypt.io/" rel="noopener noreferrer"&gt;sCrypt&lt;/a&gt; was developed with the aim of ensuring the utmost safety, security, and predictability in managing blockchain assets, while also equipping developers with the tools to create cutting-edge blockchain applications. Introduced 8 years following Solidity, sCrypt incorporated many lessons learned from the early years of Web3 application development, emphasizing the critical need for secure and reliable smart contracts. It is the primary smart contract language for &lt;a href="https://xiaohuiliu.medium.com/introduction-to-bitcoin-smart-contracts-9c0ea37dc757" rel="noopener noreferrer"&gt;Bitcoin Virtual Machine&lt;/a&gt; (BVM) based blockchains such as &lt;a href="https://xiaohuiliu.medium.com/introduce-scrypt-a-layer-1-smart-contract-framework-for-btc-b8b39c125c1a" rel="noopener noreferrer"&gt;BTC&lt;/a&gt;, &lt;a href="https://bitcoinsv.com/" rel="noopener noreferrer"&gt;BSV&lt;/a&gt;, and &lt;a href="https://www.microvisionchain.com/" rel="noopener noreferrer"&gt;MVC&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Overview: sCrypt vs. Solidity&lt;/strong&gt;&lt;br&gt;
Smart contracts control and manage billions of dollars’ worth of cryptocurrency and digital assets. Security flaws can lead to direct financial losses, particularly due to irreversible transactions and immutable code. Losses from hacks involving Solidity smart contracts have amounted to hundreds of millions of dollars over the years. These losses stem from a variety of vulnerabilities and attack vectors.&lt;/p&gt;

&lt;p&gt;The Ethereum community has made significant efforts to enable developers to create secure smart contracts by providing security guidelines and compiling information on known attacks and vulnerabilities. However, despite these efforts, security issues persist, largely because the Solidity language inherently permits these vulnerabilities. In contrast, sCrypt effectively eliminates many of these security flaws right from the start.&lt;/p&gt;

&lt;p&gt;sCrypt, being a modern language, learns from Solidity’s flaws. It adopts a distinctive approach in its design, focusing primarily on security and ensuring predictable behavior. The foundational principles of sCrypt were significantly influenced by analyzing prevalent Solidity vulnerabilities, leading to the development of a language specifically engineered with predictability and security as its primary objectives. sCrypt prioritizes security from the ground up. Its design was informed by a thorough review of the typical errors, vulnerabilities, and challenges encountered in smart contract development. The philosophy behind sCrypt emphasizes that if it’s possible to maintain functionality and expressiveness while greatly reducing the likelihood of human mistakes, such measures should be implemented at the language level.&lt;/p&gt;

&lt;p&gt;Establishing the right mental frameworks for smart contracts and blockchain systems is crucial: complexity introduces a higher likelihood of bugs, leading to further complexity in attempts to fix those bugs. This cycle can trap us in a continuously escalating complexity spiral, as witnessed in Solidity. Tackling these challenges at the programming language level can prevent this compounding complexity.&lt;/p&gt;

&lt;p&gt;Below is a high-level comparison between these two languages:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fveel7vstxk46t41plkqg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fveel7vstxk46t41plkqg.png" alt=" " width="720" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decidability&lt;/strong&gt;&lt;br&gt;
sCrypt is considered &lt;strong&gt;&lt;em&gt;decidable&lt;/em&gt;&lt;/strong&gt;, since an sCrypt smart contract always terminates and halts in a finite number of steps, for any given input. Put simply: it is guaranteed that sCrypt contract execution will end.&lt;/p&gt;

&lt;p&gt;Solidity supports unbounded loops, recursion, and dynamic function calls, which makes it impossible to decide if a Solidity smart contract will halt or not.&lt;/p&gt;

&lt;p&gt;sCrypt disallows unbounded loops and recursion at language level. Surprisingly, this is achieved &lt;strong&gt;&lt;em&gt;without sacrificing expressivity&lt;/em&gt;&lt;/strong&gt;, meaning &lt;a href="https://medium.com/coinmonks/turing-machine-on-bitcoin-7f0ebe0d52b1" rel="noopener noreferrer"&gt;Bitcoin smart contracts are still Turing-Complete&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The fact that sCrypt is decidable ensures that developers (and their tools) can more straightforwardly understand and accurately predict how sCrypt contracts will behave, no matter what the input is. In many situations, particularly with high-stakes transactions or critical systems, this predictability is highly valued.&lt;/p&gt;

&lt;p&gt;Decidability also allows for formal verification by complete static analysis of the entire call graph of a given smart contract. Formal verification is a popular method in security testing and auditing, using mathematical proofs to verify that specific properties of the contracts will consistently hold true or false under all conditions. Doing so to Solidity is incredibly difficult, due to the explosion of available paths.&lt;/p&gt;

&lt;p&gt;Reentrancy&lt;br&gt;
Reentrancy occurs when a smart contract makes a call to another contract, which then makes a call back to the original contract, effectively re-entering the initial logic. For instance, Contract A calls Contract B, waiting for a specific condition to be fulfilled before it updates its state. Meanwhile, Contract B calls back into Contract A. If your contract design isn’t meticulously crafted, reentrancy can cause your code to behave in unintended ways, whether due to a bug or as an exploit by a malicious entity. It could enable an attacker to execute multiple withdrawals before the contract updates its internal ledger, exposing the contract to various risks, including the potential for the total token balance to be siphoned off, as was infamously the case with &lt;a href="https://www.nytimes.com/2016/06/18/business/dealbook/hacker-may-have-removed-more-than-50-million-from-experimental-cybercurrency-project.html" rel="noopener noreferrer"&gt;the DAO hack&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Solidity permits reentrancy and has recently introduced an optional [&lt;em&gt;noReentrancy&lt;/em&gt;] guard that developers can choose to implement or not. Ultimately, the responsibility is on the developers to use this feature.&lt;/p&gt;

&lt;p&gt;In contrast, sCrypt does not permit reentrancy at all, eliminating this risk by design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Overflows and underflows&lt;/strong&gt;&lt;br&gt;
In Solidity, overflows occur when a calculation exceeds the maximum value that can be stored, while underflows happen when a calculation falls below the minimum value. Such events can throw smart contracts into chaos, and attackers may deliberately trigger them in contracts that are poorly coded. Typically, this results in the contract becoming inoperable or being depleted of its tokens.&lt;/p&gt;

&lt;p&gt;sCrypt guards against overflows and underflows by using only big numbers called &lt;strong&gt;&lt;em&gt;bigint&lt;/em&gt;&lt;/strong&gt;, a data type that can store integers with an arbitrarily large number of digits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learning Curve and Developer Tooling&lt;/strong&gt;&lt;br&gt;
sCrypt is an embedded Domain Specific Language (eDSL) based on TypeScript. It is strictly a subset of TypeScript, so all sCrypt code is valid TypeScript. &lt;a href="https://www.typescriptlang.org/" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; is chosen as the host language because it provides an easy, familiar language (JavaScript), but with type safety. There’s an abundance of learning materials available for TypeScript and thus sCrypt, including online tutorials, courses, documentation, and community support. This makes it relatively easy for beginners to start learning. It also has a vast ecosystem with numerous libraries and frameworks (e.g., React, Angular, Vue) that can simplify development and integration with Web2 applications.&lt;/p&gt;

&lt;p&gt;Solidity presents a steeper learning curve, especially for those new to blockchain concepts. It requires a solid understanding of specific security practices and the Ethereum ecosystem. While there are growing resources for learning Solidity, including official documentation, tutorials, and courses, the pool is orders of magnitudes smaller compared to TypeScript.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgudfk2n39djqepwhohy5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgudfk2n39djqepwhohy5.png" alt=" " width="720" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Debugging Solidity code can prove to be difficult because of the limited availability of advanced debugging tools. This limitation hampers the ability to diagnose and fix issues, particularly in the case of complex contracts. sCrypt, being TypeScript, enjoys many modern debuggers such as in Visual Studio Code. It is supported by any TypeScript IDEs, including Visual Studio Code, WebStorm, Vim and Atom.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffugifun0rst3utsk24wd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffugifun0rst3utsk24wd.png" alt=" " width="799" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pure&lt;/strong&gt;&lt;br&gt;
A pure function is a specific type of function that has the following characteristics:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;_Deterministic Output: _The output of a pure function is 
solely 
determined by its input values. Given the same input, a pure 
function will always return the same output.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Stateless:&lt;/em&gt; A pure function does not maintain or require any 
internal state to compute their output.&lt;/li&gt;
&lt;li&gt;_No Side Effects: _A pure function does not cause any 
observable side effects in the outside world. This means it 
does not modify any external state, global variables, or data 
outside its scope, nor does it depend on any external state.
Pure functions align closely with mathematical functions like 
quadratic (y=ax²+bx+c) or trigonometric (y=sin(x)). They 
allow for greater predictability, easier testing, and more 
efficient code optimization by compilers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All sCrypt functions declared as public are pure and boolean, evaluating to true or false. A function returning true will always return true, regardless of where, when, and how it is run. Its return is only determined by the calling transaction and arguments, which are both local. This means if a function is true when tested locally, it will be deemed true by miners when the enclosing transaction is broadcast. We do not even need to run a local node (e.g., &lt;em&gt;regtest&lt;/em&gt;) to test it, since &lt;a href="https://docs.scrypt.io/how-to-test-a-contract#run-tests" rel="noopener noreferrer"&gt;it can be evaluated without accessing a miner network&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In Solidity, functions are impure and capable of interacting with the blockchain through various actions, including reading from and altering the contract’s state, transferring ether, and invoking other contracts. The only exception is functions marked as pure. This impurity and unpredictability can make the code harder to test, debug, and reason about. Impure functions that alter contract states or perform transactions can be exploitable points for attackers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Postconditions&lt;/strong&gt;&lt;br&gt;
Postconditions in programming are conditions or predicates that must hold true immediately after the execution of a program or a specific block of code, such as a function or method. They are a key concept in the design by contract methodology, where they are used to specify and document the expected state of a system after a piece of code executes. Postconditions help in ensuring that a program behaves as expected and can be used for debugging, testing, and formal verification purposes.&lt;/p&gt;

&lt;p&gt;Let’s consider a function that increments a given number by one. To illustrate postconditions in JavaScript, a simple check is included after the function’s execution to ensure the postcondition holds true.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function incrementByOne(number) {
  const result = number + 1;
  return result;
}

// Function to check postcondition
function checkPostcondition(input, output) {
  if (output !== input + 1) {
    throw new Error('Postcondition failed: The output is not one greater than the input.');
  }
}

// Example usage
const inputNumber = 5;
const incrementedNumber = incrementByOne(inputNumber);

// Check the postcondition
checkPostcondition(inputNumber, incrementedNumber);

console.log('Incremented number:', incrementedNumber);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the context smart contract, postconditions protect developers and users from bugs and abuse.&lt;/p&gt;

&lt;p&gt;In sCrypt contracts with &lt;a href="https://docs.scrypt.io/how-to-write-a-contract/stateful-contract" rel="noopener noreferrer"&gt;state update&lt;/a&gt;, the new state has to be passed in when the calling transaction is constructed off chain, which is verified in the smart contract on chain. We are guaranteed the contract enters the expected and correct new state after the call.&lt;/p&gt;

&lt;p&gt;In Solidity, only the action of how a state is updated is specified. The new state is generally not passed in and one could only hope the contract is updated to the new expected state, making it unpredictable and error-prone.&lt;/p&gt;

&lt;p&gt;sCrypt verifies, while Solidity computes. The former is more secure and reliable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Composition over inheritance&lt;/strong&gt;&lt;br&gt;
sCrypt emphasizes using composition instead of inheritance. This approach implies that sCrypt smart contracts do not engage in inheritance as observed in languages such as Solidity. Consequently, there’s no need to navigate through intricate class hierarchies or deal with contracts that carry implicit behaviors from their ancestors. sCrypt mandates explicitness and deliberate composition in its design. Without the concept of inheritance, developers are required to clearly define the actions of their code. This characteristic enhances the predictability and transparency of contracts and simplifies the audit process.&lt;/p&gt;

</description>
      <category>scrypt</category>
      <category>solidity</category>
      <category>smartcontract</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>The Complete Guide to Full Stack Bitcoin SV Development</title>
      <dc:creator>OPCAT Maxi</dc:creator>
      <pubDate>Thu, 28 Mar 2024 17:09:25 +0000</pubDate>
      <link>https://dev.to/opcat/the-complete-guide-to-full-stack-bitcoin-sv-development-4o0l</link>
      <guid>https://dev.to/opcat/the-complete-guide-to-full-stack-bitcoin-sv-development-4o0l</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7tm5pvyc6z2gnte17j9i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7tm5pvyc6z2gnte17j9i.png" alt=" " width="720" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this guide, you’ll learn a web3 tech stack that will allow you to build full stack decentralized apps on the Bitcoin SV blockchain. We will walk through the entire process of building a full stack decentralized Tic-Tac-Toe, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write a smart contract.&lt;/li&gt;
&lt;li&gt;Deploy the contract&lt;/li&gt;
&lt;li&gt;Add a front-end (React)&lt;/li&gt;
&lt;li&gt;Integrate Yours wallet&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By the end, you will have a fully functional &lt;a href="https://scrypt.io/tic-tac-toe/" rel="noopener noreferrer"&gt;Tic-Tac-Toe&lt;/a&gt; App running on Bitcoin.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fthk87mdca6vvokpxxp7k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fthk87mdca6vvokpxxp7k.png" alt=" " width="720" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What we will use&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s go over the main pieces we will be using and how they fit into the stack.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1 - sCrypt Framework&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;sCrypt is a TypeScript framework to develop smart contracts on Bitcoin. It offers a complete tech stack:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.scrypt.io/" rel="noopener noreferrer"&gt;the sCrypt language&lt;/a&gt;: an embedded &lt;br&gt;
Domain Specific Language &lt;br&gt;
(eDSL) based on TypeScript, which allows developers to write &lt;br&gt;
smart contracts directly in TypeScript. Developers don’t have &lt;br&gt;
to learn a new Web3 programming language like Solidity, and can &lt;br&gt;
reuse their favorite tools, like IDEs and NPM.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.npmjs.com/package/scrypt-ts" rel="noopener noreferrer"&gt;library (scrypt-ts)&lt;/a&gt;: &lt;br&gt;
a comprehensive and concise library &lt;br&gt;
designed for client-side JavaScript applications, such as &lt;br&gt;
React, Vue, Angular, or Svelte, to interact with the Bitcoin SV &lt;br&gt;
Blockchain and its ecosystem.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/sCrypt-Inc/scrypt-cli" rel="noopener noreferrer"&gt;sCrypt CLI&lt;/a&gt;: CLI to &lt;br&gt;
easily create, compile and publish sCrypt &lt;br&gt;
projects. The CLI provides best practice project scaffolding.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Yours Wallet&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yours Wallet is an open-source digital wallet for BSV and &lt;a href="https://docs.1satordinals.com/" rel="noopener noreferrer"&gt;1Sat Ordinals&lt;/a&gt; that enables access to decentralized applications developed on &lt;a href="https://bitcoinsv.com/" rel="noopener noreferrer"&gt;Bitcoin SV&lt;/a&gt;. Yours Wallet generates and manages private keys for its users in a non-custodial manner, ensuring that the users have full control over their funds and transactions. These keys can be utilized within the wallet to securely store funds and authorize transactions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. React&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React.js, often simply referred to as React, is a JavaScript library developed by Facebook. It’s primarily used for building user interfaces (UIs) for web applications. It simplifies the process of building dynamic and interactive web applications and continues to be seemingly dominating the front-end space.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What we will Build&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We will build a very simple Tic-Tac-Toe game on chain. It uses the Bitcoin addresses of two players (Alice and Bob respectively) to initialize a smart contract. They each bet the same amount and lock it into the contract. The winner takes all bitcoins locked in the contract. If no one wins and there is a draw, the two players can each withdraw half of the money. Tic-Tac-Toe, the age-old game of strategy and skill, has now found its way onto the blockchain thanks to the power of sCrypt.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1 - Install &lt;a href="https://nodejs.org/en/download" rel="noopener noreferrer"&gt;node.js&lt;/a&gt; and npm (node.js ≥ version 16)&lt;br&gt;
2 - Install &lt;a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git" rel="noopener noreferrer"&gt;Git&lt;/a&gt;&lt;br&gt;
3 - &lt;a href="https://chromewebstore.google.com/detail/yours-wallet/mlbnicldlpdimbjdcncnklfempedeipj" rel="noopener noreferrer"&gt;Yours wallet&lt;/a&gt; Chrome extension installed in your browser&lt;br&gt;
4 - Install sCrypt CLI&lt;br&gt;
&lt;code&gt;npm install -g scrypt-cli&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s simply create a new React project.&lt;/p&gt;

&lt;p&gt;Firstly let’s create a new React project with TypeScript template.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx create-react-app tic-tac-toe --template typescript&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then, change the directory to the tic-tac-toe project directory and also run the &lt;code&gt;init&lt;/code&gt; command of the &lt;a href="https://docs.scrypt.io/installation#the-scrypt-cli-tool" rel="noopener noreferrer"&gt;CLI &lt;/a&gt;to add &lt;code&gt;sCrypt&lt;/code&gt; support in your project.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd tic-tac-toe&lt;br&gt;
npx scrypt-cli@latest init&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tic-tac-toe Contract&lt;/strong&gt;&lt;br&gt;
Next, let’s create a contract at &lt;code&gt;src/contracts/tictactoe.ts&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {
    prop, method, SmartContract, PubKey, FixedArray, assert, Sig, Utils, toByteString, hash160,
    hash256,
    fill,
    ContractTransaction,
    MethodCallOptions,
    bsv
} from "scrypt-ts";

export class TicTacToe extends SmartContract {
    @prop()
    alice: PubKey;
    @prop()
    bob: PubKey;
    @prop(true)
    isAliceTurn: boolean;
    @prop(true)
    board: FixedArray&amp;lt;bigint, 9&amp;gt;;
    static readonly EMPTY: bigint = 0n;
    static readonly ALICE: bigint = 1n;
    static readonly BOB: bigint = 2n;

    constructor(alice: PubKey, bob: PubKey) {
        super(...arguments)
        this.alice = alice;
        this.bob = bob;
        this.isAliceTurn = true;
        this.board = fill(TicTacToe.EMPTY, 9);
    }

    @method()
    public move(n: bigint, sig: Sig) {
        // check position `n`
        assert(n &amp;gt;= 0n &amp;amp;&amp;amp; n &amp;lt; 9n);
        // check signature `sig`
        let player: PubKey = this.isAliceTurn ? this.alice : this.bob;
        assert(this.checkSig(sig, player), `checkSig failed, pubkey: ${player}`);
        // update stateful properties to make the move
        assert(this.board[Number(n)] === TicTacToe.EMPTY, `board at position ${n} is not empty: ${this.board[Number(n)]}`);
        let play = this.isAliceTurn ? TicTacToe.ALICE : TicTacToe.BOB;
        this.board[Number(n)] = play;
        this.isAliceTurn = !this.isAliceTurn;

        // build the transation outputs
        let outputs = toByteString('');
        if (this.won(play)) {
            outputs = Utils.buildPublicKeyHashOutput(hash160(player), this.ctx.utxo.value);
        }
        else if (this.full()) {
            const halfAmount = this.ctx.utxo.value / 2n;
            const aliceOutput = Utils.buildPublicKeyHashOutput(hash160(this.alice), halfAmount);
            const bobOutput = Utils.buildPublicKeyHashOutput(hash160(this.bob), halfAmount);
            outputs = aliceOutput + bobOutput;
        }
        else {
            // build a output that contains latest contract state.
            outputs = this.buildStateOutput(this.ctx.utxo.value);
        }
        if (this.changeAmount &amp;gt; 0n) {
            outputs += this.buildChangeOutput();
        }
        // make sure the transaction contains the expected outputs built above
        assert(this.ctx.hashOutputs === hash256(outputs), "check hashOutputs failed");
    }

    @method()
    won(play: bigint): boolean {
        let lines: FixedArray&amp;lt;FixedArray&amp;lt;bigint, 3&amp;gt;, 8&amp;gt; = [
            [0n, 1n, 2n],
            [3n, 4n, 5n],
            [6n, 7n, 8n],
            [0n, 3n, 6n],
            [1n, 4n, 7n],
            [2n, 5n, 8n],
            [0n, 4n, 8n],
            [2n, 4n, 6n]
        ];
        let anyLine = false;
        for (let i = 0; i &amp;lt; 8; i++) {
            let line = true;
            for (let j = 0; j &amp;lt; 3; j++) {
                line = line &amp;amp;&amp;amp; this.board[Number(lines[i][j])] === play;
            }
            anyLine = anyLine || line;
        }
        return anyLine;
    }

    @method()
    full(): boolean {
        let full = true;
        for (let i = 0; i &amp;lt; 9; i++) {
            full = full &amp;amp;&amp;amp; this.board[i] !== TicTacToe.EMPTY;
        }
        return full;
    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Properties&lt;/strong&gt;&lt;br&gt;
The Tic-Tac-Toe contract features several essential properties that define its functionality:&lt;/p&gt;

&lt;p&gt;1 - &lt;strong&gt;Alice and Bob&lt;/strong&gt;: Public keys of the two players.&lt;br&gt;
2 - &lt;strong&gt;is_alice_turn&lt;/strong&gt;: A boolean flag indicating whose turn it is &lt;br&gt;
     to play.&lt;br&gt;
3 - &lt;strong&gt;board&lt;/strong&gt;: A representation of the game board, stored as a &lt;br&gt;
     fixed-size array.&lt;br&gt;
4 - &lt;strong&gt;Constants&lt;/strong&gt;: Three static properties defining game symbols &lt;br&gt;
    and empty squares.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constructor&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;constructor(alice: PubKey, bob: PubKey) {
        super(...arguments)
        this.alice = alice;
        this.bob = bob;
        this.isAliceTurn = true;
        this.board = fill(TicTacToe.EMPTY, 9);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Upon deployment, the constructor initializes the contract with the public keys of Alice and Bob. Additionally, it sets up an empty game board to kickstart the game play.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Public methods&lt;/strong&gt;&lt;br&gt;
Each contract must have at least one public &lt;code&gt;@method&lt;/code&gt;. It is denoted with the &lt;code&gt;public&lt;/code&gt; modifier and does not return any value. It is visible outside the contract and acts as the main method into the contract (like &lt;code&gt;main&lt;/code&gt; in C and Java).&lt;/p&gt;

&lt;p&gt;The public method in the contract is &lt;code&gt;move()&lt;/code&gt;, which allows players to make their moves on the board. This method validates the moves, checks the player's signature, updates the game state, and determines the outcome of the game.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Signature verification&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once the game contract is deployed, anyone can view and potentially interact with it. We need an authentication mechanism to ensure only the desired player can update the contract if it’s their turn. This is achieved using ditigal signatures.&lt;/p&gt;

&lt;p&gt;Only the authorized player can make a move during their turn, validated through their respective public key stored in the contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// check signature `sig`
let player: PubKey = this.isAliceTurn ? this.alice : this.bob;
assert(this.checkSig(sig, player), `checkSig failed, pubkey: ${player}`);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Non-Public methods&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The contract includes two non-public methods, &lt;code&gt;won()&lt;/code&gt; and &lt;code&gt;full()&lt;/code&gt;, responsible for determining whether a player has won the game and if the board is full, leading to a draw.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tx Builder: buildTxForMove&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Bitcoin transaction can have multiple inputs and outputs. We need to build a transaction when calling a contract.&lt;/p&gt;

&lt;p&gt;Here, we have implement a &lt;a href="https://docs.scrypt.io/how-to-deploy-and-call-a-contract/how-to-customize-a-contract-tx" rel="noopener noreferrer"&gt;customize transaction&lt;/a&gt; builder for the move() method as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;static buildTxForMove(
    current: TicTacToe,
    options: MethodCallOptions&amp;lt;TicTacToe&amp;gt;,
    n: bigint
  ): Promise&amp;lt;ContractTransaction&amp;gt; {
    const play = current.isAliceTurn ? TicTacToe.ALICE : TicTacToe.BOB;
    const nextInstance = current.next();
    nextInstance.board[Number(n)] = play;
    nextInstance.isAliceTurn = !current.isAliceTurn;
    const unsignedTx: bsv.Transaction = new bsv.Transaction().addInput(
      current.buildContractInput(options.fromUTXO)
    );
    if (nextInstance.won(play)) {
      const script = Utils.buildPublicKeyHashScript(
        hash160(current.isAliceTurn ? current.alice : current.bob)
      );
      unsignedTx.addOutput(
        new bsv.Transaction.Output({
          script: bsv.Script.fromHex(script),
          satoshis: current.balance,
        })
      );
      if (options.changeAddress) {
        unsignedTx.change(options.changeAddress);
      }
      return Promise.resolve({
        tx: unsignedTx,
        atInputIndex: 0,
        nexts: [],
      });
    }
    if (nextInstance.full()) {
      const halfAmount = current.balance / 2;
      unsignedTx
        .addOutput(
          new bsv.Transaction.Output({
            script: bsv.Script.fromHex(
              Utils.buildPublicKeyHashScript(hash160(current.alice))
            ),
            satoshis: halfAmount,
          })
        )
        .addOutput(
          new bsv.Transaction.Output({
            script: bsv.Script.fromHex(
              Utils.buildPublicKeyHashScript(hash160(current.bob))
            ),
            satoshis: halfAmount,
          })
        );
      if (options.changeAddress) {
        unsignedTx.change(options.changeAddress);
      }
      return Promise.resolve({
        tx: unsignedTx,
        atInputIndex: 0,
        nexts: [],
      });
    }
    unsignedTx.setOutput(0, () =&amp;gt; {
      return new bsv.Transaction.Output({
        script: nextInstance.lockingScript,
        satoshis: current.balance,
      });
    });
    if (options.changeAddress) {
      unsignedTx.change(options.changeAddress);
    }
    const nexts = [
      {
        instance: nextInstance,
        atOutputIndex: 0,
        balance: current.balance,
      },
    ];
    return Promise.resolve({
      tx: unsignedTx,
      atInputIndex: 0,
      nexts,
      next: nexts[0],
    });
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Integrate Front-end (React)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After we have written/tested our contract, we can integrate it with front-end so that users can play our game.&lt;/p&gt;

&lt;p&gt;First, let’s compile the contract and get the contract artifact json file by running the command below :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx scrypt-cli@latest compile&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feokg204zc8uyse41z7tw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feokg204zc8uyse41z7tw.png" alt=" " width="720" height="197"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should see an artifact file &lt;code&gt;tictactoe.json&lt;/code&gt; in the &lt;code&gt;artifacts&lt;/code&gt; directory. It can be used to initialize a contract at the front end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { TicTacToe } from './contracts/tictactoe';
import artifact from '../artifacts/tictactoe.json';

TicTacToe.loadArtifact(artifact);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Install and Fund Wallet&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before deploying a contract, we need to connect a wallet first. We use &lt;a href="https://chromewebstore.google.com/detail/panda-wallet/mlbnicldlpdimbjdcncnklfempedeipj" rel="noopener noreferrer"&gt;Yours Wallet&lt;/a&gt;, a MetaMask-like wallet.&lt;/p&gt;

&lt;p&gt;After installing the wallet, click the &lt;code&gt;settings&lt;/code&gt; button in the upper right corner to switch to testnet. Then copy your wallet address and go to our &lt;a href="https://scrypt.io/#faucet" rel="noopener noreferrer"&gt;faucet &lt;/a&gt;to fund it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwofo7au1rjo5w4819fdi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwofo7au1rjo5w4819fdi.png" alt=" " width="720" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Connect to wallet&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We call &lt;code&gt;requestAuth()&lt;/code&gt; to request to connect to the wallet. If the request is approved by the user, we now have full access to the wallet. We can, for example, call &lt;code&gt;getDefaultPubKey()&lt;/code&gt; to get its public key.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const walletLogin = async () =&amp;gt; {
    try {
      const provider = new DefaultProvider({
          network: bsv.Networks.testnet
      });
      const signer = new PandaSigner(provider);
      signerRef.current = signer;

      const { isAuthenticated, error } = await signer.requestAuth()
      if (!isAuthenticated) {
        throw new Error(error)
      }
      setConnected(true);
      const alicPubkey = await signer.getDefaultPubKey();
      setAlicePubkey(toHex(alicPubkey))
      // Prompt user to switch accounts
    } catch (error) {
      console.error("pandaLogin failed", error);
      alert("pandaLogin failed")
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Initialize the contract&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We have obtained the contract class &lt;code&gt;Tictactoe&lt;/code&gt; by loading the contract artifact file. When a user clicks the start button, the contract is initialized with the public keys of two players &lt;code&gt;alice&lt;/code&gt; and &lt;code&gt;bob&lt;/code&gt;. The public key can be obtained through calling &lt;code&gt;getDefaultPubKey()&lt;/code&gt; of &lt;code&gt;Signer&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The following code initializes the contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [alicePubkey, setAlicePubkey] = useState("");
const [bobPubkey, setBobPubkey] = useState("");
...
const startGame = async (amount: number) =&amp;gt; {
  try {
    const signer = signerRef.current as PandaSigner;
    const instance = new TicTacToe(
        PubKey(toHex(alicePubkey)),
        PubKey(toHex(bobPubkey))
      );
    await instance.connect(signer);

  } catch(e) {
    console.error('deploy TicTacToe failes', e)
    alert('deploy TicTacToe failes')
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Call the contract&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we can start playing the game. Every move is a call to the contract and triggers a change in the state of the contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { tx: callTx } = await p2pkh.methods.unlock(
    (sigResponses: SignatureResponse[]) =&amp;gt; findSig(sigResponses, $publickey),
    $publickey,
    {
        pubKeyOrAddrToSign: $publickey.toAddress()
    } as MethodCallOptions&amp;lt;P2PKH&amp;gt;
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After finishing with the front-end you can simply run :&lt;br&gt;
&lt;code&gt;npm start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can now view it at &lt;code&gt;http://localhost:3000/&lt;/code&gt; in your browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flngrx7slzrxzh7hmha0h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flngrx7slzrxzh7hmha0h.png" alt=" " width="600" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Congratulations! You have just built your first full stack dApp on Bitcoin. Now you can play &lt;a href="https://scrypt.io/tic-tac-toe/" rel="noopener noreferrer"&gt;tic-tac-toe&lt;/a&gt; or build your favorite game on Bitcoin. Now would be a good time to pop some champagne if you haven’t already :).&lt;/p&gt;

&lt;p&gt;One session of play can be viewed here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/l65Ha5AmKjk" rel="noopener noreferrer"&gt;https://youtu.be/l65Ha5AmKjk&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All the code can be found at &lt;a href="https://github.com/sCrypt-Inc/tic-tac-toe" rel="noopener noreferrer"&gt;this github repo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;By default, we deploy the contract on testnet. You can easily change it to mainnet.&lt;/p&gt;

</description>
      <category>scrypt</category>
      <category>smartcontract</category>
      <category>blockchain</category>
      <category>bitcoin</category>
    </item>
    <item>
      <title>How to Become a BSV Blockchain Developer in 2024</title>
      <dc:creator>OPCAT Maxi</dc:creator>
      <pubDate>Thu, 28 Mar 2024 16:16:59 +0000</pubDate>
      <link>https://dev.to/opcat/how-to-become-a-bsv-blockchain-developer-in-2024-6ol</link>
      <guid>https://dev.to/opcat/how-to-become-a-bsv-blockchain-developer-in-2024-6ol</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F78e29m32cvn6nblcwons.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F78e29m32cvn6nblcwons.png" alt=" " width="720" height="355"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this rapidly growth of blockchain technology, developers play a pivotal role in shaping the future of decentralized systems. Among all the blockchain platforms, Bitcoin SV (BSV) stands out as a powerful Blockchain offering scalability, security, and stability. As we venture into 2024, the demand for skilled BSV blockchain developers continues to surge. If you’re excited and ready to dive into this exciting field, this comprehensive guide will show you the path to become a proficient BSV blockchain developer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding the BSV Ecosystem:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before delving into the specifics of BSV development, it’s essential to grasp the fundamentals of the BSV ecosystem. BSV, short for Bitcoin Satoshi Vision, emerged as a result of a contentious hard fork from the Bitcoin Cash (BCH) blockchain. It upholds the original vision outlined in Satoshi Nakamoto’s whitepaper, emphasizing large block sizes and low fees to enable scalable transactions and data storage so that enterprises application can be build on top of blockchain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understand Basics :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://bitcoinsv.academy/course/bitcoin-theory" rel="noopener noreferrer"&gt;BSV Academy&lt;/a&gt; - Bitcoin Theory Bitcoin Theory covers the design of Bitcoin as a system as prescribed by Satoshi Nakamoto.&lt;br&gt;
&lt;a href="https://bitcoinsv.academy/bitcoin-essentials" rel="noopener noreferrer"&gt;BSV Academy&lt;/a&gt; - Bitcoin Essentials Bitcoin essentials covers Hash Functions, Merkle tree, Digital Signatures e.t.c.&lt;br&gt;
&lt;a href="//www.learnmeabitcoin.com"&gt;Learnmeabitcoin&lt;/a&gt; - A very useful and comprehensive resources to understand how bitcoin (bsv) actually work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Smart Contracts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="//scrypt.io"&gt;sCrypt&lt;/a&gt; : sCrypt is an embedded Domain Specific Language (eDSL) based on TypeScript for writing smart contracts on Bitcoin SV. sCrypt is very powerful as Smart contracts on Bitcoin are based on the UTXO model, which makes bsv blockchain scale.&lt;br&gt;
&lt;a href="//docs.scrypt.io"&gt;docs&lt;/a&gt; : A comprehensive documentation to learn sCrypt.&lt;br&gt;
&lt;a href="https://github.com/sCrypt-Inc/boilerplate" rel="noopener noreferrer"&gt;Boilerplate&lt;/a&gt; : Sample sCrypt Smart Contract codes along with tests with dozens of contract written already.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Developer Resources&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A list of resources, tools, libraries, and projects related to the Bitcoin SV can be found &lt;a href="https://github.com/yusufidimaina9989/BSV_Developer_Resources" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Below are some of the resources :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/sCrypt-Inc/scrypt-ord" rel="noopener noreferrer"&gt;sCrypt - ord&lt;/a&gt; : 1sat Ordinals library&lt;br&gt;
&lt;a href="https://www.twostack.org/products" rel="noopener noreferrer"&gt;DartSV&lt;/a&gt; : A dart library for interacting with bitcoin network.&lt;br&gt;
&lt;a href="https://coingeek.com/how-junglebus-indexes-bitcoin-internet-of-value-workshop/" rel="noopener noreferrer"&gt;JungleBus&lt;/a&gt; : is a powerful, low-level indexer to power lightweight Bitcoin data sets.&lt;br&gt;
&lt;a href="https://www.youtube.com/@bitcoinclasswithsatoshi7988/videos" rel="noopener noreferrer"&gt;Bitcoin class with satoshi&lt;/a&gt; : A very useful youtube channel to learn sCrypt.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Communities&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://t.me/scryptbitcoin" rel="noopener noreferrer"&gt;Telegram&lt;/a&gt;&lt;br&gt;
&lt;a href="https://discord.gg/bsv" rel="noopener noreferrer"&gt;Discord&lt;/a&gt;&lt;br&gt;
&lt;a href="https://join.slack.com/t/scryptworkspace/shared_invite/zt-1zeoorxyt-zggK4fGc31swt94~1X7M8w" rel="noopener noreferrer"&gt;Slack&lt;/a&gt;&lt;br&gt;
&lt;a href="https://twitter.com/sCryptPlatform" rel="noopener noreferrer"&gt;X(twitter)&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.reddit.com/r/sCrypt" rel="noopener noreferrer"&gt;Reddit&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Continuous Learning:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The field of blockchain technology evolves at a rapid pace, necessitating a commitment to lifelong learning. Engage with the BSV community through forums, meetups, and online resources to stay updated on industry trends.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Career and Opportunities:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As a BSV blockchain developer, you’ll find a wealth of career opportunities across various sectors in the eco - system. Whether you aspire to work for established enterprises, startups, or embark on entrepreneurial ventures, the demand for BSV expertise continues to grow exponentially.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.bsvblockchain.org/blockchain-jobs" rel="noopener noreferrer"&gt;Bsv blockchain jobs&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Becoming a proficient BSV blockchain developer requires dedication, curiosity, and a willingness to continue learning. By mastering sCrypt, leveraging BSV libraries and frameworks, and staying informed about the latest protocols and tools, you’ll position yourself as a valuable asset in the blockchain industry. As we navigate the transformative landscape of decentralized technology, seize the opportunity to leave your mark as a skilled BSV blockchain developer in 2024 and beyond.&lt;/p&gt;

&lt;p&gt;Tag me if you build something great.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
