starknet 3.14.1 → 3.15.2
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/.github/workflows/pr.yml +10 -8
- package/.github/workflows/release.yml +29 -3
- package/CHANGELOG.md +25 -0
- package/__mocks__/Account.json +1182 -1164
- package/__tests__/account.test.ts +19 -8
- package/__tests__/contract.test.ts +4 -10
- package/__tests__/fixtures.ts +25 -13
- package/__tests__/provider.test.ts +50 -85
- package/__tests__/utils/__snapshots__/utils.browser.test.ts.snap +2 -2
- package/__tests__/utils/__snapshots__/utils.test.ts.snap +2 -2
- package/__tests__/utils/utils.browser.test.ts +3 -5
- package/__tests__/utils/utils.test.ts +30 -5
- package/dist/provider/default.js +9 -1
- package/dist/provider/utils.js +1 -1
- package/dist/types/api.d.ts +7 -3
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.js +14 -1
- package/package.json +1 -1
- package/provider/default.js +11 -0
- package/provider/utils.js +1 -1
- package/src/provider/default.ts +9 -1
- package/src/provider/utils.ts +1 -1
- package/src/types/api.ts +11 -3
- package/src/utils/hash.ts +23 -1
- package/types/api.d.ts +10 -3
- package/utils/hash.d.ts +7 -0
- package/utils/hash.js +17 -1
- package/www/guides/account.md +4 -4
- package/__mocks__/ArgentAccount.json +0 -100369
- package/__mocks__/Readme.md +0 -2
|
@@ -8,21 +8,19 @@ import { constants, json, stark } from '../../src';
|
|
|
8
8
|
|
|
9
9
|
const { IS_BROWSER } = constants;
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
fs.readFileSync('./__mocks__/ArgentAccount.json').toString('ascii')
|
|
13
|
-
);
|
|
11
|
+
const compiledAccount = json.parse(fs.readFileSync('./__mocks__/Account.json').toString('ascii'));
|
|
14
12
|
|
|
15
13
|
test('isBrowser', () => {
|
|
16
14
|
expect(IS_BROWSER).toBe(true);
|
|
17
15
|
});
|
|
18
16
|
describe('compressProgram()', () => {
|
|
19
17
|
test('compresses a contract program', () => {
|
|
20
|
-
const compressed = stark.compressProgram(
|
|
18
|
+
const compressed = stark.compressProgram(compiledAccount.program);
|
|
21
19
|
|
|
22
20
|
expect(compressed).toMatchSnapshot();
|
|
23
21
|
});
|
|
24
22
|
test('works with strings', () => {
|
|
25
|
-
const inputProgram = json.stringify(
|
|
23
|
+
const inputProgram = json.stringify(compiledAccount.program);
|
|
26
24
|
|
|
27
25
|
const compressed = stark.compressProgram(inputProgram);
|
|
28
26
|
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
|
|
3
3
|
import { constants, hash, json, number, stark } from '../../src';
|
|
4
|
+
import { pedersen } from '../../src/utils/hash';
|
|
4
5
|
|
|
5
6
|
const { IS_BROWSER } = constants;
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
-
fs.readFileSync('./__mocks__/ArgentAccount.json').toString('ascii')
|
|
9
|
-
);
|
|
8
|
+
const compiledAccount = json.parse(fs.readFileSync('./__mocks__/Account.json').toString('ascii'));
|
|
10
9
|
|
|
11
10
|
test('isNode', () => {
|
|
12
11
|
expect(IS_BROWSER).toBe(false);
|
|
13
12
|
});
|
|
14
13
|
describe('compressProgram()', () => {
|
|
15
14
|
test('compresses a contract program', () => {
|
|
16
|
-
const inputProgram =
|
|
15
|
+
const inputProgram = compiledAccount.program;
|
|
17
16
|
|
|
18
17
|
const compressed = stark.compressProgram(inputProgram);
|
|
19
18
|
|
|
20
19
|
expect(compressed).toMatchSnapshot();
|
|
21
20
|
});
|
|
22
21
|
test('works with strings', () => {
|
|
23
|
-
const inputProgram = json.stringify(
|
|
22
|
+
const inputProgram = json.stringify(compiledAccount.program);
|
|
24
23
|
|
|
25
24
|
const compressed = stark.compressProgram(inputProgram);
|
|
26
25
|
|
|
@@ -87,3 +86,29 @@ describe('estimatedFeeToMaxFee()', () => {
|
|
|
87
86
|
expect(res).toBe(11_500);
|
|
88
87
|
});
|
|
89
88
|
});
|
|
89
|
+
|
|
90
|
+
describe('calculateContractAddressFromHash()', () => {
|
|
91
|
+
// This test just show how to use calculateContractAddressFromHash for new devs
|
|
92
|
+
|
|
93
|
+
test('calculated contract address should match the snapshot', () => {
|
|
94
|
+
const ethAddress = '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7';
|
|
95
|
+
|
|
96
|
+
const daiAddress = '0x03e85bfbb8e2a42b7bead9e88e9a1b19dbccf661471061807292120462396ec9';
|
|
97
|
+
const factoryAddress = '0x249827618A01858A72B7D04339C47195A324D20D6037033DFE2829F98AFF4FC';
|
|
98
|
+
const classHash = '0x55187E68C60664A947048E0C9E5322F9BF55F7D435ECDCF17ED75724E77368F';
|
|
99
|
+
|
|
100
|
+
// Any type of salt can be used. It depends on the dApp what kind of salt it wants to use.
|
|
101
|
+
const salt = pedersen([ethAddress, daiAddress]);
|
|
102
|
+
|
|
103
|
+
const res = hash.calculateContractAddressFromHash(
|
|
104
|
+
salt,
|
|
105
|
+
classHash,
|
|
106
|
+
[ethAddress, daiAddress, factoryAddress],
|
|
107
|
+
factoryAddress
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
expect(res).toMatchInlineSnapshot(
|
|
111
|
+
`"0x36dc8dcb3440596472ddde11facacc45d0cd250df764ae7c3d1a360c853c324"`
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
});
|
package/dist/provider/default.js
CHANGED
|
@@ -196,7 +196,12 @@ var Provider = /** @class */ (function () {
|
|
|
196
196
|
body: (0, json_1.stringify)(request),
|
|
197
197
|
headers: headers,
|
|
198
198
|
})
|
|
199
|
-
.then(function (res) {
|
|
199
|
+
.then(function (res) {
|
|
200
|
+
if (res.status >= 400) {
|
|
201
|
+
throw Error(res.statusText);
|
|
202
|
+
}
|
|
203
|
+
return res.text();
|
|
204
|
+
})
|
|
200
205
|
.then(function (res) {
|
|
201
206
|
if (endpoint === 'estimate_fee') {
|
|
202
207
|
return (0, json_1.parse)(res, function (_, v) {
|
|
@@ -207,6 +212,9 @@ var Provider = /** @class */ (function () {
|
|
|
207
212
|
});
|
|
208
213
|
}
|
|
209
214
|
return (0, json_1.parse)(res);
|
|
215
|
+
})
|
|
216
|
+
.catch(function (err) {
|
|
217
|
+
throw Error("Could not ".concat(method, " from endpoint `").concat(url, "`: ").concat(err.message));
|
|
210
218
|
})];
|
|
211
219
|
});
|
|
212
220
|
});
|
package/dist/provider/utils.js
CHANGED
|
@@ -42,7 +42,7 @@ function getBlockIdentifier(blockIdentifier) {
|
|
|
42
42
|
if (blockIdentifier === 'pending') {
|
|
43
43
|
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
44
44
|
}
|
|
45
|
-
if (typeof blockIdentifier === 'number') {
|
|
45
|
+
if (typeof blockIdentifier === 'number' || typeof blockIdentifier === 'bigint') {
|
|
46
46
|
return { type: 'BLOCK_NUMBER', data: blockIdentifier };
|
|
47
47
|
}
|
|
48
48
|
if (typeof blockIdentifier === 'string' && blockIdentifier.startsWith('0x')) {
|
package/dist/types/api.d.ts
CHANGED
|
@@ -109,6 +109,9 @@ export declare type InvokeFunctionTransaction = {
|
|
|
109
109
|
max_fee?: BigNumberish;
|
|
110
110
|
version?: BigNumberish;
|
|
111
111
|
};
|
|
112
|
+
export interface InvokeFunctionTransactionResponse extends InvokeFunctionTransaction {
|
|
113
|
+
transaction_hash: string;
|
|
114
|
+
}
|
|
112
115
|
export declare type InvokeFunctionTrace = {
|
|
113
116
|
caller_address: string;
|
|
114
117
|
contract_address: string;
|
|
@@ -135,6 +138,7 @@ export declare type ExecutionResources = {
|
|
|
135
138
|
};
|
|
136
139
|
export declare type CallContractTransaction = Omit<InvokeFunctionTransaction, 'type' | 'entry_point_type' | 'nonce'>;
|
|
137
140
|
export declare type Transaction = DeclareTransaction | DeployTransaction | InvokeFunctionTransaction;
|
|
141
|
+
export declare type TransactionResponse = DeclareTransaction | DeployTransaction | InvokeFunctionTransactionResponse;
|
|
138
142
|
export declare type CallContractResponse = {
|
|
139
143
|
result: string[];
|
|
140
144
|
};
|
|
@@ -143,7 +147,7 @@ export declare type GetBlockResponse = {
|
|
|
143
147
|
state_root: string;
|
|
144
148
|
block_hash: string;
|
|
145
149
|
transactions: {
|
|
146
|
-
[txHash: string]:
|
|
150
|
+
[txHash: string]: TransactionResponse;
|
|
147
151
|
};
|
|
148
152
|
timestamp: number;
|
|
149
153
|
transaction_receipts: {
|
|
@@ -193,7 +197,7 @@ export declare type GetTransactionTraceResponse = {
|
|
|
193
197
|
};
|
|
194
198
|
export declare type SuccessfulTransactionResponse = {
|
|
195
199
|
status: Status;
|
|
196
|
-
transaction:
|
|
200
|
+
transaction: TransactionResponse;
|
|
197
201
|
block_hash: string;
|
|
198
202
|
block_number: BlockNumber;
|
|
199
203
|
transaction_index: number;
|
|
@@ -204,7 +208,7 @@ export declare type FailedTransactionResponse = {
|
|
|
204
208
|
code: string;
|
|
205
209
|
error_message: string;
|
|
206
210
|
};
|
|
207
|
-
transaction:
|
|
211
|
+
transaction: TransactionResponse;
|
|
208
212
|
};
|
|
209
213
|
export declare type GetTransactionResponse = SuccessfulTransactionResponse | FailedTransactionResponse;
|
|
210
214
|
export declare type AddTransactionResponse = {
|
package/dist/utils/hash.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import BN from 'bn.js';
|
|
2
2
|
import { StarknetChainId, TransactionHashPrefix } from '../constants';
|
|
3
|
+
import { RawCalldata } from '../types/lib';
|
|
3
4
|
import { BigNumberish } from './number';
|
|
4
5
|
export declare const transactionVersion = 0;
|
|
5
6
|
export declare const feeTransactionVersion: BN;
|
|
@@ -24,3 +25,4 @@ export declare function computeHashOnElements(data: BigNumberish[]): string;
|
|
|
24
25
|
export declare function calculateTransactionHashCommon(txHashPrefix: TransactionHashPrefix, version: BigNumberish, contractAddress: BigNumberish, entryPointSelector: BigNumberish, calldata: BigNumberish[], maxFee: BigNumberish, chainId: StarknetChainId, additionalData?: BigNumberish[]): string;
|
|
25
26
|
export declare function calculateDeployTransactionHash(contractAddress: BigNumberish, constructorCalldata: BigNumberish[], version: BigNumberish, chainId: StarknetChainId): string;
|
|
26
27
|
export declare function calculcateTransactionHash(contractAddress: BigNumberish, version: BigNumberish, entryPointSelector: BigNumberish, calldata: BigNumberish[], maxFee: BigNumberish, chainId: StarknetChainId): string;
|
|
28
|
+
export declare function calculateContractAddressFromHash(salt: BigNumberish, classHash: BigNumberish, constructorCalldata: RawCalldata, deployerAddress: BigNumberish): string;
|
package/dist/utils/hash.js
CHANGED
|
@@ -28,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
29
|
};
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.calculcateTransactionHash = exports.calculateDeployTransactionHash = exports.calculateTransactionHashCommon = exports.computeHashOnElements = exports.pedersen = exports.getSelectorFromName = exports.starknetKeccak = exports.feeTransactionVersion = exports.transactionVersion = void 0;
|
|
31
|
+
exports.calculateContractAddressFromHash = exports.calculcateTransactionHash = exports.calculateDeployTransactionHash = exports.calculateTransactionHashCommon = exports.computeHashOnElements = exports.pedersen = exports.getSelectorFromName = exports.starknetKeccak = exports.feeTransactionVersion = exports.transactionVersion = void 0;
|
|
32
32
|
var keccak_1 = require("ethereum-cryptography/keccak");
|
|
33
33
|
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
34
34
|
var constants_1 = require("../constants");
|
|
@@ -112,3 +112,16 @@ function calculcateTransactionHash(contractAddress, version, entryPointSelector,
|
|
|
112
112
|
return calculateTransactionHashCommon(constants_1.TransactionHashPrefix.INVOKE, version, contractAddress, entryPointSelector, calldata, maxFee, chainId);
|
|
113
113
|
}
|
|
114
114
|
exports.calculcateTransactionHash = calculcateTransactionHash;
|
|
115
|
+
function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
|
|
116
|
+
var constructorCalldataHash = computeHashOnElements(constructorCalldata);
|
|
117
|
+
var CONTRACT_ADDRESS_PREFIX = (0, number_1.toFelt)('0x535441524b4e45545f434f4e54524143545f41444452455353'); // Equivalent to 'STARKNET_CONTRACT_ADDRESS'
|
|
118
|
+
var dataToHash = [
|
|
119
|
+
CONTRACT_ADDRESS_PREFIX,
|
|
120
|
+
deployerAddress,
|
|
121
|
+
salt,
|
|
122
|
+
classHash,
|
|
123
|
+
constructorCalldataHash,
|
|
124
|
+
];
|
|
125
|
+
return computeHashOnElements(dataToHash);
|
|
126
|
+
}
|
|
127
|
+
exports.calculateContractAddressFromHash = calculateContractAddressFromHash;
|
package/package.json
CHANGED
package/provider/default.js
CHANGED
|
@@ -314,6 +314,9 @@ var Provider = /** @class */ (function () {
|
|
|
314
314
|
headers: headers,
|
|
315
315
|
})
|
|
316
316
|
.then(function (res) {
|
|
317
|
+
if (res.status >= 400) {
|
|
318
|
+
throw Error(res.statusText);
|
|
319
|
+
}
|
|
317
320
|
return res.text();
|
|
318
321
|
})
|
|
319
322
|
.then(function (res) {
|
|
@@ -326,6 +329,14 @@ var Provider = /** @class */ (function () {
|
|
|
326
329
|
});
|
|
327
330
|
}
|
|
328
331
|
return (0, json_1.parse)(res);
|
|
332
|
+
})
|
|
333
|
+
.catch(function (err) {
|
|
334
|
+
throw Error(
|
|
335
|
+
'Could not '
|
|
336
|
+
.concat(method, ' from endpoint `')
|
|
337
|
+
.concat(url, '`: ')
|
|
338
|
+
.concat(err.message)
|
|
339
|
+
);
|
|
329
340
|
}),
|
|
330
341
|
];
|
|
331
342
|
});
|
package/provider/utils.js
CHANGED
|
@@ -45,7 +45,7 @@ function getBlockIdentifier(blockIdentifier) {
|
|
|
45
45
|
if (blockIdentifier === 'pending') {
|
|
46
46
|
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
47
47
|
}
|
|
48
|
-
if (typeof blockIdentifier === 'number') {
|
|
48
|
+
if (typeof blockIdentifier === 'number' || typeof blockIdentifier === 'bigint') {
|
|
49
49
|
return { type: 'BLOCK_NUMBER', data: blockIdentifier };
|
|
50
50
|
}
|
|
51
51
|
if (typeof blockIdentifier === 'string' && blockIdentifier.startsWith('0x')) {
|
package/src/provider/default.ts
CHANGED
|
@@ -159,7 +159,12 @@ export class Provider implements ProviderInterface {
|
|
|
159
159
|
body: stringify(request),
|
|
160
160
|
headers,
|
|
161
161
|
})
|
|
162
|
-
.then((res) =>
|
|
162
|
+
.then((res) => {
|
|
163
|
+
if (res.status >= 400) {
|
|
164
|
+
throw Error(res.statusText);
|
|
165
|
+
}
|
|
166
|
+
return res.text();
|
|
167
|
+
})
|
|
163
168
|
.then((res) => {
|
|
164
169
|
if (endpoint === 'estimate_fee') {
|
|
165
170
|
return parse(res, (_, v) => {
|
|
@@ -170,6 +175,9 @@ export class Provider implements ProviderInterface {
|
|
|
170
175
|
});
|
|
171
176
|
}
|
|
172
177
|
return parse(res) as Endpoints[T]['RESPONSE'];
|
|
178
|
+
})
|
|
179
|
+
.catch((err) => {
|
|
180
|
+
throw Error(`Could not ${method} from endpoint \`${url}\`: ${err.message}`);
|
|
173
181
|
});
|
|
174
182
|
}
|
|
175
183
|
|
package/src/provider/utils.ts
CHANGED
|
@@ -49,7 +49,7 @@ export function getBlockIdentifier(blockIdentifier: BlockIdentifier): BlockIdent
|
|
|
49
49
|
if (blockIdentifier === 'pending') {
|
|
50
50
|
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
51
51
|
}
|
|
52
|
-
if (typeof blockIdentifier === 'number') {
|
|
52
|
+
if (typeof blockIdentifier === 'number' || typeof blockIdentifier === 'bigint') {
|
|
53
53
|
return { type: 'BLOCK_NUMBER', data: blockIdentifier };
|
|
54
54
|
}
|
|
55
55
|
if (typeof blockIdentifier === 'string' && blockIdentifier.startsWith('0x')) {
|
package/src/types/api.ts
CHANGED
|
@@ -125,6 +125,10 @@ export type InvokeFunctionTransaction = {
|
|
|
125
125
|
version?: BigNumberish;
|
|
126
126
|
};
|
|
127
127
|
|
|
128
|
+
export interface InvokeFunctionTransactionResponse extends InvokeFunctionTransaction {
|
|
129
|
+
transaction_hash: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
128
132
|
export type InvokeFunctionTrace = {
|
|
129
133
|
caller_address: string;
|
|
130
134
|
contract_address: string;
|
|
@@ -157,6 +161,10 @@ export type CallContractTransaction = Omit<
|
|
|
157
161
|
>;
|
|
158
162
|
|
|
159
163
|
export type Transaction = DeclareTransaction | DeployTransaction | InvokeFunctionTransaction;
|
|
164
|
+
export type TransactionResponse =
|
|
165
|
+
| DeclareTransaction
|
|
166
|
+
| DeployTransaction
|
|
167
|
+
| InvokeFunctionTransactionResponse;
|
|
160
168
|
|
|
161
169
|
export type CallContractResponse = {
|
|
162
170
|
result: string[];
|
|
@@ -167,7 +175,7 @@ export type GetBlockResponse = {
|
|
|
167
175
|
state_root: string;
|
|
168
176
|
block_hash: string;
|
|
169
177
|
transactions: {
|
|
170
|
-
[txHash: string]:
|
|
178
|
+
[txHash: string]: TransactionResponse;
|
|
171
179
|
};
|
|
172
180
|
timestamp: number;
|
|
173
181
|
transaction_receipts: {
|
|
@@ -221,7 +229,7 @@ export type GetTransactionTraceResponse = {
|
|
|
221
229
|
|
|
222
230
|
export type SuccessfulTransactionResponse = {
|
|
223
231
|
status: Status;
|
|
224
|
-
transaction:
|
|
232
|
+
transaction: TransactionResponse;
|
|
225
233
|
block_hash: string;
|
|
226
234
|
block_number: BlockNumber;
|
|
227
235
|
transaction_index: number;
|
|
@@ -233,7 +241,7 @@ export type FailedTransactionResponse = {
|
|
|
233
241
|
code: string;
|
|
234
242
|
error_message: string;
|
|
235
243
|
};
|
|
236
|
-
transaction:
|
|
244
|
+
transaction: TransactionResponse;
|
|
237
245
|
};
|
|
238
246
|
|
|
239
247
|
export type GetTransactionResponse = SuccessfulTransactionResponse | FailedTransactionResponse;
|
package/src/utils/hash.ts
CHANGED
|
@@ -11,9 +11,10 @@ import {
|
|
|
11
11
|
TransactionHashPrefix,
|
|
12
12
|
ZERO,
|
|
13
13
|
} from '../constants';
|
|
14
|
+
import { RawCalldata } from '../types/lib';
|
|
14
15
|
import { ec } from './ellipticCurve';
|
|
15
16
|
import { addHexPrefix, buf2hex, utf8ToArray } from './encode';
|
|
16
|
-
import { BigNumberish, toBN, toHex } from './number';
|
|
17
|
+
import { BigNumberish, toBN, toFelt, toHex } from './number';
|
|
17
18
|
|
|
18
19
|
export const transactionVersion = 0;
|
|
19
20
|
export const feeTransactionVersion = toBN(2).pow(toBN(128)).add(toBN(transactionVersion));
|
|
@@ -132,3 +133,24 @@ export function calculcateTransactionHash(
|
|
|
132
133
|
chainId
|
|
133
134
|
);
|
|
134
135
|
}
|
|
136
|
+
|
|
137
|
+
export function calculateContractAddressFromHash(
|
|
138
|
+
salt: BigNumberish,
|
|
139
|
+
classHash: BigNumberish,
|
|
140
|
+
constructorCalldata: RawCalldata,
|
|
141
|
+
deployerAddress: BigNumberish
|
|
142
|
+
) {
|
|
143
|
+
const constructorCalldataHash = computeHashOnElements(constructorCalldata);
|
|
144
|
+
|
|
145
|
+
const CONTRACT_ADDRESS_PREFIX = toFelt('0x535441524b4e45545f434f4e54524143545f41444452455353'); // Equivalent to 'STARKNET_CONTRACT_ADDRESS'
|
|
146
|
+
|
|
147
|
+
const dataToHash = [
|
|
148
|
+
CONTRACT_ADDRESS_PREFIX,
|
|
149
|
+
deployerAddress,
|
|
150
|
+
salt,
|
|
151
|
+
classHash,
|
|
152
|
+
constructorCalldataHash,
|
|
153
|
+
];
|
|
154
|
+
|
|
155
|
+
return computeHashOnElements(dataToHash);
|
|
156
|
+
}
|
package/types/api.d.ts
CHANGED
|
@@ -119,6 +119,9 @@ export declare type InvokeFunctionTransaction = {
|
|
|
119
119
|
max_fee?: BigNumberish;
|
|
120
120
|
version?: BigNumberish;
|
|
121
121
|
};
|
|
122
|
+
export interface InvokeFunctionTransactionResponse extends InvokeFunctionTransaction {
|
|
123
|
+
transaction_hash: string;
|
|
124
|
+
}
|
|
122
125
|
export declare type InvokeFunctionTrace = {
|
|
123
126
|
caller_address: string;
|
|
124
127
|
contract_address: string;
|
|
@@ -151,6 +154,10 @@ export declare type Transaction =
|
|
|
151
154
|
| DeclareTransaction
|
|
152
155
|
| DeployTransaction
|
|
153
156
|
| InvokeFunctionTransaction;
|
|
157
|
+
export declare type TransactionResponse =
|
|
158
|
+
| DeclareTransaction
|
|
159
|
+
| DeployTransaction
|
|
160
|
+
| InvokeFunctionTransactionResponse;
|
|
154
161
|
export declare type CallContractResponse = {
|
|
155
162
|
result: string[];
|
|
156
163
|
};
|
|
@@ -159,7 +166,7 @@ export declare type GetBlockResponse = {
|
|
|
159
166
|
state_root: string;
|
|
160
167
|
block_hash: string;
|
|
161
168
|
transactions: {
|
|
162
|
-
[txHash: string]:
|
|
169
|
+
[txHash: string]: TransactionResponse;
|
|
163
170
|
};
|
|
164
171
|
timestamp: number;
|
|
165
172
|
transaction_receipts: {
|
|
@@ -209,7 +216,7 @@ export declare type GetTransactionTraceResponse = {
|
|
|
209
216
|
};
|
|
210
217
|
export declare type SuccessfulTransactionResponse = {
|
|
211
218
|
status: Status;
|
|
212
|
-
transaction:
|
|
219
|
+
transaction: TransactionResponse;
|
|
213
220
|
block_hash: string;
|
|
214
221
|
block_number: BlockNumber;
|
|
215
222
|
transaction_index: number;
|
|
@@ -220,7 +227,7 @@ export declare type FailedTransactionResponse = {
|
|
|
220
227
|
code: string;
|
|
221
228
|
error_message: string;
|
|
222
229
|
};
|
|
223
|
-
transaction:
|
|
230
|
+
transaction: TransactionResponse;
|
|
224
231
|
};
|
|
225
232
|
export declare type GetTransactionResponse =
|
|
226
233
|
| SuccessfulTransactionResponse
|
package/utils/hash.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import BN from 'bn.js';
|
|
2
2
|
|
|
3
3
|
import { StarknetChainId, TransactionHashPrefix } from '../constants';
|
|
4
|
+
import { RawCalldata } from '../types/lib';
|
|
4
5
|
import { BigNumberish } from './number';
|
|
5
6
|
export declare const transactionVersion = 0;
|
|
6
7
|
export declare const feeTransactionVersion: BN;
|
|
@@ -46,3 +47,9 @@ export declare function calculcateTransactionHash(
|
|
|
46
47
|
maxFee: BigNumberish,
|
|
47
48
|
chainId: StarknetChainId
|
|
48
49
|
): string;
|
|
50
|
+
export declare function calculateContractAddressFromHash(
|
|
51
|
+
salt: BigNumberish,
|
|
52
|
+
classHash: BigNumberish,
|
|
53
|
+
constructorCalldata: RawCalldata,
|
|
54
|
+
deployerAddress: BigNumberish
|
|
55
|
+
): string;
|
package/utils/hash.js
CHANGED
|
@@ -39,7 +39,8 @@ var __importDefault =
|
|
|
39
39
|
return mod && mod.__esModule ? mod : { default: mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
42
|
-
exports.
|
|
42
|
+
exports.calculateContractAddressFromHash =
|
|
43
|
+
exports.calculcateTransactionHash =
|
|
43
44
|
exports.calculateDeployTransactionHash =
|
|
44
45
|
exports.calculateTransactionHashCommon =
|
|
45
46
|
exports.computeHashOnElements =
|
|
@@ -174,3 +175,18 @@ function calculcateTransactionHash(
|
|
|
174
175
|
);
|
|
175
176
|
}
|
|
176
177
|
exports.calculcateTransactionHash = calculcateTransactionHash;
|
|
178
|
+
function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
|
|
179
|
+
var constructorCalldataHash = computeHashOnElements(constructorCalldata);
|
|
180
|
+
var CONTRACT_ADDRESS_PREFIX = (0, number_1.toFelt)(
|
|
181
|
+
'0x535441524b4e45545f434f4e54524143545f41444452455353'
|
|
182
|
+
); // Equivalent to 'STARKNET_CONTRACT_ADDRESS'
|
|
183
|
+
var dataToHash = [
|
|
184
|
+
CONTRACT_ADDRESS_PREFIX,
|
|
185
|
+
deployerAddress,
|
|
186
|
+
salt,
|
|
187
|
+
classHash,
|
|
188
|
+
constructorCalldataHash,
|
|
189
|
+
];
|
|
190
|
+
return computeHashOnElements(dataToHash);
|
|
191
|
+
}
|
|
192
|
+
exports.calculateContractAddressFromHash = calculateContractAddressFromHash;
|
package/www/guides/account.md
CHANGED
|
@@ -39,11 +39,11 @@ const starkKeyPub = ec.getStarkKey(starkKeyPair);;
|
|
|
39
39
|
Deploy the Account contract and wait for it to be verified on StarkNet.
|
|
40
40
|
|
|
41
41
|
```javascript
|
|
42
|
-
const
|
|
43
|
-
fs.readFileSync("./
|
|
42
|
+
const compiledAccount = json.parse(
|
|
43
|
+
fs.readFileSync("./Account.json").toString("ascii")
|
|
44
44
|
);
|
|
45
45
|
const accountResponse = await defaultProvider.deployContract({
|
|
46
|
-
contract:
|
|
46
|
+
contract: compiledAccount,
|
|
47
47
|
addressSalt: starkKeyPub,
|
|
48
48
|
});
|
|
49
49
|
```
|
|
@@ -55,7 +55,7 @@ Wait for the deployment transaction to be accepted and assign the address of the
|
|
|
55
55
|
```javascript
|
|
56
56
|
await defaultProvider.waitForTransaction(accountResponse.transaction_hash);
|
|
57
57
|
const accountContract = new Contract(
|
|
58
|
-
|
|
58
|
+
compiledAccount.abi,
|
|
59
59
|
accountResponse.address
|
|
60
60
|
);
|
|
61
61
|
const initializeResponse = await accountContract.initialize(starkKeyPub, "0");
|