You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Compiles a CashScript contract from a source file. This compile method is handy when using Node.js with the contract source file available but you are doing quick compilations (for example for contract size comparisons) and you don't need the contract artifact file to be generated.
Compiles a CashScript contract from a source code string. This compile method is handy in a browser compilation setting like the [CashScript Playground](https://playground.cashscript.org/) where testing contracts can be quickly compiled and discarded. The method is also useful if no source file is locally available (e.g. the source code is retrieved with a REST API).
The `enforceFunctionParameterTypes` option is used to enforce function parameter types, such as byte length of `bytes20` or `bytes32` types and `bool` values. By default, it is set to `true`.
108
+
109
+
If set to `false`, the compiler will not enforce function parameter types. This means that it is possible for `bytes20` values to have a different length at runtime than the expected 20 bytes. Or that `bool` values are not actually booleans, but integers.
110
+
111
+
This option is useful if you are certain that passing in incorrect function parameter types will not cause runtime vulnerabilities, and you want to save on the extra opcodes that are added to the script to enforce the types.
Copy file name to clipboardExpand all lines: website/docs/sdk/instantiation.md
+29-9Lines changed: 29 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,22 +14,22 @@ new Contract(
14
14
constructorArgs: ConstructorArgument[],
15
15
options : {
16
16
provider: NetworkProvider,
17
-
addressType?: 'p2sh20'|'p2sh32',
17
+
contractType?: 'p2sh20'|'p2sh32'|'p2s',
18
18
}
19
19
)
20
20
```
21
21
22
-
A CashScript contract can be instantiated by providing an `Artifact` object, a list of constructor arguments, and optionally an options object configuring `NetworkProvider` and `addressType`.
22
+
A CashScript contract can be instantiated by providing an `Artifact` object, a list of constructor arguments, and optionally an options object configuring `NetworkProvider` and `contractType`.
23
23
24
-
An `Artifact` object is the result of compiling a CashScript contract. Compilation can be done using the standalone [`cashc` CLI](/docs/compiler) or programmatically with the `cashc` NPM package (see [CashScript Compiler](/docs/compiler#javascript-compilation)).
24
+
An `Artifact` object is the result of compiling a CashScript contract. Compilation can be done using the standalone [`cashc` CLI](/docs/compiler) or programmatically with the `cashc` NPM package (see [CashScript Compiler](/docs/compiler#javascript-compilation)).
25
25
26
26
:::tip
27
27
If compilation is done using the `cashc` CLI with the <span style={{ display: 'inline-block' }}>`--format ts`</span> option to output TypeScript Artifacts, you will get explicit types and type checking for the constructor arguments and function arguments of the `Contract` class.
28
28
:::
29
29
30
30
The `NetworkProvider` option is used to manage network operations for the CashScript contract. By default, a mainnet `ElectrumNetworkProvider` is used, but the network providers can be configured. See the docs on [NetworkProvider](/docs/sdk/network-provider).
31
31
32
-
The `addressType` option is used to choose between a `p2sh20` and `p2sh32`address type for the CashScript contract. By default `p2sh32` is used because it has increased cryptographic security — but it is not yet supported by all wallets.
32
+
The `contractType` option is used to choose between a `p2sh20`, `p2sh32`or `p2s` contract type for the CashScript contract. By default `p2sh32` is used because it has increased cryptographic security — but it is not yet supported by all wallets.
33
33
34
34
:::caution
35
35
p2sh32 was introduced because p2sh20 is cryptographically insecure for a large subset of smart contracts. For contracts holding large sums of BCH this provides an incentive to find a hash collision and hack the contract.
@@ -66,6 +66,10 @@ A contract's regular address (without token-support) can be retrieved through th
66
66
Wallets will not allow you to send CashTokens to this address. For that you must use the [tokenAddress](#tokenaddress) below. Wallets which have not upgraded might not recognize this new address type.
67
67
:::
68
68
69
+
:::info
70
+
If you are using a `p2s` contract, the `address` member field does not exist on the contract object.
71
+
:::
72
+
69
73
#### Example
70
74
```ts
71
75
console.log(contract.address)
@@ -78,17 +82,33 @@ contract.tokenAddress: string
78
82
79
83
A contract's token-supporting address can be retrieved through the `tokenAddress` member field.
80
84
85
+
:::info
86
+
If you are using a `p2s` contract, the `tokenAddress` member field does not exist on the contract object.
87
+
:::
88
+
81
89
#### Example
82
90
```ts
83
91
console.log(contract.tokenAddress)
84
92
```
85
93
94
+
### lockingBytecode
95
+
```ts
96
+
contract.lockingBytecode: string
97
+
```
98
+
99
+
Returns the contract's locking bytecode encoded as a hex string. This exists for all contract types, including `p2s`.
100
+
101
+
#### Example
102
+
```ts
103
+
console.log(contract.lockingBytecode)
104
+
```
105
+
86
106
### bytecode
87
107
```ts
88
108
contract.bytecode: string
89
109
```
90
110
91
-
Returns the contract's redeem script encoded as a hex string.
111
+
Returns the contract's bytecode encoded as a hex string.
The size of the contract's bytecode in bytes can be retrieved through the `bytesize` member field. This is useful to ensure that the contract is not too big, since Bitcoin Cash smart contracts can be 1,650 bytes at most.
123
+
The size of the contract's bytecode in bytes can be retrieved through the `bytesize` member field. This is useful to ensure that the contract is not too big, since Bitcoin Cash smart contracts can be 10,000 bytes at most for P2SH contracts and 201 bytes for P2S contracts. See the [Script & Transaction Limits](/docs/compiler/script-limits) page for more information.
104
124
105
-
:::tip
125
+
:::info
106
126
Using `contract.bytesize` is the best way to get the size of contract bytecode, as it includes the constructor arguments.
107
127
The size outputs of the `cashc` compiler are based on the bytecode without constructor arguments so are always an underestimate.
108
128
:::
109
129
110
130
#### Example
111
131
```ts
112
132
// make sure the contract bytesize is within standardness limits
Copy file name to clipboardExpand all lines: website/docs/sdk/other-network-providers.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ new FullStackNetworkProvider(network: Network, bchjs: BCHJS)
47
47
The `FullStackNetworkProvider` uses [FullStack.cash][fullstack]' infrastructure to connect to the BCH network. FullStack.cash' offers dedicated infrastructure and support plans for larger projects. Both `network` and `bchjs` parameters are mandatory, where `bchjs` is an instance of FullStack.cash' [BCHJS][bchjs].
48
48
49
49
:::caution
50
-
The `FullStackNetworkProvider` does not currently support CashTokens. If you want to use CashTokens, please use the `ElectrumNetworkProvider` instead.
50
+
The `FullStackNetworkProvider` does not currently support CashTokens or the `getUtxosForLockingBytecode()` method. If you want to use these features, please use the `ElectrumNetworkProvider` instead.
The `BitcoinRpcNetworkProvider` uses a direct connection to a BCH node. Note that a regular node does not have indexing, so any address of interest (e.g. the contract address) need to be registered by the node *before* sending any funds to those addresses. Because of this it is recommended to use a different network provider unless you have a specific reason to use the RPC provider.
73
73
74
74
:::caution
75
-
The `BitcoinRpcNetworkProvider` does not currently support CashTokens. If you want to use CashTokens, use the `ElectrumNetworkProvider` instead.
75
+
The `BitcoinRpcNetworkProvider` does not currently support CashTokens or the `getUtxosForLockingBytecode()` method. If you want to use these features, please use the `ElectrumNetworkProvider` instead.
0 commit comments