starknet 4.6.0 → 4.7.0
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 +25 -0
- package/__tests__/account.test.ts +2 -5
- package/__tests__/contract.test.ts +0 -1
- package/__tests__/defaultProvider.test.ts +9 -1
- package/__tests__/sequencerProvider.test.ts +10 -8
- package/__tests__/utils/ellipticalCurve.test.ts +7 -8
- package/account/default.d.ts +3 -2
- package/account/default.js +22 -29
- package/account/interface.d.ts +2 -1
- package/contract/contractFactory.d.ts +1 -2
- package/contract/default.d.ts +2 -2
- package/contract/default.js +7 -3
- package/dist/account/default.d.ts +3 -2
- package/dist/account/default.js +22 -29
- package/dist/account/interface.d.ts +2 -1
- package/dist/contract/contractFactory.d.ts +1 -2
- package/dist/contract/default.d.ts +2 -2
- package/dist/contract/default.js +7 -3
- package/dist/provider/default.d.ts +4 -3
- package/dist/provider/default.js +9 -3
- package/dist/provider/interface.d.ts +10 -3
- package/dist/provider/rpc.d.ts +12 -10
- package/dist/provider/rpc.js +80 -72
- package/dist/provider/sequencer.d.ts +4 -3
- package/dist/provider/sequencer.js +14 -6
- package/dist/signer/default.d.ts +2 -2
- package/dist/signer/default.js +2 -2
- package/dist/signer/interface.d.ts +2 -2
- package/dist/types/api/openrpc.d.ts +17 -27
- package/dist/types/api/rpc.d.ts +4 -128
- package/dist/types/api/sequencer.d.ts +15 -4
- package/dist/types/lib.d.ts +10 -4
- package/dist/types/provider.d.ts +3 -2
- package/dist/utils/hash.d.ts +2 -2
- package/dist/utils/hash.js +5 -5
- package/dist/utils/responseParser/rpc.d.ts +2 -5
- package/dist/utils/responseParser/rpc.js +2 -38
- package/package.json +1 -1
- package/provider/default.d.ts +4 -3
- package/provider/default.js +9 -3
- package/provider/interface.d.ts +10 -3
- package/provider/rpc.d.ts +12 -10
- package/provider/rpc.js +80 -72
- package/provider/sequencer.d.ts +4 -3
- package/provider/sequencer.js +14 -6
- package/signer/default.d.ts +2 -2
- package/signer/default.js +2 -2
- package/signer/interface.d.ts +2 -2
- package/src/account/default.ts +21 -20
- package/src/account/interface.ts +2 -1
- package/src/contract/contractFactory.ts +1 -2
- package/src/contract/default.ts +16 -8
- package/src/provider/default.ts +12 -5
- package/src/provider/interface.ts +15 -4
- package/src/provider/rpc.ts +89 -73
- package/src/provider/sequencer.ts +16 -8
- package/src/signer/default.ts +8 -8
- package/src/signer/interface.ts +2 -2
- package/src/types/api/openrpc.ts +20 -25
- package/src/types/api/rpc.ts +4 -128
- package/src/types/api/sequencer.ts +17 -4
- package/src/types/lib.ts +7 -5
- package/src/types/provider.ts +3 -2
- package/src/utils/hash.ts +7 -6
- package/src/utils/responseParser/rpc.ts +7 -25
- package/types/api/openrpc.d.ts +17 -27
- package/types/api/rpc.d.ts +4 -128
- package/types/api/sequencer.d.ts +15 -4
- package/types/lib.d.ts +10 -4
- package/types/provider.d.ts +3 -2
- package/utils/hash.d.ts +2 -2
- package/utils/hash.js +5 -5
- package/utils/responseParser/rpc.d.ts +2 -5
- package/utils/responseParser/rpc.js +2 -38
- package/www/docs/API/account.md +3 -3
- package/www/docs/API/contract.md +2 -2
- package/www/docs/API/provider.md +6 -0
- package/www/docs/API/utils.md +2 -2
package/src/account/interface.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ProviderInterface } from '../provider';
|
|
2
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
2
3
|
import { SignerInterface } from '../signer';
|
|
3
4
|
import {
|
|
4
5
|
Abi,
|
|
@@ -92,5 +93,5 @@ export abstract class AccountInterface extends ProviderInterface {
|
|
|
92
93
|
*/
|
|
93
94
|
public abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
|
|
94
95
|
|
|
95
|
-
public abstract getNonce(): Promise<
|
|
96
|
+
public abstract getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
96
97
|
}
|
|
@@ -3,7 +3,6 @@ import assert from 'minimalistic-assert';
|
|
|
3
3
|
import { AccountInterface } from '../account';
|
|
4
4
|
import { ProviderInterface, defaultProvider } from '../provider';
|
|
5
5
|
import { Abi, CompiledContract, RawCalldata } from '../types';
|
|
6
|
-
import { BigNumberish } from '../utils/number';
|
|
7
6
|
import { Contract } from './default';
|
|
8
7
|
|
|
9
8
|
export class ContractFactory {
|
|
@@ -32,7 +31,7 @@ export class ContractFactory {
|
|
|
32
31
|
*/
|
|
33
32
|
public async deploy(
|
|
34
33
|
constructorCalldata?: RawCalldata,
|
|
35
|
-
addressSalt?:
|
|
34
|
+
addressSalt?: string | undefined
|
|
36
35
|
): Promise<Contract> {
|
|
37
36
|
const { contract_address, transaction_hash } = await this.providerOrAccount.deployContract({
|
|
38
37
|
contract: this.compiledContract,
|
package/src/contract/default.ts
CHANGED
|
@@ -9,10 +9,10 @@ import {
|
|
|
9
9
|
AbiEntry,
|
|
10
10
|
Args,
|
|
11
11
|
AsyncContractFunction,
|
|
12
|
+
Call,
|
|
12
13
|
Calldata,
|
|
13
14
|
ContractFunction,
|
|
14
15
|
FunctionAbi,
|
|
15
|
-
Invocation,
|
|
16
16
|
InvokeFunctionResponse,
|
|
17
17
|
Overrides,
|
|
18
18
|
ParsedStruct,
|
|
@@ -125,7 +125,7 @@ export class Contract implements ContractInterface {
|
|
|
125
125
|
address: string,
|
|
126
126
|
providerOrAccount: ProviderInterface | AccountInterface = defaultProvider
|
|
127
127
|
) {
|
|
128
|
-
this.address = address;
|
|
128
|
+
this.address = address.toLowerCase();
|
|
129
129
|
this.providerOrAccount = providerOrAccount;
|
|
130
130
|
this.abi = abi;
|
|
131
131
|
this.structs = abi
|
|
@@ -578,13 +578,22 @@ export class Contract implements ContractInterface {
|
|
|
578
578
|
});
|
|
579
579
|
}
|
|
580
580
|
|
|
581
|
+
if (!options.nonce) {
|
|
582
|
+
throw new Error(`Nonce is required when invoking a function without an account`);
|
|
583
|
+
}
|
|
584
|
+
|
|
581
585
|
// eslint-disable-next-line no-console
|
|
582
586
|
console.warn(`Invoking ${method} without an account. This will not work on a public node.`);
|
|
583
587
|
|
|
584
|
-
return this.providerOrAccount.invokeFunction(
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
+
return this.providerOrAccount.invokeFunction(
|
|
589
|
+
{
|
|
590
|
+
...invocation,
|
|
591
|
+
signature: options.signature || [],
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
nonce: options.nonce,
|
|
595
|
+
}
|
|
596
|
+
);
|
|
588
597
|
}
|
|
589
598
|
|
|
590
599
|
public async call(
|
|
@@ -630,13 +639,12 @@ export class Contract implements ContractInterface {
|
|
|
630
639
|
throw Error('Contract must be connected to the account contract to estimate');
|
|
631
640
|
}
|
|
632
641
|
|
|
633
|
-
public populate(method: string, args: Array<any> = []):
|
|
642
|
+
public populate(method: string, args: Array<any> = []): Call {
|
|
634
643
|
const { inputs } = this.abi.find((abi) => abi.name === method) as FunctionAbi;
|
|
635
644
|
return {
|
|
636
645
|
contractAddress: this.address,
|
|
637
646
|
entrypoint: method,
|
|
638
647
|
calldata: this.compileCalldata(args, inputs),
|
|
639
|
-
signature: [],
|
|
640
648
|
};
|
|
641
649
|
}
|
|
642
650
|
}
|
package/src/provider/default.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
GetTransactionReceiptResponse,
|
|
14
14
|
GetTransactionResponse,
|
|
15
15
|
Invocation,
|
|
16
|
-
|
|
16
|
+
InvocationsDetailsWithNonce,
|
|
17
17
|
InvokeFunctionResponse,
|
|
18
18
|
} from '../types';
|
|
19
19
|
import { BigNumberish } from '../utils/number';
|
|
@@ -63,10 +63,17 @@ export class Provider implements ProviderInterface {
|
|
|
63
63
|
|
|
64
64
|
public async getEstimateFee(
|
|
65
65
|
invocation: Invocation,
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
invocationDetails: InvocationsDetailsWithNonce,
|
|
67
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
68
68
|
): Promise<EstimateFeeResponse> {
|
|
69
|
-
return this.provider.getEstimateFee(invocation,
|
|
69
|
+
return this.provider.getEstimateFee(invocation, invocationDetails, blockIdentifier);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public async getNonce(
|
|
73
|
+
contractAddress: string,
|
|
74
|
+
blockIdentifier?: BlockIdentifier
|
|
75
|
+
): Promise<BigNumberish> {
|
|
76
|
+
return this.provider.getNonce(contractAddress, blockIdentifier);
|
|
70
77
|
}
|
|
71
78
|
|
|
72
79
|
public async getStorageAt(
|
|
@@ -94,7 +101,7 @@ export class Provider implements ProviderInterface {
|
|
|
94
101
|
|
|
95
102
|
public async invokeFunction(
|
|
96
103
|
functionInvocation: Invocation,
|
|
97
|
-
details:
|
|
104
|
+
details: InvocationsDetailsWithNonce
|
|
98
105
|
): Promise<InvokeFunctionResponse> {
|
|
99
106
|
return this.provider.invokeFunction(functionInvocation, details);
|
|
100
107
|
}
|
|
@@ -13,7 +13,7 @@ import type {
|
|
|
13
13
|
GetTransactionReceiptResponse,
|
|
14
14
|
GetTransactionResponse,
|
|
15
15
|
Invocation,
|
|
16
|
-
|
|
16
|
+
InvocationsDetailsWithNonce,
|
|
17
17
|
InvokeFunctionResponse,
|
|
18
18
|
} from '../types';
|
|
19
19
|
import type { BigNumberish } from '../utils/number';
|
|
@@ -69,6 +69,17 @@ export abstract class ProviderInterface {
|
|
|
69
69
|
blockIdentifier?: BlockIdentifier
|
|
70
70
|
): Promise<ContractClass>;
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Gets the nonce of a contract with respect to a specific block
|
|
74
|
+
*
|
|
75
|
+
* @param contractAddress - contract address
|
|
76
|
+
* @returns the hex nonce
|
|
77
|
+
*/
|
|
78
|
+
public abstract getNonce(
|
|
79
|
+
contractAddress: string,
|
|
80
|
+
blockIdentifier?: BlockIdentifier
|
|
81
|
+
): Promise<BigNumberish>;
|
|
82
|
+
|
|
72
83
|
/**
|
|
73
84
|
* Gets the contract's storage variable at a specific key.
|
|
74
85
|
*
|
|
@@ -141,7 +152,7 @@ export abstract class ProviderInterface {
|
|
|
141
152
|
*/
|
|
142
153
|
public abstract invokeFunction(
|
|
143
154
|
invocation: Invocation,
|
|
144
|
-
details
|
|
155
|
+
details: InvocationsDetailsWithNonce
|
|
145
156
|
): Promise<InvokeFunctionResponse>;
|
|
146
157
|
|
|
147
158
|
/**
|
|
@@ -160,8 +171,8 @@ export abstract class ProviderInterface {
|
|
|
160
171
|
*/
|
|
161
172
|
public abstract getEstimateFee(
|
|
162
173
|
invocation: Invocation,
|
|
163
|
-
|
|
164
|
-
|
|
174
|
+
details: InvocationsDetailsWithNonce,
|
|
175
|
+
blockIdentifier: BlockIdentifier
|
|
165
176
|
): Promise<EstimateFeeResponse>;
|
|
166
177
|
|
|
167
178
|
/**
|
package/src/provider/rpc.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
GetTransactionReceiptResponse,
|
|
13
13
|
GetTransactionResponse,
|
|
14
14
|
Invocation,
|
|
15
|
-
|
|
15
|
+
InvocationsDetailsWithNonce,
|
|
16
16
|
InvokeFunctionResponse,
|
|
17
17
|
} from '../types';
|
|
18
18
|
import { RPC } from '../types/api';
|
|
@@ -31,7 +31,10 @@ import { randomAddress } from '../utils/stark';
|
|
|
31
31
|
import { ProviderInterface } from './interface';
|
|
32
32
|
import { Block, BlockIdentifier } from './utils';
|
|
33
33
|
|
|
34
|
-
export type RpcProviderOptions = {
|
|
34
|
+
export type RpcProviderOptions = {
|
|
35
|
+
nodeUrl: string;
|
|
36
|
+
retries?: number;
|
|
37
|
+
};
|
|
35
38
|
|
|
36
39
|
export class RpcProvider implements ProviderInterface {
|
|
37
40
|
public nodeUrl: string;
|
|
@@ -41,9 +44,12 @@ export class RpcProvider implements ProviderInterface {
|
|
|
41
44
|
|
|
42
45
|
private responseParser = new RPCResponseParser();
|
|
43
46
|
|
|
47
|
+
private retries: number;
|
|
48
|
+
|
|
44
49
|
constructor(optionsOrProvider: RpcProviderOptions) {
|
|
45
|
-
const { nodeUrl } = optionsOrProvider;
|
|
50
|
+
const { nodeUrl, retries } = optionsOrProvider;
|
|
46
51
|
this.nodeUrl = nodeUrl;
|
|
52
|
+
this.retries = retries || 200;
|
|
47
53
|
|
|
48
54
|
this.getChainId().then((chainId) => {
|
|
49
55
|
this.chainId = chainId;
|
|
@@ -67,13 +73,13 @@ export class RpcProvider implements ProviderInterface {
|
|
|
67
73
|
|
|
68
74
|
protected async fetchEndpoint<T extends keyof RPC.Methods>(
|
|
69
75
|
method: T,
|
|
70
|
-
|
|
71
|
-
): Promise<RPC.Methods[T]['
|
|
76
|
+
params?: RPC.Methods[T]['params']
|
|
77
|
+
): Promise<RPC.Methods[T]['result']> {
|
|
72
78
|
try {
|
|
73
|
-
const rawResult = await this.fetch(method,
|
|
79
|
+
const rawResult = await this.fetch(method, params);
|
|
74
80
|
const { error, result } = await rawResult.json();
|
|
75
81
|
this.errorHandler(error);
|
|
76
|
-
return result as RPC.Methods[T]['
|
|
82
|
+
return result as RPC.Methods[T]['result'];
|
|
77
83
|
} catch (error: any) {
|
|
78
84
|
this.errorHandler(error?.response?.data);
|
|
79
85
|
throw error;
|
|
@@ -99,27 +105,37 @@ export class RpcProvider implements ProviderInterface {
|
|
|
99
105
|
public async getBlockWithTxHashes(
|
|
100
106
|
blockIdentifier: BlockIdentifier = 'pending'
|
|
101
107
|
): Promise<RPC.GetBlockWithTxHashesResponse> {
|
|
102
|
-
const
|
|
103
|
-
return this.fetchEndpoint('starknet_getBlockWithTxHashes',
|
|
108
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
109
|
+
return this.fetchEndpoint('starknet_getBlockWithTxHashes', { block_id });
|
|
104
110
|
}
|
|
105
111
|
|
|
106
112
|
public async getBlockWithTxs(
|
|
107
113
|
blockIdentifier: BlockIdentifier = 'pending'
|
|
108
114
|
): Promise<RPC.GetBlockWithTxs> {
|
|
109
|
-
const
|
|
110
|
-
return this.fetchEndpoint('starknet_getBlockWithTxs',
|
|
115
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
116
|
+
return this.fetchEndpoint('starknet_getBlockWithTxs', { block_id });
|
|
111
117
|
}
|
|
112
118
|
|
|
113
119
|
public async getClassHashAt(
|
|
114
120
|
blockIdentifier: BlockIdentifier,
|
|
115
121
|
contractAddress: RPC.ContractAddress
|
|
116
122
|
): Promise<RPC.Felt> {
|
|
117
|
-
const
|
|
118
|
-
return this.fetchEndpoint('starknet_getClassHashAt',
|
|
123
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
124
|
+
return this.fetchEndpoint('starknet_getClassHashAt', {
|
|
125
|
+
block_id,
|
|
126
|
+
contract_address: contractAddress,
|
|
127
|
+
});
|
|
119
128
|
}
|
|
120
129
|
|
|
121
|
-
public async getNonce(
|
|
122
|
-
|
|
130
|
+
public async getNonce(
|
|
131
|
+
contractAddress: string,
|
|
132
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
133
|
+
): Promise<RPC.Nonce> {
|
|
134
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
135
|
+
return this.fetchEndpoint('starknet_getNonce', {
|
|
136
|
+
contract_address: contractAddress,
|
|
137
|
+
block_id,
|
|
138
|
+
});
|
|
123
139
|
}
|
|
124
140
|
|
|
125
141
|
public async getPendingTransactions(): Promise<RPC.PendingTransactions> {
|
|
@@ -131,8 +147,8 @@ export class RpcProvider implements ProviderInterface {
|
|
|
131
147
|
}
|
|
132
148
|
|
|
133
149
|
public async getStateUpdate(blockIdentifier: BlockIdentifier): Promise<RPC.StateUpdate> {
|
|
134
|
-
const
|
|
135
|
-
return this.fetchEndpoint('starknet_getStateUpdate',
|
|
150
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
151
|
+
return this.fetchEndpoint('starknet_getStateUpdate', { block_id });
|
|
136
152
|
}
|
|
137
153
|
|
|
138
154
|
public async getStorageAt(
|
|
@@ -141,49 +157,50 @@ export class RpcProvider implements ProviderInterface {
|
|
|
141
157
|
blockIdentifier: BlockIdentifier = 'pending'
|
|
142
158
|
): Promise<BigNumberish> {
|
|
143
159
|
const parsedKey = toHex(toBN(key));
|
|
144
|
-
const
|
|
145
|
-
return this.fetchEndpoint('starknet_getStorageAt',
|
|
146
|
-
contractAddress,
|
|
147
|
-
parsedKey,
|
|
148
|
-
|
|
149
|
-
|
|
160
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
161
|
+
return this.fetchEndpoint('starknet_getStorageAt', {
|
|
162
|
+
contract_address: contractAddress,
|
|
163
|
+
key: parsedKey,
|
|
164
|
+
block_id,
|
|
165
|
+
});
|
|
150
166
|
}
|
|
151
167
|
|
|
152
168
|
// Methods from Interface
|
|
153
|
-
public async getTransaction(txHash:
|
|
169
|
+
public async getTransaction(txHash: string): Promise<GetTransactionResponse> {
|
|
154
170
|
return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
|
|
155
171
|
}
|
|
156
172
|
|
|
157
|
-
public async getTransactionByHash(
|
|
158
|
-
|
|
159
|
-
): Promise<RPC.GetTransactionByHashResponse> {
|
|
160
|
-
return this.fetchEndpoint('starknet_getTransactionByHash', [txHash]);
|
|
173
|
+
public async getTransactionByHash(txHash: string): Promise<RPC.GetTransactionByHashResponse> {
|
|
174
|
+
return this.fetchEndpoint('starknet_getTransactionByHash', { transaction_hash: txHash });
|
|
161
175
|
}
|
|
162
176
|
|
|
163
177
|
public async getTransactionByBlockIdAndIndex(
|
|
164
178
|
blockIdentifier: BlockIdentifier,
|
|
165
179
|
index: number
|
|
166
180
|
): Promise<RPC.GetTransactionByBlockIdAndIndex> {
|
|
167
|
-
const
|
|
168
|
-
return this.fetchEndpoint('starknet_getTransactionByBlockIdAndIndex',
|
|
169
|
-
block.identifier,
|
|
170
|
-
index,
|
|
171
|
-
]);
|
|
181
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
182
|
+
return this.fetchEndpoint('starknet_getTransactionByBlockIdAndIndex', { block_id, index });
|
|
172
183
|
}
|
|
173
184
|
|
|
174
|
-
public async getTransactionReceipt(txHash:
|
|
175
|
-
return this.fetchEndpoint('starknet_getTransactionReceipt',
|
|
185
|
+
public async getTransactionReceipt(txHash: string): Promise<GetTransactionReceiptResponse> {
|
|
186
|
+
return this.fetchEndpoint('starknet_getTransactionReceipt', { transaction_hash: txHash }).then(
|
|
176
187
|
this.responseParser.parseGetTransactionReceiptResponse
|
|
177
188
|
);
|
|
178
189
|
}
|
|
179
190
|
|
|
180
191
|
public async getClass(classHash: RPC.Felt): Promise<RPC.ContractClass> {
|
|
181
|
-
return this.fetchEndpoint('starknet_getClass',
|
|
192
|
+
return this.fetchEndpoint('starknet_getClass', { class_hash: classHash });
|
|
182
193
|
}
|
|
183
194
|
|
|
184
|
-
public async getClassAt(
|
|
185
|
-
|
|
186
|
-
|
|
195
|
+
public async getClassAt(
|
|
196
|
+
contractAddress: string,
|
|
197
|
+
blockIdentifier: BlockIdentifier
|
|
198
|
+
): Promise<RPC.ContractClass> {
|
|
199
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
200
|
+
return this.fetchEndpoint('starknet_getClassAt', {
|
|
201
|
+
block_id,
|
|
202
|
+
contract_address: contractAddress,
|
|
203
|
+
});
|
|
187
204
|
}
|
|
188
205
|
|
|
189
206
|
public async getCode(
|
|
@@ -195,20 +212,20 @@ export class RpcProvider implements ProviderInterface {
|
|
|
195
212
|
|
|
196
213
|
public async getEstimateFee(
|
|
197
214
|
invocation: Invocation,
|
|
198
|
-
|
|
199
|
-
|
|
215
|
+
invocationDetails: InvocationsDetailsWithNonce,
|
|
216
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
200
217
|
): Promise<EstimateFeeResponse> {
|
|
201
218
|
const block_id = new Block(blockIdentifier).identifier;
|
|
202
|
-
return this.fetchEndpoint('starknet_estimateFee',
|
|
203
|
-
{
|
|
219
|
+
return this.fetchEndpoint('starknet_estimateFee', {
|
|
220
|
+
request: {
|
|
204
221
|
contract_address: invocation.contractAddress,
|
|
205
|
-
entry_point_selector: getSelectorFromName(invocation.entrypoint),
|
|
206
222
|
calldata: parseCalldata(invocation.calldata),
|
|
207
223
|
signature: bigNumberishArrayToHexadecimalStringArray(invocation.signature || []),
|
|
208
224
|
version: toHex(toBN(invocationDetails?.version || 0)),
|
|
225
|
+
max_fee: toHex(toBN(invocationDetails?.maxFee || 0)),
|
|
209
226
|
},
|
|
210
227
|
block_id,
|
|
211
|
-
|
|
228
|
+
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
212
229
|
}
|
|
213
230
|
|
|
214
231
|
public async declareContract({
|
|
@@ -217,14 +234,14 @@ export class RpcProvider implements ProviderInterface {
|
|
|
217
234
|
}: DeclareContractPayload): Promise<DeclareContractResponse> {
|
|
218
235
|
const contractDefinition = parseContract(contract);
|
|
219
236
|
|
|
220
|
-
return this.fetchEndpoint('starknet_addDeclareTransaction',
|
|
221
|
-
{
|
|
237
|
+
return this.fetchEndpoint('starknet_addDeclareTransaction', {
|
|
238
|
+
contract_class: {
|
|
222
239
|
program: contractDefinition.program,
|
|
223
240
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
224
241
|
abi: contractDefinition.abi, // rpc 2.0
|
|
225
242
|
},
|
|
226
|
-
toHex(toBN(version || 0)),
|
|
227
|
-
|
|
243
|
+
version: toHex(toBN(version || 0)),
|
|
244
|
+
});
|
|
228
245
|
}
|
|
229
246
|
|
|
230
247
|
public async deployContract({
|
|
@@ -234,31 +251,30 @@ export class RpcProvider implements ProviderInterface {
|
|
|
234
251
|
}: DeployContractPayload): Promise<DeployContractResponse> {
|
|
235
252
|
const contractDefinition = parseContract(contract);
|
|
236
253
|
|
|
237
|
-
return this.fetchEndpoint('starknet_addDeployTransaction',
|
|
238
|
-
addressSalt ?? randomAddress(),
|
|
239
|
-
bigNumberishArrayToHexadecimalStringArray(constructorCalldata ?? []),
|
|
240
|
-
{
|
|
254
|
+
return this.fetchEndpoint('starknet_addDeployTransaction', {
|
|
255
|
+
contract_address_salt: addressSalt ?? randomAddress(),
|
|
256
|
+
constructor_calldata: bigNumberishArrayToHexadecimalStringArray(constructorCalldata ?? []),
|
|
257
|
+
contract_definition: {
|
|
241
258
|
program: contractDefinition.program,
|
|
242
259
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
243
260
|
abi: contractDefinition.abi, // rpc 2.0
|
|
244
261
|
},
|
|
245
|
-
|
|
262
|
+
});
|
|
246
263
|
}
|
|
247
264
|
|
|
248
265
|
public async invokeFunction(
|
|
249
266
|
functionInvocation: Invocation,
|
|
250
|
-
details:
|
|
267
|
+
details: InvocationsDetailsWithNonce
|
|
251
268
|
): Promise<InvokeFunctionResponse> {
|
|
252
|
-
return this.fetchEndpoint('starknet_addInvokeTransaction',
|
|
253
|
-
{
|
|
269
|
+
return this.fetchEndpoint('starknet_addInvokeTransaction', {
|
|
270
|
+
function_invocation: {
|
|
254
271
|
contract_address: functionInvocation.contractAddress,
|
|
255
|
-
entry_point_selector: getSelectorFromName(functionInvocation.entrypoint),
|
|
256
272
|
calldata: parseCalldata(functionInvocation.calldata),
|
|
257
273
|
},
|
|
258
|
-
bigNumberishArrayToHexadecimalStringArray(functionInvocation.signature || []),
|
|
259
|
-
toHex(toBN(details.maxFee || 0)),
|
|
260
|
-
toHex(toBN(details.version || 0)),
|
|
261
|
-
|
|
274
|
+
signature: bigNumberishArrayToHexadecimalStringArray(functionInvocation.signature || []),
|
|
275
|
+
max_fee: toHex(toBN(details.maxFee || 0)),
|
|
276
|
+
version: toHex(toBN(details.version || 0)),
|
|
277
|
+
});
|
|
262
278
|
}
|
|
263
279
|
|
|
264
280
|
// Methods from Interface
|
|
@@ -267,29 +283,29 @@ export class RpcProvider implements ProviderInterface {
|
|
|
267
283
|
blockIdentifier: BlockIdentifier = 'pending'
|
|
268
284
|
): Promise<CallContractResponse> {
|
|
269
285
|
const block_id = new Block(blockIdentifier).identifier;
|
|
270
|
-
const result = await this.fetchEndpoint('starknet_call',
|
|
271
|
-
{
|
|
286
|
+
const result = await this.fetchEndpoint('starknet_call', {
|
|
287
|
+
request: {
|
|
272
288
|
contract_address: call.contractAddress,
|
|
273
289
|
entry_point_selector: getSelectorFromName(call.entrypoint),
|
|
274
290
|
calldata: parseCalldata(call.calldata),
|
|
275
291
|
},
|
|
276
292
|
block_id,
|
|
277
|
-
|
|
293
|
+
});
|
|
278
294
|
|
|
279
295
|
return this.responseParser.parseCallContractResponse(result);
|
|
280
296
|
}
|
|
281
297
|
|
|
282
298
|
public async traceTransaction(transactionHash: RPC.TransactionHash): Promise<RPC.Trace> {
|
|
283
|
-
return this.fetchEndpoint('starknet_traceTransaction',
|
|
299
|
+
return this.fetchEndpoint('starknet_traceTransaction', { transaction_hash: transactionHash });
|
|
284
300
|
}
|
|
285
301
|
|
|
286
302
|
public async traceBlockTransactions(blockHash: RPC.BlockHash): Promise<RPC.Traces> {
|
|
287
|
-
return this.fetchEndpoint('starknet_traceBlockTransactions',
|
|
303
|
+
return this.fetchEndpoint('starknet_traceBlockTransactions', { block_hash: blockHash });
|
|
288
304
|
}
|
|
289
305
|
|
|
290
|
-
public async waitForTransaction(txHash:
|
|
306
|
+
public async waitForTransaction(txHash: string, retryInterval: number = 8000) {
|
|
307
|
+
let { retries } = this;
|
|
291
308
|
let onchain = false;
|
|
292
|
-
let retries = 200;
|
|
293
309
|
|
|
294
310
|
while (!onchain) {
|
|
295
311
|
const successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING'];
|
|
@@ -315,7 +331,7 @@ export class RpcProvider implements ProviderInterface {
|
|
|
315
331
|
}
|
|
316
332
|
|
|
317
333
|
if (retries === 0) {
|
|
318
|
-
throw
|
|
334
|
+
throw new Error('waitForTransaction timedout with retries');
|
|
319
335
|
}
|
|
320
336
|
}
|
|
321
337
|
|
|
@@ -335,8 +351,8 @@ export class RpcProvider implements ProviderInterface {
|
|
|
335
351
|
public async getTransactionCount(
|
|
336
352
|
blockIdentifier: BlockIdentifier
|
|
337
353
|
): Promise<RPC.GetTransactionCountResponse> {
|
|
338
|
-
const
|
|
339
|
-
return this.fetchEndpoint('starknet_getBlockTransactionCount',
|
|
354
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
355
|
+
return this.fetchEndpoint('starknet_getBlockTransactionCount', { block_id });
|
|
340
356
|
}
|
|
341
357
|
|
|
342
358
|
/**
|
|
@@ -366,6 +382,6 @@ export class RpcProvider implements ProviderInterface {
|
|
|
366
382
|
* @returns events and the pagination of the events
|
|
367
383
|
*/
|
|
368
384
|
public async getEvents(eventFilter: RPC.EventFilter): Promise<RPC.GetEventsResponse> {
|
|
369
|
-
return this.fetchEndpoint('starknet_getEvents',
|
|
385
|
+
return this.fetchEndpoint('starknet_getEvents', { filter: eventFilter });
|
|
370
386
|
}
|
|
371
387
|
}
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
GetTransactionReceiptResponse,
|
|
15
15
|
GetTransactionResponse,
|
|
16
16
|
Invocation,
|
|
17
|
-
|
|
17
|
+
InvocationsDetailsWithNonce,
|
|
18
18
|
InvokeFunctionResponse,
|
|
19
19
|
} from '../types';
|
|
20
20
|
import {
|
|
@@ -234,6 +234,13 @@ export class SequencerProvider implements ProviderInterface {
|
|
|
234
234
|
);
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
+
public async getNonce(
|
|
238
|
+
contractAddress: string,
|
|
239
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
240
|
+
): Promise<BigNumberish> {
|
|
241
|
+
return this.fetchEndpoint('get_nonce', { contractAddress, blockIdentifier });
|
|
242
|
+
}
|
|
243
|
+
|
|
237
244
|
public async getStorageAt(
|
|
238
245
|
contractAddress: string,
|
|
239
246
|
key: BigNumberish,
|
|
@@ -272,16 +279,16 @@ export class SequencerProvider implements ProviderInterface {
|
|
|
272
279
|
|
|
273
280
|
public async invokeFunction(
|
|
274
281
|
functionInvocation: Invocation,
|
|
275
|
-
details:
|
|
282
|
+
details: InvocationsDetailsWithNonce
|
|
276
283
|
): Promise<InvokeFunctionResponse> {
|
|
277
284
|
return this.fetchEndpoint('add_transaction', undefined, {
|
|
278
285
|
type: 'INVOKE_FUNCTION',
|
|
279
286
|
contract_address: functionInvocation.contractAddress,
|
|
280
|
-
entry_point_selector: getSelectorFromName(functionInvocation.entrypoint),
|
|
281
287
|
calldata: bigNumberishArrayToDecimalStringArray(functionInvocation.calldata ?? []),
|
|
282
288
|
signature: bigNumberishArrayToDecimalStringArray(functionInvocation.signature ?? []),
|
|
289
|
+
nonce: toHex(toBN(details.nonce)),
|
|
283
290
|
max_fee: toHex(toBN(details.maxFee || 0)),
|
|
284
|
-
version: toHex(toBN(details.version ||
|
|
291
|
+
version: toHex(toBN(details.version || 1)),
|
|
285
292
|
}).then(this.responseParser.parseInvokeFunctionResponse);
|
|
286
293
|
}
|
|
287
294
|
|
|
@@ -316,18 +323,19 @@ export class SequencerProvider implements ProviderInterface {
|
|
|
316
323
|
|
|
317
324
|
public async getEstimateFee(
|
|
318
325
|
invocation: Invocation,
|
|
319
|
-
|
|
320
|
-
|
|
326
|
+
invocationDetails: InvocationsDetailsWithNonce,
|
|
327
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
321
328
|
): Promise<EstimateFeeResponse> {
|
|
322
329
|
return this.fetchEndpoint(
|
|
323
330
|
'estimate_fee',
|
|
324
331
|
{ blockIdentifier },
|
|
325
332
|
{
|
|
333
|
+
type: 'INVOKE_FUNCTION',
|
|
326
334
|
contract_address: invocation.contractAddress,
|
|
327
|
-
entry_point_selector: getSelectorFromName(invocation.entrypoint),
|
|
328
335
|
calldata: invocation.calldata ?? [],
|
|
329
336
|
signature: bigNumberishArrayToDecimalStringArray(invocation.signature || []),
|
|
330
|
-
version: toHex(toBN(invocationDetails?.version ||
|
|
337
|
+
version: toHex(toBN(invocationDetails?.version || 1)),
|
|
338
|
+
nonce: toHex(toBN(invocationDetails.nonce)),
|
|
331
339
|
}
|
|
332
340
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
333
341
|
}
|
package/src/signer/default.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Abi,
|
|
1
|
+
import { Abi, Call, InvocationsSignerDetails, KeyPair, Signature } from '../types';
|
|
2
2
|
import { genKeyPair, getStarkKey, sign } from '../utils/ellipticCurve';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { calculateTransactionHash } from '../utils/hash';
|
|
4
|
+
import { fromCallsToExecuteCalldata } from '../utils/transaction';
|
|
5
5
|
import { TypedData, getMessageHash } from '../utils/typedData';
|
|
6
6
|
import { SignerInterface } from './interface';
|
|
7
7
|
|
|
@@ -17,7 +17,7 @@ export class Signer implements SignerInterface {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
public async signTransaction(
|
|
20
|
-
transactions:
|
|
20
|
+
transactions: Call[],
|
|
21
21
|
transactionsDetail: InvocationsSignerDetails,
|
|
22
22
|
abis?: Abi[]
|
|
23
23
|
): Promise<Signature> {
|
|
@@ -26,15 +26,15 @@ export class Signer implements SignerInterface {
|
|
|
26
26
|
}
|
|
27
27
|
// now use abi to display decoded data somewhere, but as this signer is headless, we can't do that
|
|
28
28
|
|
|
29
|
-
const calldata =
|
|
29
|
+
const calldata = fromCallsToExecuteCalldata(transactions);
|
|
30
30
|
|
|
31
|
-
const msgHash =
|
|
31
|
+
const msgHash = calculateTransactionHash(
|
|
32
32
|
transactionsDetail.walletAddress,
|
|
33
33
|
transactionsDetail.version,
|
|
34
|
-
getSelectorFromName('__execute__'),
|
|
35
34
|
calldata,
|
|
36
35
|
transactionsDetail.maxFee,
|
|
37
|
-
transactionsDetail.chainId
|
|
36
|
+
transactionsDetail.chainId,
|
|
37
|
+
transactionsDetail.nonce
|
|
38
38
|
);
|
|
39
39
|
|
|
40
40
|
return sign(this.keyPair, msgHash);
|
package/src/signer/interface.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Abi,
|
|
1
|
+
import { Abi, Call, InvocationsSignerDetails, Signature } from '../types';
|
|
2
2
|
import { TypedData } from '../utils/typedData';
|
|
3
3
|
|
|
4
4
|
export abstract class SignerInterface {
|
|
@@ -33,7 +33,7 @@ export abstract class SignerInterface {
|
|
|
33
33
|
* @returns signature
|
|
34
34
|
*/
|
|
35
35
|
public abstract signTransaction(
|
|
36
|
-
transactions:
|
|
36
|
+
transactions: Call[],
|
|
37
37
|
transactionsDetail: InvocationsSignerDetails,
|
|
38
38
|
abis?: Abi[]
|
|
39
39
|
): Promise<Signature>;
|