Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cashscript

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cashscript

⚖️ Easily write and interact with Cash Contracts on Bitcoin Cash

  • 0.3.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
249
decreased by-41.27%
Maintainers
1
Weekly downloads
 
Created
Source

CashScript SDK

Build Status Coverage Status NPM Version NPM Monthly Downloads NPM License

CashScript is a high level language enabling basic smart contract functionality on Bitcoin Cash. While these cash contracts are less powerful than Ethereum's smart contracts, CashScript was in many ways inspired by Ethereum's development ecosystem. Ethereum has always had one of the most accessible development ecosystems in terms of tooling, and with CashScript we want to bring that accessibility to Bitcoin Cash.


The CashScript JavaScript SDK allows you to easily integrate cash contracts written with CashScript into JavaScript or TypeScript applications. The CashScript SDK uses cash contract .cash files or .json artifact files to generate a JavaScript Contract object that can be used to instantiated and interact with these cash contracts. See the SDK documentation for a full reference of the SDK.

Note: The CashScript currently only supports NodeJS, as it uses some NodeJS-specific functionality (fs, path). We are working on making the library compatible with the browser as well as NodeJS, but this is currently not supported.

Attention: CashScript is in active development, and is currently in a beta phase. While CashScript is in beta stage, its APIs and usage is subject to change, so be sure to check the documentation. During the beta phase it is possible that the library still contains bugs, so for now the CashScript SDK can only be used on the testnet network.

Installation

The CashScript SDK can be installed through npm:

npm install cashscript

Usage

After installing, the CashScript SDK can be imported into your TypeScript or JavaScript projects.

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

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

...
  // Compile the P2PKH Cash Contract
  const P2PKH: Contract = Contract.compile(path.join(__dirname, 'p2pkh.cash'), 'testnet');

  // Instantiate a new P2PKH contract with constructor arguments: { pkh: pkh }
  const instance: Instance = P2PKH.new(pkh);

  // Get contract balance & output address + balance
  const contractBalance: number = await instance.getBalance();
  console.log('contract address:', instance.address);
  console.log('contract balance:', contractBalance);

  // 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 tx: TxnDetailsResult = await instance.functions.spend(pk, new Sig(keypair))
    .send(instance.address, 10000);
  console.log('transaction details:', tx);
...

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 cash contracts is defining the P2PKH pattern inside a cash contract, which can be found under examples/p2pkh.cash. Its usage can be found under examples/p2pkh.ts or examples/p2pkh-artifact.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 git@github.com:Bitcoin-com/cashscript.git
cd cashscript/examples
yarn / 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

The CashScript Language

CashScript is a high-level language that allows you to write Cash Contracts in a straightforward and familiar way. It is inspired by Ethereum's Solidity, but it is not the same, and cash contracts work very differently from Ethereum's smart contracts. See the Language documentation for a full reference of the language.

Keywords

FAQs

Package last updated on 31 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc