CoolFace
Apppublic

codenlighten/scrypt

sourceHugging Faceopenrailupdated 3y agoView on Hugging Face
0likes
ethereum-devs.md97 linesDownload Raw Back to root
1---2sidebar_position: 123---4 5# sCrypt for Ethereum Developers6 7# Smart contracts on Bitcoin vs Ethereum8Bitcoin and Ethereum are both layer-1 blockchains with [fully programmable smart contracts](https://xiaohuiliu.medium.com/turing-machine-on-bitcoin-7f0ebe0d52b1).9However, their designs fundamentally differ. 10 11Ethereum is a global state machine, whose state consists of all smart contracts deployed on it. Each transaction is an input to the state machine, transitioning it to the next state according to the rules defined in the smart contract the transaction calls. The design imposes severe limitations on scalability, since transactions must be sequentially processed due to potential race conditions.12 13In Bitcoin, transaction processing is independent of each other since all information needed is localized. There is no shared global state. Bitcoin is maximally parallelizable by design.14 15Detailed side-by-side comparison can be found [here](ttps://xiaohuiliu.medium.com/bitcoin-vs-ethereum-smart-contracts-921e0a12b043), which is concisely summarized below.16 17|| Ethereum | Bitcoin |18|---|---|---|19| Execution Environment | [Ethereum Virtual Machine](https://ethereum.org/en/developers/docs/evm/) (EVM) | [Bitcoin Virtual Machine](https://xiaohuiliu.medium.com/introduction-to-bitcoin-smart-contracts-9c0ea37dc757) (BVM)|20| Model | Account | [UTXO](./overview.md#how-do-bitcoin-smart-contracts-work) |21| Transaction Fee | $1-10 | $0.00001 |22| Transactions Per Second | 15 | 3000+ |23| Transaction Processing | Sequential | Parallel |24| Scalability | Vertical | Horizontal |25| Paradigm | Impure | Pure |26 27 28# Smart contract development on Bitcoin vs Ethereum29 30Besides unboundedly scalable fundation, Bitcoin also offers superior smart cotnract developer experience.31 32The table below shows a comparison of popular Ethereum development tools and their counterparts in the Bitcoin ecosystem.33 34There are two noticeable differences.351. Bitcoin smart contract is written in TypeScript, one of the most popular programming languages tens of millions of Web2 developers are already familiar with. They do not have to learn a new niche programming language like Solidity, placing a high barrier to entry. They can reuse all of their favoriate tools, such as Visual Studio Code, [WebStorm](https://www.jetbrains.com/webstorm/), and NPM. 362. Ethereum's development tools are **fragmented**. They are developed by different entities, who are often competitors. There is disincentive to make them more interoperable, thus they don't communicate with each other well. By contrast, sCrypt takes a more holistic and systematic approach. It builds a unified full-stack platform that encompasses most tools, from programming language, to framework/libraries. Developed synergistically, they are fully compatible with each other, greatly simplifing and streamlining development process.37 38 39|| Ethereum | Bitcoin |40|---|---|---|41| Programming Language | [Solidity](https://soliditylang.org/) | [sCrypt DSL](https://docs.scrypt.io/) |42| Framework | [Hardhat](https://hardhat.org/) / [Truffle](https://trufflesuite.com/truffle/) | [The sCrypt CLI](https://www.npmjs.com/package/scrypt-cli) |43| Libraries | [Web3.js](https://web3js.org/#/) / [Ethers.js](https://docs.ethers.org) | [scrypt-ts](https://docs.scrypt.io/how-to-write-a-contract/) |44| Developer Platform | [Alchemy](https://www.alchemy.com/) / [Infura](https://www.infura.io/) | [sCrypt](https://scrypt.io) |45| IDE | [Remix](https://remix.ethereum.org)[^1] | [Visual Studio Code](https://code.visualstudio.com/) |46| Wallet | [MetaMask](https://metamask.io/) | [Sensilet](https://sensilet.com/) |47| Block Explorer | [Etherscan](https://etherscan.io/) | [WhatsOnChain](https://whatsonchain.com/) |48 49[^1]: Visual Studio Code can also be used for Solidity with various extentions. However, its support is extremely limited compared to that of sCrypt, a TypeScript DSL, which is supported out of box without any extension. For example, [VS Code debugger](./how-to-debug-a-contract.md) has first-class comprehensive support for sCrypt, but does not suppport Solidity.50 51## Example Code52 53Let's compare a counter smart contract between Solidity and sCrypt.54 55```js56pragma solidity >=0.7.0 <0.9.0;57 58contract Counter {59 60    int private count;61 62    constructor(int _initialCount) {63        count = _initialCount;64    }65 66    function incrementCounter() public {67        count += 1;68    }69 70    function getCount() public view returns (int) {71        return count;72    }73 74}75```76 77```ts78class Counter extends SmartContract {79 80    @prop(true)81    count: bigint82 83    constructor(count: bigint) {84        super(...arguments)85        this.count = count86    }87 88    @method()89    public incremenCounter() {90        this.count++91 92        assert(hash256(this.buildStateOutput(this.ctx.utxo.value)) == this.ctx.hashOutputs)93    }94 95}96```97