All Projects → Bitcoin-com → cashscript

Bitcoin-com / cashscript

Licence: MIT License
⚖️ Easily write and interact with Bitcoin Cash smart contracts

Programming Languages

typescript
32286 projects
solidity
1140 projects
javascript
184084 projects - #8 most used programming language
ANTLR
299 projects
CSS
56736 projects
Dockerfile
14818 projects
shell
77523 projects

Projects that are alternatives of or similar to cashscript

algo-coin
Python library for algorithmic trading cryptocurrencies across multiple exchanges
Stars: ✭ 386 (+354.12%)
Mutual labels:  bitcoin-cash
surbtc-api-client-python
Cliente para servicios web de SURBTC en Python
Stars: ✭ 12 (-85.88%)
Mutual labels:  bitcoin-cash
copernicus
Golang bitcoin library
Stars: ✭ 18 (-78.82%)
Mutual labels:  bitcoin-cash
tape-recorder
BSV Hackathon: Use Tape Recorder to record any computation onto Bitcoin Script using a Wang B machine written in Forth
Stars: ✭ 22 (-74.12%)
Mutual labels:  bitcoin-script
pandacash-cli
🐼Fast Bitcoin Cash RPC client for testing and development (inspired by ganache-cli)
Stars: ✭ 19 (-77.65%)
Mutual labels:  bitcoin-cash
cryptosub
Track 170+ cryptocurrency subreddits, view most popular coins, activity trends, most frequent words, and more
Stars: ✭ 37 (-56.47%)
Mutual labels:  bitcoin-cash
profbit
Track your Coinbase profits!
Stars: ✭ 37 (-56.47%)
Mutual labels:  bitcoin-cash
BitcoinTransactionTool
A complete tool for creating and editing bitcoin transactions
Stars: ✭ 16 (-81.18%)
Mutual labels:  bitcoin-script
wallet-address-validator
Useful library for validation of Bitcoin, Litecoin, Ethereum and other cryptocoin addresses
Stars: ✭ 240 (+182.35%)
Mutual labels:  bitcoin-cash
Essentia-iOS
All in One Blockchain solution
Stars: ✭ 50 (-41.18%)
Mutual labels:  bitcoin-cash
CryptoCurrency.Net
CryptoCurrency.Net
Stars: ✭ 21 (-75.29%)
Mutual labels:  bitcoin-cash
bitcoincashjs
WARNING: This project is no longer maintained. Please, use bitcore-lib-cash instead.
Stars: ✭ 80 (-5.88%)
Mutual labels:  bitcoin-cash
bitcoin
Fresh Bitcoin Implementation
Stars: ✭ 23 (-72.94%)
Mutual labels:  bitcoin-cash
sdk-js
Viblo Javascript SDK
Stars: ✭ 17 (-80%)
Mutual labels:  sdk-js
bitcoin-kit-android
Comprehensive Bitcoin development library for iOS, implemented on Swift. SPV wallet implementation for Bitcoin, Bitcoin Cash, Litecoin and Dash blockchains. Fully compliant with existing standards and BIPs.
Stars: ✭ 102 (+20%)
Mutual labels:  bitcoin-cash
atomic-swap-kit-android
Atomic Swap Android library for Bitcoin (BTC) and Bitcoin Cash (BCH) swaps in decentralized manner. Implemented on Kotlin.
Stars: ✭ 17 (-80%)
Mutual labels:  bitcoin-cash
gcash
An alternative full node bitcoin-ABC implementation written in Go (golang)
Stars: ✭ 21 (-75.29%)
Mutual labels:  bitcoin-cash
datum-sdk
Datum Javascript API
Stars: ✭ 15 (-82.35%)
Mutual labels:  sdk-js
bitcoin-cash-converter
Java converter from legacy address to new bitcoincash format and vice versa
Stars: ✭ 22 (-74.12%)
Mutual labels:  bitcoin-cash
coinsplitter
Bitcoin Cash / Bitcoin Satoshi Vision coin splitter.
Stars: ✭ 17 (-80%)
Mutual labels:  bitcoin-cash

CashScript

Build Status Coverage Status NPM Version NPM Monthly Downloads NPM License

