<?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: sCrypt</title>
    <description>The latest articles on DEV Community by sCrypt (@scrypt).</description>
    <link>https://dev.to/scrypt</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1379475%2Fae960e9b-ae85-46bb-88e1-6b3dfa2f6fe4.png</url>
      <title>DEV Community: sCrypt</title>
      <link>https://dev.to/scrypt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/scrypt"/>
    <language>en</language>
    <item>
      <title>Bitcoin OP_CAT Use Cases Series #2: Merkle Trees</title>
      <dc:creator>sCrypt</dc:creator>
      <pubDate>Sun, 23 Jun 2024 07:25:35 +0000</pubDate>
      <link>https://dev.to/scrypt/bitcoin-opcat-use-cases-series-2-merkle-trees-447c</link>
      <guid>https://dev.to/scrypt/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"&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://media.dev.to/cdn-cgi/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://media.dev.to/cdn-cgi/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="Image description" 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://media.dev.to/cdn-cgi/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://media.dev.to/cdn-cgi/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="Image description" 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"&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"&gt;STARK verifier&lt;/a&gt; in Bitcoin Script, with &lt;a href="https://github.com/Bitcoin-Wildlife-Sanctuary/bitcoin-circle-stark/"&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"&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"&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--------------------------------"&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--------------------------------"&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://media.dev.to/cdn-cgi/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://media.dev.to/cdn-cgi/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="Image description" 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>sCrypt</dc:creator>
      <pubDate>Fri, 05 Apr 2024 21:17:23 +0000</pubDate>
      <link>https://dev.to/scrypt/smart-contract-programming-languages-scrypt-vs-solidity-57m3</link>
      <guid>https://dev.to/scrypt/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://media.dev.to/cdn-cgi/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://media.dev.to/cdn-cgi/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="Image description" 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/"&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"&gt;Binance Smart Chain&lt;/a&gt; and &lt;a href="https://tron.network/"&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/"&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"&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"&gt;BTC&lt;/a&gt;, &lt;a href="https://bitcoinsv.com/"&gt;BSV&lt;/a&gt;, and &lt;a href="https://www.microvisionchain.com/"&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://media.dev.to/cdn-cgi/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://media.dev.to/cdn-cgi/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="Image description" 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"&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"&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/"&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://media.dev.to/cdn-cgi/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://media.dev.to/cdn-cgi/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="Image description" 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://media.dev.to/cdn-cgi/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://media.dev.to/cdn-cgi/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="Image description" width="800" 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"&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"&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>sCrypt</dc:creator>
      <pubDate>Thu, 28 Mar 2024 17:09:25 +0000</pubDate>
      <link>https://dev.to/scrypt/the-complete-guide-to-full-stack-bitcoin-sv-development-4o0l</link>
      <guid>https://dev.to/scrypt/the-complete-guide-to-full-stack-bitcoin-sv-development-4o0l</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/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://media.dev.to/cdn-cgi/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="Image description" 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/"&gt;Tic-Tac-Toe&lt;/a&gt; App running on Bitcoin.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/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://media.dev.to/cdn-cgi/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="Image description" 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/"&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"&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"&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/"&gt;1Sat Ordinals&lt;/a&gt; that enables access to decentralized applications developed on &lt;a href="https://bitcoinsv.com/"&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"&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"&gt;Git&lt;/a&gt;&lt;br&gt;
3 - &lt;a href="https://chromewebstore.google.com/detail/yours-wallet/mlbnicldlpdimbjdcncnklfempedeipj"&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"&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"&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://media.dev.to/cdn-cgi/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://media.dev.to/cdn-cgi/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="Image description" 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"&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"&gt;faucet &lt;/a&gt;to fund it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/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://media.dev.to/cdn-cgi/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="Image description" 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://media.dev.to/cdn-cgi/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://media.dev.to/cdn-cgi/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="Image description" 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/"&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"&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"&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>sCrypt</dc:creator>
      <pubDate>Thu, 28 Mar 2024 16:16:59 +0000</pubDate>
      <link>https://dev.to/scrypt/how-to-become-a-bsv-blockchain-developer-in-2024-6ol</link>
      <guid>https://dev.to/scrypt/how-to-become-a-bsv-blockchain-developer-in-2024-6ol</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/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://media.dev.to/cdn-cgi/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="Image description" 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"&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"&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"&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"&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"&gt;sCrypt - ord&lt;/a&gt; : 1sat Ordinals library&lt;br&gt;
&lt;a href="https://www.twostack.org/products"&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/"&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"&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"&gt;Telegram&lt;/a&gt;&lt;br&gt;
&lt;a href="https://discord.gg/bsv"&gt;Discord&lt;/a&gt;&lt;br&gt;
&lt;a href="https://join.slack.com/t/scryptworkspace/shared_invite/zt-1zeoorxyt-zggK4fGc31swt94~1X7M8w"&gt;Slack&lt;/a&gt;&lt;br&gt;
&lt;a href="https://twitter.com/sCryptPlatform"&gt;X(twitter)&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.reddit.com/r/sCrypt"&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"&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>
