The complete guide to full stack BSV blockchain development – CoinGeek
This post was first published onMedium.
In this guide, youll 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:
By the end, you will have a fully functionalTic-Tac-Toe Apprunning on Bitcoin.
What we will use
Lets go over the main pieces we will be using and how they fit into the stack.
1. sCrypt Framework
sCrypt is a TypeScript framework to develop smart contracts on Bitcoin. It offers a complete tech stack:
2. Yours Wallet
Yours Walletis an open-source digital wallet for BSV and1Sat Ordinalsthat enables access to decentralized applications developed onBitcoin SV. 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.
3. React
React.js, often simply referred to as React, is a JavaScript library developed by Facebook. Its 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.
What we will Build
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.
Prerequisites
Getting Started
Lets simply create a new React project.
Firstly lets create a new React project with TypeScript template.
Then, change the directory to the tic-tac-toe project directory and also run theinitcommand of theCLIto addsCryptsupport in your project.
Tic-tac-toe Contract
Next, lets create a contract atsrc/contracts/tictactoe.ts:
Properties
The Tic-Tac-Toe contract features several essential properties that define its functionality:
Constructor
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.
Public methods
Each contract must have at least one public@method. It is denoted with thepublicmodifier and does not return any value. It is visible outside the contract and acts as the main method into the contract (likemainin C and Java).
The public method in the contract ismove(), which allows players to make their moves on the board. This method validates the moves, checks the players signature, updates the game state, and determines the outcome of the game.
Signature verification
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 its their turn. This is achieved using digital signatures.
Only the authorized player can make a move during their turn, validated through their respective public key stored in the contract.
Non-Public methods
The contract includes two non-public methods,won()andfull(), responsible for determining whether a player has won the game and if the board is full, leading to a draw.
Tx Builder: buildTxForMove
Bitcoin transaction can have multiple inputs and outputs. We need to build a transaction when calling a contract.
Here, we have implement acustomize transactionbuilder for themove()method as below:
Integrate Front-end (React)
After we have written/tested our contract, we can integrate it with front-end so that users can play our game.
First, lets compile the contract and get the contract artifact json file by running the command below:
You should see an artifact filetictactoe.jsonin theartifactsdirectory. It can be used to initialize a contract at the front end.
Install and Fund Wallet
Before deploying a contract, we need to connect a wallet first. We useYours Wallet, a MetaMask-like wallet.
After installing the wallet, click thesettingsbutton in the upper right corner to switch to testnet. Then copy your wallet address and go to ourfaucetto fund it.
Connect to wallet
We callrequestAuth()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, callgetDefaultPubKey()to get its public key.
Initialize the contract
We have obtained the contract classTictactoe by loading the contract artifact file. When a user clicks thestartbutton, the contract is initialized with the public keys of two playersaliceandbob. The public key can be obtained through callingetDefaultPubKey()ofSigner.
The following code initializes the contract.
Call the contract
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.
After finishing with the front-end you can simply run :
You can now view it at `http://localhost:3000/` in your browser.
Conclusion
Congratulations! You have just built your first full stack dApp on Bitcoin. Now you can playtic-tac-toeor build your favorite game on Bitcoin. Now would be a good time to pop some champagne if you havent already :).
One session of play can be viewed here:
All the code can be found atthis github repo.
By default, we deploy the contract on testnet. You can easily change it to mainnet.
Watch: sCrypt Hackathon 2024 (17th March 2024, PM)
New to blockchain? Check out CoinGeeks Blockchain for Beginners section, the ultimate resource guide to learn more about blockchain technology.
More:
The complete guide to full stack BSV blockchain development - CoinGeek
- Court Rules OFAC Exceeded Authority in Sanctioning Tornado Cash Smart Contracts - Lawyer Monthly Magazine - November 28th, 2024 [November 28th, 2024]
- Fifth Circuit Rules OFAC Overstepped in Sanctioning Tornado Cash's Immutable Smart Contracts - Decrypt - November 26th, 2024 [November 26th, 2024]
- Ethereum Time Machine: A New Era for Smart Contracts and Future-Based Transactions - Crypto News Flash - November 16th, 2024 [November 16th, 2024]
- Ethereum researcher unveils time machine for even smarter, smart contracts - StartupNews.fyi - November 16th, 2024 [November 16th, 2024]
- FlexiNetAI Is Disrupting Blockchain Space With Innovative Smart Contracts - StreetInsider.com - November 2nd, 2024 [November 2nd, 2024]
- From Code to Intelligence: How Yeager.ai is Building Internet-Native Smart Contracts - hackernoon.com - November 2nd, 2024 [November 2nd, 2024]
- Smart Contracts Platforms Market Poised for Explosive Growth, Reaching $230.4 Billion by 2032 - openPR - October 23rd, 2024 [October 23rd, 2024]
- Healthcare Smart Contracts Market Business Insights, Key Trend Analysis - News in Assen - October 7th, 2024 [October 7th, 2024]
- From Court to Code: Smart Contracts and Arbitration - JD Supra - September 21st, 2024 [September 21st, 2024]
- VeChain CEO Says Incentivizing EV Drivers For Reducing C02 Emissions Is "Very Cheap" Because Of Smart contracts - 99Bitcoins - September 21st, 2024 [September 21st, 2024]
- How Smart Contracts are Reinventing the Gaming Experience - SMEStreet - September 21st, 2024 [September 21st, 2024]
- W3.io Launches Industry Alliance to Develop the First Orchestration Cloud for Smart Contracts - Decrypt - September 19th, 2024 [September 19th, 2024]
- Smart Contracts Market: Enabling Secure and Automated Transactions - openPR - September 19th, 2024 [September 19th, 2024]
- How Smart Contracts are Enhancing Trust in Crypto-Based Gambling Platforms - UseTheBitcoin - September 19th, 2024 [September 19th, 2024]
- Meticulous Research Projects the Smart Contracts Market to Reach $8.7 Billion by 2031 - openPR - September 19th, 2024 [September 19th, 2024]
- Smart Contracts: where are we now and does AI have a role to play? - Travers Smith - September 10th, 2024 [September 10th, 2024]
- Friend.tech's FRIEND token tanks to record low as team abandons control of smart contracts - Crypto Briefing - September 10th, 2024 [September 10th, 2024]
- Friend.Tech Faces Uncertain Future After Transferring Control of Smart Contracts - BSC News - September 10th, 2024 [September 10th, 2024]
- Ripples Vision: Native Smart Contracts on XRPL Mainnet and Launching the XRPL EVM Sidechain - CryptoGlobe - September 6th, 2024 [September 6th, 2024]
- Ripple Will Support Ethereum Compatible Smart Contracts Soon - Live Bitcoin News - September 6th, 2024 [September 6th, 2024]
- Smart Contracts On The XRP Ledger, Ripples Change Of Heart Worries Community | Bitcoinist.com - Bitcoinist - September 6th, 2024 [September 6th, 2024]
- Ripple to bring smart contracts on XRP Ledger - crypto.news - September 6th, 2024 [September 6th, 2024]
- Ripple to Add Ethereum-Compatible Smart Contracts to XRP Ledger - Cryptonews - September 6th, 2024 [September 6th, 2024]
- Ripple to Add Ethereum Smart Contracts to its XRP Ledger - Watcher Guru - September 6th, 2024 [September 6th, 2024]
- Flare Labs CEO Says Smart Contracts on XRP Ledger Will Make FXRP Even Better - The Crypto Basic - September 6th, 2024 [September 6th, 2024]
- Ripple Introduces Smart Contracts and Innovative NFT Features to the XRP Ledger - Crypto News Flash - September 6th, 2024 [September 6th, 2024]
- Tensions Rise in XRP Community as Ripple Reverses Stance on XRPL Smart Contracts - The Crypto Basic - September 6th, 2024 [September 6th, 2024]
- XRP Ledger set to gain smart contracts and EVM Sidechain - CryptoTvplus - September 6th, 2024 [September 6th, 2024]
- XRP to Moon: Ripple To Expand XRP Ledger with Ethereum-Compatible Smart Contracts - Coinpedia Fintech News - September 6th, 2024 [September 6th, 2024]
- Ripple Announces Smart Contracts for XRP Ledger, Expanding Features for NFTs, AMMs, and DEXs - BSC News - September 6th, 2024 [September 6th, 2024]
- Ripple To Add Ethereum Smart Contracts To XRP Ledger By yolowire.com - Investing.com Canada - September 6th, 2024 [September 6th, 2024]
- Ripple to Enhance XRP Ledger with Ethereum-Compatible Smart Contracts - Crypto News Australia - September 6th, 2024 [September 6th, 2024]
- Ripple to launch smart contracts on XRP Ledger (XRPL), boosting DeFi capabilities and DApps - Invezz - September 6th, 2024 [September 6th, 2024]
- Soroban: Unlocking DeFi Opportunities with Smart Contracts on Stellar - The Defiant - DeFi News - August 20th, 2024 [August 20th, 2024]
- How Are Smart Contracts Different From DApps: Top 5 Amazing Examples Of Each - Blockchain Magazine - August 20th, 2024 [August 20th, 2024]
- Bitcoin Sidechains: CertiK Shares Insights on Clarity Smart Contracts which Are Utilized By Stacks Chain - Crowdfund Insider - August 16th, 2024 [August 16th, 2024]
- Blockchain Currencys Role in the Evolution of Smart Contracts - NFL Draft Diamonds - August 16th, 2024 [August 16th, 2024]
- How to Bridge to Internet Computer? - Watcher Guru - July 15th, 2024 [July 15th, 2024]
- Why (Almost) Everyone in Ethereum Is So Excited About a Wallet-Related Proposal - Unchained - Unchained - April 13th, 2024 [April 13th, 2024]
- Ethereum's Pectra upgrade slated for Q4 2024, bringing smart contract features and improved UX for wallets - Crypto Briefing - April 13th, 2024 [April 13th, 2024]
- Ethereum's Pectra upgrade to make normal wallets 'smart' and improve UX - Cointelegraph - April 13th, 2024 [April 13th, 2024]
- Ex-Amazon engineer sentenced to 3 years in prison for $12m crypto hack - crypto.news - April 13th, 2024 [April 13th, 2024]
- How Are Smart Contracts Transforming Financial Transactions? - IT News Africa - April 13th, 2024 [April 13th, 2024]
- Enhancing Smart Contract Security With SolidityScan and Blockscout Integration - Business - April 13th, 2024 [April 13th, 2024]
- Top 15 Use Cases of Blockchain in the Real World, 2024 - Analytics Insight - April 13th, 2024 [April 13th, 2024]
- exSat Unveiled: Pioneering the Future of Bitcoin Scalability and Interoperability with Layer 2 Solutions - FinanceFeeds - April 9th, 2024 [April 9th, 2024]
- ZkLink looks to solve Ethereum's fragmented liquidity with a layer 3 but there are risks - DLNews - April 9th, 2024 [April 9th, 2024]
- 1 in 6 new Base meme coins are scams, 91% have vulnerabilities - TradingView - April 9th, 2024 [April 9th, 2024]
- The AI-Based Smart Contract Audit Firm "Bunzz Audit" Has Officially Launched - Chronicle-Tribune - April 9th, 2024 [April 9th, 2024]
- BlockDAG Smart Contract Leads With 20,000x ROIs As Top Trending Crypto Surpassing Dogecoin Rally And ICP's ... - Blockchain Magazine - April 9th, 2024 [April 9th, 2024]
- What Is Ethereum Restaking? - Ledger - April 9th, 2024 [April 9th, 2024]
- The Contract Evolution: Are Smart Contracts Outsmarting Tradition? - yTech - April 1st, 2024 [April 1st, 2024]
- Vitalik Buterin Initiates 'The Purge': Ethereum Protocol Simplification for Enhanced Efficiency - TradingView - April 1st, 2024 [April 1st, 2024]
- sCrypt Hackathon 2024: Making Ordinals easier with smart contracts - CoinGeek - April 1st, 2024 [April 1st, 2024]
- Smart Contracts and Family Law: Revolutionizing Agreements for the Modern Family - The Good Men Project - April 1st, 2024 [April 1st, 2024]
- NEAR launches tool for signing transactions on Bitcoin, Ethereum and more - Blockworks - April 1st, 2024 [April 1st, 2024]
- sCrypt Hackathon 2024: Project Babbage on why users should be at the center of digital economy - CoinGeek - April 1st, 2024 [April 1st, 2024]
- Cardano Gains Momentum: Innovative Developments Promise Continued Expansion and Evolution - West Island Blog - April 1st, 2024 [April 1st, 2024]
- How smart accounts and account abstraction can unlock Ethereum's full utility - Cointelegraph - March 22nd, 2024 [March 22nd, 2024]
- Stellar will invest $100M in Soroban smart contract apps in bid to beat Ethereum - VentureBeat - March 22nd, 2024 [March 22nd, 2024]
- Top 10 Intriguing Ways EVM (Ethereum Virtual Machine) Was Popularized By DeFi Craze - Blockchain Magazine - March 22nd, 2024 [March 22nd, 2024]
- Cardano (ADA)'s Smart Contract Boom: Is ADA Heading to $5? - CryptoTicker.io - Bitcoin Price, Ethereum Price & Crypto News - March 22nd, 2024 [March 22nd, 2024]
- Blockchain evolution with MANTA for Sora and intelligent contracts - Cointelegraph - March 22nd, 2024 [March 22nd, 2024]
- Top 10 Amazing Ways Ethereum Limitations Can Be Resolved By DApps Support - Blockchain Magazine - March 22nd, 2024 [March 22nd, 2024]
- The Anticipated Altcoin Season- A Look at the Possibilities and Potential Players Satoshi Business News - The San Bernardino American News - March 22nd, 2024 [March 22nd, 2024]
- Crypto to Buy Now: Stellar's Sorban, Scorpion Casinos' Daily Staking Reward for 10x Gains and Uniswaps Volatility - Analytics Insight - March 22nd, 2024 [March 22nd, 2024]
- Smart Contracts Go Live on Stellar, Kicking Off a "New Era" for the Network - Cryptonews - February 23rd, 2024 [February 23rd, 2024]
- Stacks (STX) price outperforms the market as interest in layer-2 Bitcoin grows - TradingView - February 23rd, 2024 [February 23rd, 2024]
- This Is What Vitalik Buterin Thinks About Artificial Intelligence (AI) - BeInCrypto - February 23rd, 2024 [February 23rd, 2024]
- 200-year-old Scotch whiskey maker enters the AI age with generated labels - ReadWrite - February 23rd, 2024 [February 23rd, 2024]
- Smart Contracts: the future of efficient and transparent business interactions - NL Times - February 23rd, 2024 [February 23rd, 2024]
- Understanding DAOs: The Pros and Cons of Decentralized Autonomous Organizations - Geeks World Wide - February 23rd, 2024 [February 23rd, 2024]
- Vitalik Buterin says AI could help solve Ethereum's 'biggest technical risk' - Cointelegraph - February 23rd, 2024 [February 23rd, 2024]
- Chainlink Bulls Brace For Explosive Growth Following $216 Million Whale Accumulation - TradingView - February 23rd, 2024 [February 23rd, 2024]
- Demystifying Smart Contracts: The Power of Decentralization | by Advancio | Dec, 2023 - Medium - December 10th, 2023 [December 10th, 2023]
- Web3 Firm Thirdweb Finds Major Vulnerability In Smart Contracts - Cryptonews - December 10th, 2023 [December 10th, 2023]
- What is Flare (FLR)?: Will Flare Price Explode in 2024? - CryptoTicker.io - Bitcoin Price, Ethereum Price & Crypto News - December 10th, 2023 [December 10th, 2023]
- Web3 developer Thirdweb boosts bounty to $50,000 in light of fresh smart contract security risks - CryptoSlate - December 10th, 2023 [December 10th, 2023]
- Smart contract exploit in TIME token leads to $188k loss - crypto.news - December 10th, 2023 [December 10th, 2023]
- The Future of Trust and Efficiency in Transactions - Medium - December 10th, 2023 [December 10th, 2023]