T3203
The CashScript used here is a high-level programming language for smart contracts forked for the eCash chain by community dev Sam Rock. It offers a strong abstraction layer over eCash's 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 eCash differ greatly from smart contracts on Ethereum.
The example here consists of a CashScript contract (p2pkh.cash) which is compiled using the CashScript compiler into a JSON output (p2pkhContract.json), which is then imported into JS modules (p2pkhContract.js) to facilitate interactions with that contract.
Note: this eCash fork of CashScript was split from CashScript v0.6.5 which was the last version before they implemented introspection opcodes, cashtokens support...etc.
Overview:
- /contracts/p2pkh.cash is the contract in the CashScript language which takes in a public key hash at the point of creation and ensures only the matching public key and signature can unlock the spend() function.
- /contracts/p2pkContract.json is the output from compiling the CashScript contract, which is imported into js files for contract interaction.
- /scripts/p2pkhContract.js contains the createP2pkhContract() function which instantiates CashScript via Chronik and creates a new contract based on the supplied public key hash. Its entry point function calls createP2pkhContract() and then displays the contract address/balance before sending a nominal amount in sats back to the contract