Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ In the 'Editor' panel you can write CashScript contracts and compile them. After

The CashScript Playground allows for importing or exporting contract Artifacts and makes it easy to test new versions of your CashScript code. Similarly, it's also easy to create many contract instances of the same contract with different contract arguments. The created Artifacts and contracts are remembered between sessions.

On the 'Wallets' tab, new key-pairs for testing wallets can be generated with just a mouse click. Each with detailed info on about the key pair and its network balance, with a full list of all current UTXOs. Lastly the TransactionBuilder supports CashTokens, manual input selection for easy P2PK inputs and signing selection through a simple dropdown!
On the 'Wallets' tab, new key-pairs for testing wallets can be generated with just a mouse click. Each with detailed info on about the key pair and its network balance, with a full list of all current UTXOs. Lastly the TransactionBuilder supports CashTokens and signing selection through a simple dropdown!

## Limitations

The playground uses the 'Simple transactio builder' so it doesn't currently support combining multiple different smart contracts in one transaction.
The playground doesn't currently support combining multiple different smart contracts in one transaction.

Special transaction options such as OP_RETURN or relative timelocks are also not supported by the playground.

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"@types/react": "18.0.30",
"@types/react-dom": "18.0.11",
"bootstrap": "^5.3.3",
"cashc": "^0.11.0-next.0",
"cashscript": "^0.11.0-next.0",
"cashc": "^0.11.0-next.1",
"cashscript": "^0.11.0-next.1",
"eslint": "^9.18.0",
"eslint-config-next": "^15.1.4",
"next": "^15.1.4",
Expand Down
23 changes: 6 additions & 17 deletions src/components/ContractFunction.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react'
import { AbiFunction, NetworkProvider, FunctionArgument, Recipient, SignatureTemplate, MockNetworkProvider } from 'cashscript'
import { AbiFunction, NetworkProvider, FunctionArgument, Recipient, SignatureTemplate, TransactionBuilder } from 'cashscript'
import { Form, InputGroup, Button, Card } from 'react-bootstrap'
import { readAsType, ExplorerString, Wallet, NamedUtxo, ContractInfo } from './shared'