CashScript is a high-level programming language for smart contracts on Bitcoin Cash. It offers a strong abstraction layer over Bitcoin Cash' native virtual machine, Bitcoin Script. Its syntax is based on Ethereum's smart contract language Solidity, but its functionality is very different since smart contracts on Bitcoin Cash differ greatly from smart contracts on Ethereum. For a detailed comparison of them, refer to the blog post Smart Contracts on Ethereum, Bitcoin and Bitcoin Cash.

This repository contains the code for the CashScript compiler & command line tool under packages/cashc/. This repository also contains the code for the CashScript JavaScript SDK under packages/cashscript/. The source code of the CashScript.org website is included under website/. Visit the website for a detailed Documentation on the CashScript language and SDK.

The CashScript Language

CashScript is a high-level language that allows you to write Bitcoin Cash smart contracts in a straightforward and familiar way. Its syntax is inspired by Ethereum's Solidity language, but its functionality is different since the underlying systems have very different fundamentals. See the language documentation for a full reference of the language.

The CashScript Compiler

CashScript features a compiler as a standalone command line tool, called cashc. It can be installed through npm and used to compile .cash files into .json artifact files. These artifact files can be imported into the CashScript JavaScript SDK (or other SDKs in the future). The cashc NPM package can also be imported inside JavaScript files to compile .cash files without using the command line tool.

Installation

npm install -g cashc

Usage

Usage: cashc [options] [source_file]

Options:
  --output, -o   Specify a file to output the generated artifact.       [string]
  --hex, -h      Compile the contract to hex format rather than a full artifact
                                                                       [boolean]
  --asm, -A      Compile the contract to ASM format rather than a full artifact
                                                                       [boolean]
  --opcount, -c  Display the number of opcodes in the compiled bytecode[boolean]
  --size, -s     Display the size in bytes of the compiled bytecode    [boolean]
  --help         Show help                                             [boolean]
  --version      Show version number                                   [boolean]

The CashScript SDK

The main way to interact with CashScript contracts and integrate them into applications is using the CashScript SDK. This SDK allows you to import .json artifact files that were compiled using the cashc compiler and convert them to Contract objects. These objects are used to create new contract instances. These instances are used to interact with the contracts using the functions that were implemented in the .cash file. For more information on the CashScript SDK, refer to the SDK documentation.

Installation

npm install cashscript

Usage

import { Contract, ... } from 'cashscript';
const { Contract, ... } = require('cashscript');

Using the CashScript SDK, you can import contract artifact files, create new instances of these contracts, and interact with these instances:

...
  // Import the P2PKH artifact
  const P2PKH = require('./p2pkh-artifact.json');

  // Instantiate a network provider for CashScript's network operations
  const provider = new ElectrumNetworkProvider('mainnet');

  // Create a new P2PKH contract with constructor arguments: { pkh: pkh }
  const contract = new Contract(P2PKH, [pkh], provider);

  // Get contract balance & output address + balance
  console.log('contract address:', contract.address);
  console.log('contract balance:', await contract.getBalance());

  // Call the spend function with the owner's signature
  // And use it to send 0. 000 100 00 BCH back to the contract's address
  const txDetails = await contract.functions
    .spend(pk, new SignatureTemplate(keypair))
    .to(contract.address, 10000)
    .send();

  console.log(txDetails);
...

Examples

If you want to see CashScript in action and check out its usage, there are several example contracts in the examples/ directory. The .cash files contain example contracts, and the .ts files contain example usage of the CashScript SDK to interact with these contracts.

The "Hello World" of CashScript contracts is defining the P2PKH pattern inside a contract, which can be found under examples/p2pkh.cash. Its usage can be found under examples/p2pkh.ts.

Running the examples

To run the examples, clone this repository and navigate to the examples/ directory. Since the examples depend on the SDK, be sure to run npm install or yarn inside the examples/ directory, which installs all required packages.

git clone [email protected]:Bitcoin-com/cashscript.git
cd cashscript/examples
npm install

All .ts files in the examples/ directory can then be executed with ts-node.

npm install -g ts-node
ts-node p2pkh.ts

All .js files can be executed with node.

node p2pkh.js
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].