starknet 4.3.0 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -1
- package/__mocks__/typedDataSessionExample.json +42 -0
- package/__tests__/defaultProvider.test.ts +11 -24
- package/__tests__/rpcProvider.test.ts +32 -5
- package/__tests__/sequencerProvider.test.ts +9 -1
- package/__tests__/utils/__snapshots__/ellipticalCurve.test.ts.snap +2 -0
- package/__tests__/utils/ellipticalCurve.test.ts +5 -0
- package/__tests__/utils/merkle.test.ts +146 -0
- package/__tests__/utils/typedData.test.ts +107 -9
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/provider/default.d.ts +2 -2
- package/dist/provider/default.js +3 -3
- package/dist/provider/interface.d.ts +6 -3
- package/dist/provider/rpc.d.ts +9 -4
- package/dist/provider/rpc.js +70 -28
- package/dist/provider/sequencer.d.ts +2 -2
- package/dist/provider/sequencer.js +4 -4
- package/dist/provider/utils.d.ts +12 -0
- package/dist/provider/utils.js +17 -1
- package/dist/signer/default.d.ts +1 -1
- package/dist/signer/default.js +1 -0
- package/dist/types/api/openrpc.d.ts +151 -0
- package/dist/types/api/openrpc.js +9 -0
- package/dist/types/api/rpc.d.ts +22 -43
- package/dist/types/provider.d.ts +5 -5
- package/dist/utils/ellipticCurve.d.ts +13 -0
- package/dist/utils/ellipticCurve.js +20 -16
- package/dist/utils/hash.js +8 -6
- package/dist/utils/merkle.d.ts +10 -0
- package/dist/utils/merkle.js +90 -0
- package/dist/utils/number.d.ts +1 -0
- package/dist/utils/number.js +6 -2
- package/dist/utils/responseParser/rpc.d.ts +13 -3
- package/dist/utils/responseParser/rpc.js +2 -10
- package/dist/utils/responseParser/sequencer.d.ts +4 -1
- package/dist/utils/responseParser/sequencer.js +1 -7
- package/dist/utils/typedData/index.d.ts +23 -8
- package/dist/utils/typedData/index.js +70 -31
- package/dist/utils/typedData/types.d.ts +8 -3
- package/index.d.ts +1 -0
- package/index.js +2 -1
- package/package.json +1 -1
- package/provider/default.d.ts +2 -2
- package/provider/default.js +3 -3
- package/provider/interface.d.ts +6 -3
- package/provider/rpc.d.ts +9 -4
- package/provider/rpc.js +70 -28
- package/provider/sequencer.d.ts +2 -2
- package/provider/sequencer.js +4 -4
- package/provider/utils.d.ts +12 -0
- package/provider/utils.js +17 -1
- package/signer/default.d.ts +1 -1
- package/signer/default.js +1 -0
- package/src/index.ts +1 -0
- package/src/provider/default.ts +2 -3
- package/src/provider/interface.ts +5 -3
- package/src/provider/rpc.ts +59 -32
- package/src/provider/sequencer.ts +3 -6
- package/src/provider/utils.ts +22 -1
- package/src/signer/default.ts +2 -2
- package/src/types/api/openrpc.ts +168 -0
- package/src/types/api/rpc.ts +22 -45
- package/src/types/provider.ts +5 -5
- package/src/utils/ellipticCurve.ts +20 -16
- package/src/utils/hash.ts +8 -6
- package/src/utils/merkle.ts +70 -0
- package/src/utils/number.ts +5 -1
- package/src/utils/responseParser/rpc.ts +16 -13
- package/src/utils/responseParser/sequencer.ts +5 -8
- package/src/utils/typedData/index.ts +88 -34
- package/src/utils/typedData/types.ts +12 -4
- package/types/api/openrpc.d.ts +151 -0
- package/types/api/openrpc.js +9 -0
- package/types/api/rpc.d.ts +22 -43
- package/types/provider.d.ts +5 -5
- package/utils/ellipticCurve.d.ts +13 -0
- package/utils/ellipticCurve.js +20 -16
- package/utils/hash.js +8 -6
- package/utils/merkle.d.ts +10 -0
- package/utils/merkle.js +90 -0
- package/utils/number.d.ts +1 -0
- package/utils/number.js +6 -2
- package/utils/responseParser/rpc.d.ts +13 -3
- package/utils/responseParser/rpc.js +2 -10
- package/utils/responseParser/sequencer.d.ts +4 -1
- package/utils/responseParser/sequencer.js +1 -7
- package/utils/typedData/index.d.ts +23 -8
- package/utils/typedData/index.js +70 -31
- package/utils/typedData/types.d.ts +8 -3
- package/www/docs/API/account.md +20 -18
- package/www/docs/API/contract.md +10 -10
- package/www/docs/API/contractFactory.md +14 -11
- package/www/docs/API/provider.md +29 -63
- package/www/docs/API/signer.md +8 -10
- package/www/docs/API/utils.md +157 -74
- package/www/guides/account.md +12 -12
- package/www/guides/erc20.md +19 -4
- package/www/guides/intro.md +3 -1
package/utils/typedData/index.js
CHANGED
|
@@ -39,8 +39,9 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
39
39
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.getMessageHash = exports.getStructHash = exports.encodeData = exports.getTypeHash = exports.encodeType = exports.getDependencies = void 0;
|
|
42
|
+
exports.getMessageHash = exports.getStructHash = exports.encodeData = exports.encodeValue = exports.getTypeHash = exports.encodeType = exports.getDependencies = exports.isMerkleTreeType = exports.prepareSelector = void 0;
|
|
43
43
|
var hash_1 = require("../hash");
|
|
44
|
+
var merkle_1 = require("../merkle");
|
|
44
45
|
var number_1 = require("../number");
|
|
45
46
|
var shortString_1 = require("../shortString");
|
|
46
47
|
var utils_1 = require("./utils");
|
|
@@ -56,6 +57,14 @@ function getHex(value) {
|
|
|
56
57
|
throw new Error("Invalid BigNumberish: ".concat(value));
|
|
57
58
|
}
|
|
58
59
|
}
|
|
60
|
+
function prepareSelector(selector) {
|
|
61
|
+
return (0, number_1.isHex)(selector) ? selector : (0, hash_1.getSelectorFromName)(selector);
|
|
62
|
+
}
|
|
63
|
+
exports.prepareSelector = prepareSelector;
|
|
64
|
+
function isMerkleTreeType(type) {
|
|
65
|
+
return type.type === 'merkletree';
|
|
66
|
+
}
|
|
67
|
+
exports.isMerkleTreeType = isMerkleTreeType;
|
|
59
68
|
/**
|
|
60
69
|
* Get the dependencies of a struct type. If a struct has the same dependency multiple times, it's only included once
|
|
61
70
|
* in the resulting array.
|
|
@@ -65,12 +74,8 @@ function getHex(value) {
|
|
|
65
74
|
* @param {string[]} [dependencies]
|
|
66
75
|
* @return {string[]}
|
|
67
76
|
*/
|
|
68
|
-
var getDependencies = function (
|
|
77
|
+
var getDependencies = function (types, type, dependencies) {
|
|
69
78
|
if (dependencies === void 0) { dependencies = []; }
|
|
70
|
-
// `getDependencies` is called by most other functions, so we validate the JSON schema here
|
|
71
|
-
if (!(0, utils_1.validateTypedData)(typedData)) {
|
|
72
|
-
throw new Error('Typed data does not match JSON schema');
|
|
73
|
-
}
|
|
74
79
|
// Include pointers (struct arrays)
|
|
75
80
|
if (type[type.length - 1] === '*') {
|
|
76
81
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -79,14 +84,29 @@ var getDependencies = function (typedData, type, dependencies) {
|
|
|
79
84
|
if (dependencies.includes(type)) {
|
|
80
85
|
return dependencies;
|
|
81
86
|
}
|
|
82
|
-
if (!
|
|
87
|
+
if (!types[type]) {
|
|
83
88
|
return dependencies;
|
|
84
89
|
}
|
|
85
90
|
return __spreadArray([
|
|
86
91
|
type
|
|
87
|
-
], __read(
|
|
92
|
+
], __read(types[type].reduce(function (previous, t) { return __spreadArray(__spreadArray([], __read(previous), false), __read((0, exports.getDependencies)(types, t.type, previous).filter(function (dependency) { return !previous.includes(dependency); })), false); }, [])), false);
|
|
88
93
|
};
|
|
89
94
|
exports.getDependencies = getDependencies;
|
|
95
|
+
function getMerkleTreeType(types, ctx) {
|
|
96
|
+
if (ctx.parent && ctx.key) {
|
|
97
|
+
var parentType = types[ctx.parent];
|
|
98
|
+
var merkleType = parentType.find(function (t) { return t.name === ctx.key; });
|
|
99
|
+
var isMerkleTree = isMerkleTreeType(merkleType);
|
|
100
|
+
if (!isMerkleTree) {
|
|
101
|
+
throw new Error("".concat(ctx.key, " is not a merkle tree"));
|
|
102
|
+
}
|
|
103
|
+
if (merkleType.contains.endsWith('*')) {
|
|
104
|
+
throw new Error("Merkle tree contain property must not be an array but was given ".concat(ctx.key));
|
|
105
|
+
}
|
|
106
|
+
return merkleType.contains;
|
|
107
|
+
}
|
|
108
|
+
return 'raw';
|
|
109
|
+
}
|
|
90
110
|
/**
|
|
91
111
|
* Encode a type to a string. All dependant types are alphabetically sorted.
|
|
92
112
|
*
|
|
@@ -94,12 +114,12 @@ exports.getDependencies = getDependencies;
|
|
|
94
114
|
* @param {string} type
|
|
95
115
|
* @return {string}
|
|
96
116
|
*/
|
|
97
|
-
var encodeType = function (
|
|
98
|
-
var _a = __read((0, exports.getDependencies)(
|
|
99
|
-
var
|
|
100
|
-
return
|
|
117
|
+
var encodeType = function (types, type) {
|
|
118
|
+
var _a = __read((0, exports.getDependencies)(types, type)), primary = _a[0], dependencies = _a.slice(1);
|
|
119
|
+
var newTypes = !primary ? [] : __spreadArray([primary], __read(dependencies.sort()), false);
|
|
120
|
+
return newTypes
|
|
101
121
|
.map(function (dependency) {
|
|
102
|
-
return "".concat(dependency, "(").concat(
|
|
122
|
+
return "".concat(dependency, "(").concat(types[dependency].map(function (t) { return "".concat(t.name, ":").concat(t.type); }), ")");
|
|
103
123
|
})
|
|
104
124
|
.join('');
|
|
105
125
|
};
|
|
@@ -111,8 +131,8 @@ exports.encodeType = encodeType;
|
|
|
111
131
|
* @param {string} type
|
|
112
132
|
* @return {string}
|
|
113
133
|
*/
|
|
114
|
-
var getTypeHash = function (
|
|
115
|
-
return (0, hash_1.getSelectorFromName)((0, exports.encodeType)(
|
|
134
|
+
var getTypeHash = function (types, type) {
|
|
135
|
+
return (0, hash_1.getSelectorFromName)((0, exports.encodeType)(types, type));
|
|
116
136
|
};
|
|
117
137
|
exports.getTypeHash = getTypeHash;
|
|
118
138
|
/**
|
|
@@ -124,25 +144,39 @@ exports.getTypeHash = getTypeHash;
|
|
|
124
144
|
* @param {any} data
|
|
125
145
|
* @returns {[string, string]}
|
|
126
146
|
*/
|
|
127
|
-
var encodeValue = function (
|
|
128
|
-
if (
|
|
147
|
+
var encodeValue = function (types, type, data, ctx) {
|
|
148
|
+
if (ctx === void 0) { ctx = {}; }
|
|
149
|
+
if (types[type]) {
|
|
129
150
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
130
|
-
return [type, (0, exports.getStructHash)(
|
|
151
|
+
return [type, (0, exports.getStructHash)(types, type, data)];
|
|
131
152
|
}
|
|
132
|
-
if (Object.keys(
|
|
153
|
+
if (Object.keys(types)
|
|
133
154
|
.map(function (x) { return "".concat(x, "*"); })
|
|
134
155
|
.includes(type)) {
|
|
135
156
|
var structHashes = data.map(function (struct) {
|
|
136
157
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
137
|
-
return (0, exports.getStructHash)(
|
|
158
|
+
return (0, exports.getStructHash)(types, type.slice(0, -1), struct);
|
|
138
159
|
});
|
|
139
160
|
return [type, (0, hash_1.computeHashOnElements)(structHashes)];
|
|
140
161
|
}
|
|
162
|
+
if (type === 'merkletree') {
|
|
163
|
+
var merkleTreeType_1 = getMerkleTreeType(types, ctx);
|
|
164
|
+
var structHashes = data.map(function (struct) {
|
|
165
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
166
|
+
return (0, exports.encodeValue)(types, merkleTreeType_1, struct)[1];
|
|
167
|
+
});
|
|
168
|
+
var root = new merkle_1.MerkleTree(structHashes).root;
|
|
169
|
+
return ['felt', root];
|
|
170
|
+
}
|
|
141
171
|
if (type === 'felt*') {
|
|
142
172
|
return ['felt*', (0, hash_1.computeHashOnElements)(data)];
|
|
143
173
|
}
|
|
174
|
+
if (type === 'selector') {
|
|
175
|
+
return ['felt', prepareSelector(data)];
|
|
176
|
+
}
|
|
144
177
|
return [type, getHex(data)];
|
|
145
178
|
};
|
|
179
|
+
exports.encodeValue = encodeValue;
|
|
146
180
|
/**
|
|
147
181
|
* Encode the data to an ABI encoded Buffer. The data should be a key -> value object with all the required values. All
|
|
148
182
|
* dependant types are automatically encoded.
|
|
@@ -151,20 +185,23 @@ var encodeValue = function (typedData, type, data) {
|
|
|
151
185
|
* @param {string} type
|
|
152
186
|
* @param {Record<string, any>} data
|
|
153
187
|
*/
|
|
154
|
-
var encodeData = function (
|
|
155
|
-
var _a = __read(
|
|
188
|
+
var encodeData = function (types, type, data) {
|
|
189
|
+
var _a = __read(types[type].reduce(function (_a, field) {
|
|
156
190
|
var _b = __read(_a, 2), ts = _b[0], vs = _b[1];
|
|
157
191
|
if (data[field.name] === undefined || data[field.name] === null) {
|
|
158
192
|
throw new Error("Cannot encode data: missing data for '".concat(field.name, "'"));
|
|
159
193
|
}
|
|
160
194
|
var value = data[field.name];
|
|
161
|
-
var _c = __read(encodeValue(
|
|
195
|
+
var _c = __read((0, exports.encodeValue)(types, field.type, value, {
|
|
196
|
+
parent: type,
|
|
197
|
+
key: field.name,
|
|
198
|
+
}), 2), t = _c[0], encodedValue = _c[1];
|
|
162
199
|
return [
|
|
163
200
|
__spreadArray(__spreadArray([], __read(ts), false), [t], false),
|
|
164
201
|
__spreadArray(__spreadArray([], __read(vs), false), [encodedValue], false),
|
|
165
202
|
];
|
|
166
|
-
}, [['felt'], [(0, exports.getTypeHash)(
|
|
167
|
-
return [
|
|
203
|
+
}, [['felt'], [(0, exports.getTypeHash)(types, type)]]), 2), returnTypes = _a[0], values = _a[1];
|
|
204
|
+
return [returnTypes, values];
|
|
168
205
|
};
|
|
169
206
|
exports.encodeData = encodeData;
|
|
170
207
|
/**
|
|
@@ -176,24 +213,26 @@ exports.encodeData = encodeData;
|
|
|
176
213
|
* @param {Record<string, any>} data
|
|
177
214
|
* @return {Buffer}
|
|
178
215
|
*/
|
|
179
|
-
var getStructHash = function (
|
|
180
|
-
return (0, hash_1.computeHashOnElements)((0, exports.encodeData)(
|
|
216
|
+
var getStructHash = function (types, type, data) {
|
|
217
|
+
return (0, hash_1.computeHashOnElements)((0, exports.encodeData)(types, type, data)[1]);
|
|
181
218
|
};
|
|
182
219
|
exports.getStructHash = getStructHash;
|
|
183
220
|
/**
|
|
184
|
-
* Get the EIP-191 encoded message to sign, from the typedData object.
|
|
185
|
-
* with Keccak256.
|
|
221
|
+
* Get the EIP-191 encoded message to sign, from the typedData object.
|
|
186
222
|
*
|
|
187
223
|
* @param {TypedData} typedData
|
|
188
224
|
* @param {BigNumberish} account
|
|
189
225
|
* @return {string}
|
|
190
226
|
*/
|
|
191
227
|
var getMessageHash = function (typedData, account) {
|
|
228
|
+
if (!(0, utils_1.validateTypedData)(typedData)) {
|
|
229
|
+
throw new Error('Typed data does not match JSON schema');
|
|
230
|
+
}
|
|
192
231
|
var message = [
|
|
193
232
|
(0, shortString_1.encodeShortString)('StarkNet Message'),
|
|
194
|
-
(0, exports.getStructHash)(typedData, 'StarkNetDomain', typedData.domain),
|
|
233
|
+
(0, exports.getStructHash)(typedData.types, 'StarkNetDomain', typedData.domain),
|
|
195
234
|
account,
|
|
196
|
-
(0, exports.getStructHash)(typedData, typedData.primaryType, typedData.message),
|
|
235
|
+
(0, exports.getStructHash)(typedData.types, typedData.primaryType, typedData.message),
|
|
197
236
|
];
|
|
198
237
|
return (0, hash_1.computeHashOnElements)(message);
|
|
199
238
|
};
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
export declare type StarkNetMerkleType = {
|
|
2
|
+
name: string;
|
|
3
|
+
type: 'merkletree';
|
|
4
|
+
contains: string;
|
|
5
|
+
};
|
|
1
6
|
/**
|
|
2
7
|
* A single type, as part of a struct. The `type` field can be any of the EIP-712 supported types.
|
|
3
8
|
*
|
|
4
9
|
* Note that the `uint` and `int` aliases like in Solidity, and fixed point numbers are not supported by the EIP-712
|
|
5
10
|
* standard.
|
|
6
11
|
*/
|
|
7
|
-
export
|
|
12
|
+
export declare type StarkNetType = {
|
|
8
13
|
name: string;
|
|
9
|
-
type:
|
|
10
|
-
}
|
|
14
|
+
type: string;
|
|
15
|
+
} | StarkNetMerkleType;
|
|
11
16
|
/**
|
|
12
17
|
* The EIP712 domain struct. Any of these fields are optional, but it must contain at least one field.
|
|
13
18
|
*/
|
package/www/docs/API/account.md
CHANGED
|
@@ -12,36 +12,36 @@ This API is the primary way to interact with an account contract on StarkNet.
|
|
|
12
12
|
|
|
13
13
|
## Creating an instance
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
To create a new instance of the Account, first an account contract must be deployed. Also there needs to be a Provider instance that will be passed in the constructor and key pair for the account.
|
|
16
16
|
|
|
17
17
|
`new starknet.Account(Provider, address, starkKeyPair)`
|
|
18
18
|
|
|
19
|
-
##
|
|
19
|
+
## Properties
|
|
20
20
|
|
|
21
21
|
account.**address** => _string_
|
|
22
22
|
|
|
23
|
-
The address of the account contract
|
|
23
|
+
The address of the account contract.
|
|
24
24
|
|
|
25
|
-
##
|
|
25
|
+
## Methods
|
|
26
26
|
|
|
27
27
|
account.**getNonce()** => _Promise < string >_
|
|
28
28
|
|
|
29
|
-
Gets new Nonce for the next transaction
|
|
29
|
+
Gets the new Nonce for the next transaction.
|
|
30
30
|
|
|
31
31
|
<hr />
|
|
32
32
|
|
|
33
33
|
account.**estimateFee**(calls [ , options ]) => _Promise < EstimateFeeResponse >_
|
|
34
34
|
|
|
35
|
-
Gets the estimated fee for the call(s)
|
|
35
|
+
Gets the estimated fee for the call(s).
|
|
36
36
|
|
|
37
37
|
The _options_ object may include any of:
|
|
38
38
|
|
|
39
39
|
- options.**blockIdentifier** - Block Identifier for the transaction
|
|
40
40
|
- options.**nonce** - Nonce for the transaction
|
|
41
41
|
|
|
42
|
-
######
|
|
42
|
+
###### _EstimateFeeResponse_
|
|
43
43
|
|
|
44
|
-
```
|
|
44
|
+
```typescript
|
|
45
45
|
{
|
|
46
46
|
overall_fee: BN;
|
|
47
47
|
gas_consumed?: BN;
|
|
@@ -53,7 +53,7 @@ The _options_ object may include any of:
|
|
|
53
53
|
|
|
54
54
|
account.**execute**(calls [ , abi , transactionsDetail ]) => _Promise < AddTransactionResponse >_
|
|
55
55
|
|
|
56
|
-
Executes one or multiple calls using the account contract
|
|
56
|
+
Executes one or multiple calls using the account contract.
|
|
57
57
|
|
|
58
58
|
The _transactionsDetail_ object may include any of:
|
|
59
59
|
|
|
@@ -61,9 +61,9 @@ The _transactionsDetail_ object may include any of:
|
|
|
61
61
|
- transactionsDetail.**nonce** - Nonce for the transaction
|
|
62
62
|
- transactionsDetail.**version** - Version for the transaction (default is 0)
|
|
63
63
|
|
|
64
|
-
######
|
|
64
|
+
###### _AddTransactionResponse_
|
|
65
65
|
|
|
66
|
-
```
|
|
66
|
+
```typescript
|
|
67
67
|
{
|
|
68
68
|
transaction_hash: string;
|
|
69
69
|
};
|
|
@@ -73,11 +73,11 @@ The _transactionsDetail_ object may include any of:
|
|
|
73
73
|
|
|
74
74
|
account.**signMessage**(typedData) => _Promise < Signature >_
|
|
75
75
|
|
|
76
|
-
Creates a signature from the passed data
|
|
76
|
+
Creates a signature from the passed data.
|
|
77
77
|
|
|
78
|
-
######
|
|
78
|
+
###### _Signature_
|
|
79
79
|
|
|
80
|
-
```
|
|
80
|
+
```typescript
|
|
81
81
|
string[];
|
|
82
82
|
```
|
|
83
83
|
|
|
@@ -85,20 +85,22 @@ string[];
|
|
|
85
85
|
|
|
86
86
|
account.**hashMessage**(typedData) => _Promise < string >_
|
|
87
87
|
|
|
88
|
-
Creates a hash from the passed data
|
|
88
|
+
Creates a hash from the passed data.
|
|
89
89
|
|
|
90
90
|
<hr />
|
|
91
91
|
|
|
92
92
|
account.**verifyMessageHash**(hash, signature) => _Promise < boolean >_
|
|
93
93
|
|
|
94
|
-
Verify a signature of a given hash
|
|
94
|
+
Verify a signature of a given hash.
|
|
95
95
|
|
|
96
|
-
**WARNING**
|
|
96
|
+
> **WARNING**
|
|
97
|
+
>
|
|
98
|
+
> This method is not recommended, use `verifyMessage` instead
|
|
97
99
|
|
|
98
100
|
<hr />
|
|
99
101
|
|
|
100
102
|
account.**verifyMessage**(typedData, signature) => _Promise < boolean >_
|
|
101
103
|
|
|
102
|
-
Verify a signature of a JSON object
|
|
104
|
+
Verify a signature of a JSON object.
|
|
103
105
|
|
|
104
106
|
<hr />
|
package/www/docs/API/contract.md
CHANGED
|
@@ -12,19 +12,19 @@ Contracts allow you to transform Cairo values, like `Uint256` to `BigNumber`. It
|
|
|
12
12
|
|
|
13
13
|
`new starknet.Contract(abi, address, providerOrAccount)`
|
|
14
14
|
|
|
15
|
-
`contract.attach(
|
|
15
|
+
`contract.attach(address)` _for changing the address of the connected contract_
|
|
16
16
|
|
|
17
|
-
`contract.connect(
|
|
17
|
+
`contract.connect(providerOrAccount)` _for changing the provider or account_
|
|
18
18
|
|
|
19
|
-
##
|
|
19
|
+
## Properties
|
|
20
20
|
|
|
21
21
|
contract.**address** => _string_
|
|
22
22
|
|
|
23
|
-
The address the contract was constructed/connected with
|
|
23
|
+
The address the contract was constructed/connected with.
|
|
24
24
|
|
|
25
25
|
contract.**providerOrAccount** => _ProviderInterface | AccountInterface_
|
|
26
26
|
|
|
27
|
-
Provider or account that are used to interact with the network
|
|
27
|
+
Provider or account that are used to interact with the network.
|
|
28
28
|
|
|
29
29
|
contract.**deployTransactionHash** => _string | null_
|
|
30
30
|
|
|
@@ -32,9 +32,9 @@ If the Contract object is the result of a ContractFactory deployment, this is th
|
|
|
32
32
|
|
|
33
33
|
contract.**abi** => _Abi_
|
|
34
34
|
|
|
35
|
-
The ABI the contract was constructed with
|
|
35
|
+
The ABI the contract was constructed with.
|
|
36
36
|
|
|
37
|
-
##
|
|
37
|
+
## Methods
|
|
38
38
|
|
|
39
39
|
contract.**deployed**() => _Promise < Contract >_
|
|
40
40
|
|
|
@@ -46,13 +46,13 @@ A Meta-Class is a Class which has any of its properties determined at run-time.
|
|
|
46
46
|
|
|
47
47
|
### Read-Only Methods(constant)
|
|
48
48
|
|
|
49
|
-
A constant method (denoted view in Cairo) is read-only and evaluates a small amount of
|
|
49
|
+
A constant method (denoted view in Cairo) is read-only and evaluates a small amount of Cairo code against the current blockchain state. It is therefore free and does not require any fee, but cannot make changes to the blockchain state...
|
|
50
50
|
|
|
51
51
|
contract.**METHOD_NAME**(...args [ , overrides ]) => _Promise < Result >_
|
|
52
52
|
|
|
53
53
|
The type of the result depends on the ABI. Result object will be returned with each parameter available positionally and if the parameter is named, it will also be available by its name.
|
|
54
54
|
|
|
55
|
-
The _overrides_ object for a read-only method may include
|
|
55
|
+
The _overrides_ object for a read-only method may include:
|
|
56
56
|
|
|
57
57
|
- overrides.**blockIdentifier**
|
|
58
58
|
|
|
@@ -62,7 +62,7 @@ A non-constant method requires a transaction to be signed and requires payment i
|
|
|
62
62
|
|
|
63
63
|
contract.**METHOD_NAME**(...args [ , overrides ]) => _Promise < AddTransactionResponse >_
|
|
64
64
|
|
|
65
|
-
Returns a
|
|
65
|
+
Returns a _AddTransactionResponse_ for the transaction after it is sent to the network. This requires that Contract has a signer.
|
|
66
66
|
|
|
67
67
|
The _overrides_ object for write methods may include any of:
|
|
68
68
|
|
|
@@ -4,7 +4,7 @@ sidebar_position: 5
|
|
|
4
4
|
|
|
5
5
|
# Contract Factory
|
|
6
6
|
|
|
7
|
-
Contract Factory allow you to deploy contracts
|
|
7
|
+
Contract Factory allow you to deploy contracts to StarkNet. To deploy a Contract, additional information is needed that is not available on a Contract object itself.
|
|
8
8
|
|
|
9
9
|
## Creating an instance
|
|
10
10
|
|
|
@@ -18,25 +18,28 @@ Creates a new instance of a ContractFactory for the contract described by the _c
|
|
|
18
18
|
|
|
19
19
|
## Properties
|
|
20
20
|
|
|
21
|
-
contractFactory.**abi** => _Abi_
|
|
21
|
+
contractFactory.**abi** => _Abi_
|
|
22
22
|
|
|
23
|
-
The ABI the contractFactory was constructed with
|
|
23
|
+
The ABI the contractFactory was constructed with.
|
|
24
24
|
|
|
25
|
-
contractFactory.**compiledContract** => _CompiledContract_
|
|
25
|
+
contractFactory.**compiledContract** => _CompiledContract_
|
|
26
26
|
|
|
27
|
-
The compiled contract the contractFactory was constructed with
|
|
27
|
+
The compiled contract the contractFactory was constructed with.
|
|
28
28
|
|
|
29
|
-
contractFactory.**providerOrAccount** => _ProviderInterface | AccountInterface_
|
|
29
|
+
contractFactory.**providerOrAccount** => _ProviderInterface | AccountInterface_
|
|
30
30
|
|
|
31
|
-
Provider or account that are used to interact with the network
|
|
31
|
+
Provider or account that are used to interact with the network.
|
|
32
32
|
|
|
33
33
|
## Methods
|
|
34
34
|
|
|
35
35
|
contractFactory.**attach**( address ) ⇒ _Contract_
|
|
36
36
|
|
|
37
|
-
Return an instance of a
|
|
37
|
+
Return an instance of a _Contract_ attached to address. This is the same as using the _Contract_ constructor with address and this _compiledContract_ and _providerOrAccount_ passed in when creating the ContractFactory.
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
Uses the provider to deploy the Contract with constructorCalldata passed into the constructor and returns a Contract which is attached to the address where this contract will be deployed.
|
|
39
|
+
<hr />
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
contractFactory.**deploy**( constructorCalldata, addressSalt ) ⇒ _Promise < Contract >_
|
|
42
|
+
|
|
43
|
+
Uses the provider to deploy the Contract with _constructorCalldata_ passed into the constructor and returns a _Contract_ which is attached to the address where this contract will be deployed.
|
|
44
|
+
|
|
45
|
+
The transaction hash can be found at _contract.deployTransactionHash_, and no interactions should be made until the transaction is resolved.
|