Expand All @@ -18,7 +18,6 @@ const ContractFunction: React.FC<Props> = ({ contractInfo, abi, provider, wallet
const [inputs, setInputs] = useState<NamedUtxo[]>([{ txid: '', vout: 0, satoshis: 0n, name: ``, isP2pkh: false }])
const [outputHasFT, setOutputHasFT] = useState<boolean[]>([])
const [outputHasNFT, setOutputHasNFT] = useState<boolean[]>([])
const [noAutomaticChange, setNoAutomaticChange] = useState<boolean>(false)
const [namedUtxoList, setNamedUtxoList] = useState<NamedUtxo[]>([])

const contract = contractInfo.contract
Expand Down Expand Up @@ -270,23 +269,21 @@ const ContractFunction: React.FC<Props> = ({ contractInfo, abi, provider, wallet

// try to send transaction and alert result
try {
// first step of constructing transaction
const transaction = contract.functions[abi.name](...functionArgs)
// start constructing transaction
const transaction = new TransactionBuilder({provider})

// add inputs to transaction in correct order
for(const input of inputs){
if(input.isP2pkh){
const walletIndex = input.walletIndex as number
const sigTemplate = new SignatureTemplate(wallets[walletIndex].privKey)
transaction.fromP2PKH(input, sigTemplate)
transaction.addInput(input, sigTemplate.unlockP2PKH())
} else {
transaction.from(input)
transaction.addInput(input, contract.unlock[abi.name](...functionArgs))
}
}

// if noAutomaticChange is enabled, add this to the transaction in construction
if (noAutomaticChange) transaction.withoutChange().withoutTokenChange()
transaction.to(outputs)
transaction.addOutputs(outputs)

// check for mocknet
if(provider.network == "mocknet"){
Expand Down Expand Up @@ -353,14 +350,6 @@ const ContractFunction: React.FC<Props> = ({ contractInfo, abi, provider, wallet
<Button variant="outline-secondary" size="sm" onClick={addInput}>+</Button>
</Card.Subtitle>
{inputFields}
<Form style={{ marginTop: '10px', marginBottom: '5px' }}>
<Form.Check
type="switch"
id={"noAutomaticChange" + abi?.name}
label="disable automatic change output"
onChange={() => setNoAutomaticChange(!noAutomaticChange)}
/>
</Form>
<Card.Subtitle style={{ marginTop: '10px', marginBottom: '5px' }}>
Transaction outputs{' '}
<Button variant="outline-secondary" size="sm" disabled={outputs.length <= 1} onClick={removeOutput}>-</Button>
Expand Down
86 changes: 37 additions & 49 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
resolved "https://registry.yarnpkg.com/@bitauth/libauth/-/libauth-3.1.0-next.2.tgz#121782b38774d9fba8226406db9b9af0c8d8e464"
integrity sha512-XRtk9p8UHvtjSPS38rsfHXzaPHG5j9FpN4qHqqGLoAuZYy675PBiOy9zP6ah8lTnnIVaCFl2ekct8w0Hy1oefw==

"@cashscript/utils@^0.11.0-next.0":
version "0.11.0-next.0"
resolved "https://registry.yarnpkg.com/@cashscript/utils/-/utils-0.11.0-next.0.tgz#0a22b870ab0d72c96c7e52d7791bfe85e8d3368d"
integrity sha512-FuKUFBR33UQHO6DxFqf0oKIVEi5zP/f1quJO2xPIKRvn9+L79MrUXQa7p1DhKPRWrH5RSTZGZAGh5yNqHe/OLw==
"@cashscript/utils@^0.11.0-next.1":
version "0.11.0-next.1"
resolved "https://registry.yarnpkg.com/@cashscript/utils/-/utils-0.11.0-next.1.tgz#46b00b9527f7060935ad21110985f976fe552cd1"
integrity sha512-+kVXnmJ0dA/JqVnAo4URgsGE6bOkyxepgRcZWvhOoCUYGtwRc02ltL0sHBEv1ysTaiFYhNHhGkrFUNvMec/1xw==
dependencies:
"@bitauth/libauth" "^3.1.0-next.2"

Expand Down Expand Up @@ -870,10 +870,10 @@ ansi-styles@^4.1.0:
dependencies:
color-convert "^2.0.1"

antlr4@^4.13.1-patch-1:
version "4.13.1-patch-1"
resolved "https://registry.yarnpkg.com/antlr4/-/antlr4-4.13.1-patch-1.tgz#946176f863f890964a050c4f18c47fd6f7e57602"
integrity sha512-OjFLWWLzDMV9rdFhpvroCWR4ooktNg9/nvVYSA5z28wuVpU36QUNuioR1XLnQtcjVlf8npjyz593PxnU/f/Cow==
antlr4@^4.13.2:
version "4.13.2"
resolved "https://registry.yarnpkg.com/antlr4/-/antlr4-4.13.2.tgz#0d084ad0e32620482a9c3a0e2470c02e72e4006d"
integrity sha512-QiVbZhyy4xAZ17UPEuG3YTOt8ZaoeOR1CvEAqrEsDBsOqINslaB147i9xqljZqoyf5S+EUlGStaj+t22LT9MOg==

argparse@^2.0.1:
version "2.0.1"
Expand Down Expand Up @@ -1135,29 +1135,31 @@ caniuse-lite@^1.0.30001579:
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001625.tgz#ead1b155ea691d6a87938754d3cb119c24465b03"
integrity sha512-4KE9N2gcRH+HQhpeiRZXd+1niLB/XNLAhSy4z7fI8EzcbcPoAqjNInxVHTiTwWfTIV4w096XG8OtCOCQQKPv3w==

cashc@^0.11.0-next.0:
version "0.11.0-next.0"
resolved "https://registry.yarnpkg.com/cashc/-/cashc-0.11.0-next.0.tgz#c3c100d4e2a32dc0725ef446df87508a11962dba"
integrity sha512-toO/Xrr7S91kJAZyL+/MMwfJbqzEm0Ak3aKxq01bFSy5qzg67xfPs4OsRuw2aXGKI+g/LZ/+odYI3v+GSXyXqw==
cashc@^0.11.0-next.1:
version "0.11.0-next.1"
resolved "https://registry.yarnpkg.com/cashc/-/cashc-0.11.0-next.1.tgz#6f708190c5309788f8a5e1babe083d3edd638454"
integrity sha512-85f7x8ybUyZ+i8QbzGeNaPsIgwODNjYxpFnc/h6k1R/s8ueQsOsA5v7dC/A0pF74cOhHKYrJ5nLH8vL6OZDzXw==
dependencies:
"@bitauth/libauth" "^3.1.0-next.2"
"@cashscript/utils" "^0.11.0-next.0"
antlr4 "^4.13.1-patch-1"
commander "^7.1.0"
semver "^7.5.4"
"@cashscript/utils" "^0.11.0-next.1"
antlr4 "^4.13.2"
commander "^13.1.0"
semver "^7.6.3"

cashscript@^0.11.0-next.0:
version "0.11.0-next.0"
resolved "https://registry.yarnpkg.com/cashscript/-/cashscript-0.11.0-next.0.tgz#55e72c44b129e4b20967af7086dfb705ff053f0f"
integrity sha512-gdVy7ErbZRLcaO0xVobxbwO9mqBbhWUcG5+I49OHmf3pHajoA/CgmfD4JfQ13Okinsqgh4nbYOEG8sgn5fwieg==
cashscript@^0.11.0-next.1:
version "0.11.0-next.1"
resolved "https://registry.yarnpkg.com/cashscript/-/cashscript-0.11.0-next.1.tgz#0ae6592bd7bb63ead30eff5c4ff8200299fdf6aa"
integrity sha512-IqmxjcXefAvYbYa2kPCQcS7A4tlWNfDEEctfuVoJ8tZW2qDYaVGwgvdbwVddw1FeK7rZ+AFT7r2zCyHzM/XnWQ==
dependencies:
"@bitauth/libauth" "^3.1.0-next.2"
"@cashscript/utils" "^0.11.0-next.0"
"@cashscript/utils" "^0.11.0-next.1"
"@mr-zwets/bchn-api-wrapper" "^1.0.1"
delay "^5.0.0"
change-case "^5.4.4"
delay "^6.0.0"
electrum-cash "^2.0.10"
fast-deep-equal "^3.1.3"
pako "^2.1.0"
semver "^7.6.3"

chalk@^2.0.0:
version "2.4.2"
Expand All @@ -1176,6 +1178,11 @@ chalk@^4.0.0:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

change-case@^5.4.4:
version "5.4.4"
resolved "https://registry.yarnpkg.com/change-case/-/change-case-5.4.4.tgz#0d52b507d8fb8f204343432381d1a6d7bff97a02"
integrity sha512-HRQyTk2/YPEkt9TnUPbOpr64Uw3KOicFWPVBb+xiHvd6eBx/qPr9xqfBFDT8P2vWsvvz4jbEkfDe71W3VyNu2w==

chokidar@^4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-4.0.3.tgz#7be37a4c03c9aee1ecfe862a4a23b2c70c205d30"
Expand Down Expand Up @@ -1233,10 +1240,10 @@ color@^4.2.3:
color-convert "^2.0.1"
color-string "^1.9.0"

commander@^7.1.0:
version "7.2.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7"
integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==
commander@^13.1.0:
version "13.1.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-13.1.0.tgz#776167db68c78f38dcce1f9b8d7b8b9a488abf46"
integrity sha512-/rFeCpNJQbhSZjGVwO9RFV3xPqbnERS8MmIQzCtD/zl6gpJuV/bMLuN92oG3F7d8oDEHHRrujSXNUr8fpjntKw==

[email protected]:
version "0.0.1"
Expand Down Expand Up @@ -1378,10 +1385,10 @@ define-properties@^1.2.1:
has-property-descriptors "^1.0.0"
object-keys "^1.1.1"

delay@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/delay/-/delay-5.0.0.tgz#137045ef1b96e5071060dd5be60bf9334436bd1d"
integrity sha512-ReEBKkIfe4ya47wlPYf/gu5ib6yUG0/Aez0JQZQz94kiWtRQvZIQbTiehsnwHvLSWJnQdhVeqYue7Id1dKr0qw==
delay@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/delay/-/delay-6.0.0.tgz#43749aefdf6cabd9e17b0d00bd3904525137e607"
integrity sha512-2NJozoOHQ4NuZuVIr5CWd0iiLVIRSDepakaovIN+9eIDHEhdCAEvSy2cuf1DCrPPQLvHmbqTHODlhHg8UCy4zw==

dequal@^2.0.3:
version "2.0.3"
Expand Down Expand Up @@ -2729,13 +2736,6 @@ loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0:
dependencies:
js-tokens "^3.0.0 || ^4.0.0"

lru-cache@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94"
integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==
dependencies:
yallist "^4.0.0"

math-intrinsics@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/math-intrinsics/-/math-intrinsics-1.1.0.tgz#a0dd74be81e2aa5c2f27e65ce283605ee4e2b7f9"
Expand Down Expand Up @@ -3282,13 +3282,6 @@ semver@^6.3.1:
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==

semver@^7.5.4:
version "7.6.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.0.tgz#1a46a4db4bffcccd97b743b5005c8325f23d4e2d"
integrity sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==
dependencies:
lru-cache "^6.0.0"

semver@^7.6.0, semver@^7.6.3:
version "7.6.3"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143"
Expand Down Expand Up @@ -3865,11 +3858,6 @@ ws@^7.5.2:
resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.9.tgz#54fa7db29f4c7cec68b1ddd3a89de099942bb591"
integrity sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==

yallist@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==

yaml@^1.10.0:
version "1.10.2"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.2.tgz#2301c5ffbf12b467de8da2333a459e29e7920e4b"
Expand Down