Skip to content

Commit 8f4e422

Browse files
committed
Update examples and small fixes
Comment fixes Small fixes Update fixtures after rebase Update READMEs Rename parameter -> argument
1 parent 35e9a18 commit 8f4e422

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3318
-8312
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
**/grammar/
44
/website/
55
*.js
6+
examples/webapp

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = {
22
root: true,
33
parser: '@typescript-eslint/parser',
44
plugins: ['@typescript-eslint'],
5-
extends: ['airbnb-typescript'],
5+
extends: ['airbnb-typescript/base'],
66
parserOptions: {
77
project: './tsconfig.json',
88
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features

README.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -53,33 +53,37 @@ npm install cashscript
5353

5454
### Usage
5555
```ts
56-
import { Contract, ... } from 'cashscript';
56+
import { Contract, CashCompiler, ... } from 'cashscript';
5757
```
5858

5959
```js
60-
const { Contract, ... } = require('cashscript');
60+
const { Contract, CashCompiler, ... } = require('cashscript');
6161
```
6262

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

6565
```ts
6666
...
6767
// Compile the P2PKH contract
68-
const P2PKH = Contract.compile('./p2pkh.cash', 'mainnet');
68+
const P2PKH = CashCompiler.compileFile('./p2pkh.cash');
6969

70-
// Instantiate a new P2PKH contract with constructor arguments: { pkh: pkh }
71-
const instance = P2PKH.new(pkh);
70+
// Instantiate a network provider for CashScript's network operations
71+
const provider = new ElectrumNetworkProvider('mainnet');
72+
73+
// Create a new P2PKH contract with constructor arguments: { pkh: pkh }
74+
const contract = new Contract(P2PKH, [pkh], provider);
7275

7376
// Get contract balance & output address + balance
74-
console.log('contract address:', instance.address);
75-
console.log('contract balance:', await instance.getBalance());
77+
console.log('contract address:', contract.address);
78+
console.log('contract balance:', await contract.getBalance());
7679

7780
// Call the spend function with the owner's signature
7881
// And use it to send 0. 000 100 00 BCH back to the contract's address
79-
const txDetails = await instance.functions
82+
const txDetails = await contract.functions
8083
.spend(pk, new SignatureTemplate(keypair))
81-
.to(instance.address, 10000)
84+
.to(contract.address, 10000)
8285
.send();
86+
8387
console.log(txDetails);
8488
...
8589
```

examples/Browser/package.json

-29
This file was deleted.

examples/Browser/public/favicon.ico

-3.78 KB
Binary file not shown.

examples/Browser/public/p2pkh.cash

-7
This file was deleted.

examples/Browser/src/App.js

-102
This file was deleted.

examples/Escrow/Escrow.cash

-53
This file was deleted.

examples/Escrow/Escrow.ts

-81
This file was deleted.

examples/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# CashScript examples
2-
This folder contains a number of example CashScript contracts to show off its functionality and usage. The `.cash` files contain example contracts, and the `.ts`/`.js` files contain exmaple usage of the CashScript SDK with these contracts.
2+
This folder contains a number of example CashScript contracts to show off its functionality and usage. The `.cash` files contain example contracts, and the `.ts`/`.js` files contain example usage of the CashScript SDK with these contracts.
33

4-
The "Hello World" of cash contracts is defining the P2PKH pattern inside a cash contract, which can be found under [`p2pkh.cash`](/examples/p2pkh.cash). Its usage can be found under [`p2pkh.ts`](/examples/p2pkh.ts). To showcase web usage of the CashScript SDK, the `p2pkh.cash` contract has also been integrated into a very simple React app under [`Browser`](/examples/Browser/).
4+
The "Hello World" of cash contracts is defining the P2PKH pattern inside a cash contract, which can be found under [`p2pkh.cash`](/examples/p2pkh.cash). Its usage can be found under [`p2pkh.ts`](/examples/p2pkh.ts). To showcase web usage of the CashScript SDK, the `p2pkh.cash` contract has also been integrated into a very simple React webapp under [`webapp`](/examples/webapp/).
55

66
## Running the examples
77
To run the examples, clone this repository and navigate to the `examples/` directory. Since the examples depend on the SDK, be sure to run `yarn` inside the `examples/` directory, which installs all required packages.
@@ -25,12 +25,12 @@ All `.js` files can be executed with `node`.
2525
node p2pkh.js
2626
```
2727

28-
## Running the browser example
29-
The browser example can be run from the `Browser/` folder.
28+
## Running the webapp example
29+
The webapp example can be run from the `webapp/` folder.
3030

3131
```bash
3232
yarn
3333
yarn start
3434
```
3535

36-
This will display a simple webapp that allows you to create a P2PKH contract from a specific seed phrase and use the contract to send BCH. The code can be found in [`Browser/src/App.js`](/examples/Browser/src/App.js). Note that the `.cash` file has to be read, and then passed into the CashScript SDK, rather than passing just the file path into the SDK.
36+
This will display a simple webapp that allows you to create a P2PKH contract from a specific seed phrase and use the contract to send BCH. The code can be found in [`webapp/src/App.ts`](/examples/webapp/src/App.ts). Note that the `.cash` file has to be read, and then passed into the CashScript SDK, rather than passing just the file path into the SDK.

examples/announcement.cash

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma cashscript ^0.4.0;
1+
pragma cashscript ^0.5.0;
22

33
/* This is a contract showcasing covenants outside of regular transactional use.
44
* It enforces the contract to make an "announcement" on Memo.cash, and send the

0 commit comments

Comments
 (0)