starknet 4.16.0 → 4.17.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 +11 -0
- package/__tests__/account.test.ts +2 -0
- package/__tests__/contract.test.ts +14 -2
- package/__tests__/defaultProvider.test.ts +4 -2
- package/__tests__/fixtures.ts +1 -1
- package/__tests__/rpcProvider.test.ts +2 -6
- package/dist/index.d.ts +8 -45
- package/dist/index.global.js +4128 -4106
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +199 -177
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +199 -177
- package/dist/index.mjs.map +1 -1
- package/index.d.ts +8 -45
- package/index.global.js +4128 -4106
- package/index.global.js.map +1 -1
- package/index.js +199 -177
- package/index.js.map +1 -1
- package/index.mjs +199 -177
- package/index.mjs.map +1 -1
- package/package.json +4 -3
- package/src/contract/contractFactory.ts +13 -6
- package/src/contract/default.ts +11 -226
- package/src/provider/default.ts +2 -2
- package/src/provider/interface.ts +2 -2
- package/src/utils/calldata.ts +250 -0
- package/www/docs/API/account.md +50 -24
- package/www/docs/API/contract.md +20 -6
- package/www/docs/API/contractFactory.md +7 -3
- package/www/docs/API/provider.md +126 -44
- package/www/docs/API/signer.md +14 -4
- package/www/docs/API/utils.md +23 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
# [4.17.0](https://github.com/0xs34n/starknet.js/compare/v4.16.0...v4.17.0) (2022-12-13)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- merge conflicts ([92a3be8](https://github.com/0xs34n/starknet.js/commit/92a3be8500153d4b87b888f454bb4140edb88411))
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- contract factory deploy arguments ([9eff7f4](https://github.com/0xs34n/starknet.js/commit/9eff7f4ccc74cb5f0c0594e88c0292600f20ec09))
|
|
10
|
+
- update contractFactory docs ([76f8440](https://github.com/0xs34n/starknet.js/commit/76f8440233c4a1e24e3dfff25fe02525e86a8258))
|
|
11
|
+
|
|
1
12
|
# [4.16.0](https://github.com/0xs34n/starknet.js/compare/v4.15.1...v4.16.0) (2022-12-12)
|
|
2
13
|
|
|
3
14
|
### Bug Fixes
|
|
@@ -338,6 +338,8 @@ describe('deploy and test Wallet', () => {
|
|
|
338
338
|
expect(deployments).toHaveProperty('transaction_hash');
|
|
339
339
|
expect(deployments.contract_address[0]).toBeDefined();
|
|
340
340
|
expect(deployments.contract_address[1]).toBeDefined();
|
|
341
|
+
|
|
342
|
+
await provider.waitForTransaction(deployments.transaction_hash);
|
|
341
343
|
});
|
|
342
344
|
});
|
|
343
345
|
});
|
|
@@ -220,12 +220,24 @@ describe('contract module', () => {
|
|
|
220
220
|
});
|
|
221
221
|
test('deployment of new contract', async () => {
|
|
222
222
|
const factory = new ContractFactory(compiledErc20, classHash, account);
|
|
223
|
-
const erc20 = await factory.deploy(
|
|
223
|
+
const erc20 = await factory.deploy(
|
|
224
|
+
compileCalldata({
|
|
225
|
+
name: encodeShortString('Token'),
|
|
226
|
+
symbol: encodeShortString('ERC20'),
|
|
227
|
+
recipient: wallet,
|
|
228
|
+
})
|
|
229
|
+
);
|
|
224
230
|
expect(erc20 instanceof Contract);
|
|
225
231
|
});
|
|
226
232
|
test('wait for deployment transaction', async () => {
|
|
227
233
|
const factory = new ContractFactory(compiledErc20, classHash, account);
|
|
228
|
-
const contract = await factory.deploy(
|
|
234
|
+
const contract = await factory.deploy(
|
|
235
|
+
compileCalldata({
|
|
236
|
+
name: encodeShortString('Token'),
|
|
237
|
+
symbol: encodeShortString('ERC20'),
|
|
238
|
+
recipient: wallet,
|
|
239
|
+
})
|
|
240
|
+
);
|
|
229
241
|
expect(contract.deployed()).resolves.not.toThrow();
|
|
230
242
|
});
|
|
231
243
|
test('attach new contract', async () => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { BlockNumber, GetBlockResponse, stark } from '../src';
|
|
1
|
+
import { BlockNumber, GetBlockResponse, Provider, stark } from '../src';
|
|
2
2
|
import { toBN } from '../src/utils/number';
|
|
3
3
|
import { encodeShortString } from '../src/utils/shortString';
|
|
4
4
|
import { compiledErc20, erc20ClassHash, getTestAccount, getTestProvider } from './fixtures';
|
|
5
5
|
|
|
6
6
|
const { compileCalldata } = stark;
|
|
7
7
|
|
|
8
|
-
const testProvider = getTestProvider();
|
|
8
|
+
const testProvider = new Provider(getTestProvider());
|
|
9
9
|
|
|
10
10
|
describe('defaultProvider', () => {
|
|
11
11
|
let exampleTransactionHash: string;
|
|
@@ -17,6 +17,8 @@ describe('defaultProvider', () => {
|
|
|
17
17
|
const account = getTestAccount(testProvider);
|
|
18
18
|
|
|
19
19
|
beforeAll(async () => {
|
|
20
|
+
expect(testProvider).toBeInstanceOf(Provider);
|
|
21
|
+
|
|
20
22
|
const { deploy } = await account.declareDeploy({
|
|
21
23
|
contract: compiledErc20,
|
|
22
24
|
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
|
package/__tests__/fixtures.ts
CHANGED
|
@@ -47,7 +47,7 @@ export const getTestProvider = (): ProviderInterface => {
|
|
|
47
47
|
if (IS_LOCALHOST_DEVNET) {
|
|
48
48
|
// accelerate the tests when running locally
|
|
49
49
|
const originalWaitForTransaction = provider.waitForTransaction.bind(provider);
|
|
50
|
-
provider.waitForTransaction = (txHash, retryInterval) => {
|
|
50
|
+
provider.waitForTransaction = (txHash: string, retryInterval?: number) => {
|
|
51
51
|
return originalWaitForTransaction(txHash, retryInterval || 1000);
|
|
52
52
|
};
|
|
53
53
|
}
|
|
@@ -86,8 +86,8 @@ describeIfRpc('RPCProvider', () => {
|
|
|
86
86
|
});
|
|
87
87
|
|
|
88
88
|
describe('deploy contract related tests', () => {
|
|
89
|
-
let contract_address;
|
|
90
|
-
let transaction_hash;
|
|
89
|
+
let contract_address: string;
|
|
90
|
+
let transaction_hash: string;
|
|
91
91
|
|
|
92
92
|
beforeAll(async () => {
|
|
93
93
|
const { deploy } = await account.declareDeploy({
|
|
@@ -128,9 +128,5 @@ describeIfRpc('RPCProvider', () => {
|
|
|
128
128
|
expect(contractClass).toHaveProperty('program');
|
|
129
129
|
expect(contractClass).toHaveProperty('entry_points_by_type');
|
|
130
130
|
});
|
|
131
|
-
|
|
132
|
-
test.todo('getEstimateFee');
|
|
133
|
-
|
|
134
|
-
test.todo('invokeFunction');
|
|
135
131
|
});
|
|
136
132
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1477,7 +1477,7 @@ declare abstract class ProviderInterface {
|
|
|
1477
1477
|
abstract deployAccountContract(payload: DeployAccountContractPayload, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
|
|
1478
1478
|
/**
|
|
1479
1479
|
* Invokes a function on starknet
|
|
1480
|
-
* @deprecated This method wont be supported as soon as fees are mandatory
|
|
1480
|
+
* @deprecated This method wont be supported as soon as fees are mandatory. Should not be used outside of Account class
|
|
1481
1481
|
*
|
|
1482
1482
|
* @param invocation the invocation object containing:
|
|
1483
1483
|
* - contractAddress - the address of the contract
|
|
@@ -1506,7 +1506,7 @@ declare abstract class ProviderInterface {
|
|
|
1506
1506
|
abstract declareContract(transaction: DeclareContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeclareContractResponse>;
|
|
1507
1507
|
/**
|
|
1508
1508
|
* Estimates the fee for a given INVOKE transaction
|
|
1509
|
-
* @deprecated Please use getInvokeEstimateFee or getDeclareEstimateFee instead
|
|
1509
|
+
* @deprecated Please use getInvokeEstimateFee or getDeclareEstimateFee instead. Should not be used outside of Account class
|
|
1510
1510
|
*
|
|
1511
1511
|
* @param invocation the invocation object containing:
|
|
1512
1512
|
* - contractAddress - the address of the contract
|
|
@@ -1737,13 +1737,13 @@ declare class Provider implements ProviderInterface {
|
|
|
1737
1737
|
get chainId(): StarknetChainId;
|
|
1738
1738
|
getChainId(): Promise<StarknetChainId>;
|
|
1739
1739
|
getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse>;
|
|
1740
|
-
getClassAt(contractAddress: string, blockIdentifier
|
|
1740
|
+
getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
|
|
1741
1741
|
getClassHashAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<string>;
|
|
1742
1742
|
getClassByHash(classHash: string): Promise<ContractClass>;
|
|
1743
1743
|
getEstimateFee(invocationWithTxType: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
1744
1744
|
getInvokeEstimateFee(invocationWithTxType: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
1745
1745
|
getNonceForAddress(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
1746
|
-
getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier
|
|
1746
|
+
getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
1747
1747
|
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
1748
1748
|
getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
|
|
1749
1749
|
callContract(request: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
|
@@ -2322,6 +2322,7 @@ declare class Contract implements ContractInterface {
|
|
|
2322
2322
|
[name: string]: ContractFunction;
|
|
2323
2323
|
};
|
|
2324
2324
|
readonly [key: string]: AsyncContractFunction | any;
|
|
2325
|
+
private checkCalldata;
|
|
2325
2326
|
/**
|
|
2326
2327
|
* Contract class to handle contract methods
|
|
2327
2328
|
*
|
|
@@ -2337,29 +2338,6 @@ declare class Contract implements ContractInterface {
|
|
|
2337
2338
|
invoke(method: string, args?: Array<any>, options?: Overrides): Promise<InvokeFunctionResponse>;
|
|
2338
2339
|
estimate(method: string, args?: Array<any>): Promise<EstimateFeeResponse>;
|
|
2339
2340
|
populate(method: string, args?: Array<any>): Call;
|
|
2340
|
-
/**
|
|
2341
|
-
* Deep parse of the object that has been passed to the method
|
|
2342
|
-
*
|
|
2343
|
-
* @param struct - struct that needs to be calculated
|
|
2344
|
-
* @return {number} - number of members for the given struct
|
|
2345
|
-
*/
|
|
2346
|
-
private calculateStructMembers;
|
|
2347
|
-
/**
|
|
2348
|
-
* Validates if all arguments that are passed to the method are corresponding to the ones in the abi
|
|
2349
|
-
*
|
|
2350
|
-
* @param type - type of the method
|
|
2351
|
-
* @param method - name of the method
|
|
2352
|
-
* @param args - arguments that are passed to the method
|
|
2353
|
-
*/
|
|
2354
|
-
protected validateMethodAndArgs(type: 'INVOKE' | 'CALL', method: string, args?: Array<any>): void;
|
|
2355
|
-
/**
|
|
2356
|
-
* Deep parse of the object that has been passed to the method
|
|
2357
|
-
*
|
|
2358
|
-
* @param element - element that needs to be parsed
|
|
2359
|
-
* @param type - name of the method
|
|
2360
|
-
* @return {string | string[]} - parsed arguments in format that contract is expecting
|
|
2361
|
-
*/
|
|
2362
|
-
protected parseCalldataValue(element: ParsedStruct | BigNumberish | BigNumberish[], type: string): string | string[];
|
|
2363
2341
|
/**
|
|
2364
2342
|
* Parse of the response elements that are converted to Object (Struct) by using the abi
|
|
2365
2343
|
*
|
|
@@ -2368,22 +2346,6 @@ declare class Contract implements ContractInterface {
|
|
|
2368
2346
|
* @return {BigNumberish | ParsedStruct} - parsed arguments in format that contract is expecting
|
|
2369
2347
|
*/
|
|
2370
2348
|
protected parseResponseStruct(responseIterator: Iterator<string>, type: string): BigNumberish | ParsedStruct;
|
|
2371
|
-
/**
|
|
2372
|
-
* Parse one field of the calldata by using input field from the abi for that method
|
|
2373
|
-
*
|
|
2374
|
-
* @param args - value of the field
|
|
2375
|
-
* @param input - input(field) information from the abi that will be used to parse the data
|
|
2376
|
-
* @return {string | string[]} - parsed arguments in format that contract is expecting
|
|
2377
|
-
*/
|
|
2378
|
-
protected parseCalldataField(argsIterator: Iterator<any>, input: AbiEntry): string | string[];
|
|
2379
|
-
/**
|
|
2380
|
-
* Parse the calldata by using input fields from the abi for that method
|
|
2381
|
-
*
|
|
2382
|
-
* @param args - arguments passed the the method
|
|
2383
|
-
* @param inputs - list of inputs(fields) that are in the abi
|
|
2384
|
-
* @return {Calldata} - parsed arguments in format that contract is expecting
|
|
2385
|
-
*/
|
|
2386
|
-
protected compileCalldata(args: Array<any>, inputs: AbiEntry[]): Calldata;
|
|
2387
2349
|
/**
|
|
2388
2350
|
* Parse elements of the response and structuring them into one field by using output property from the abi for that method
|
|
2389
2351
|
*
|
|
@@ -2407,15 +2369,16 @@ declare class ContractFactory {
|
|
|
2407
2369
|
compiledContract: CompiledContract;
|
|
2408
2370
|
classHash: string;
|
|
2409
2371
|
account: AccountInterface;
|
|
2372
|
+
private checkCalldata;
|
|
2410
2373
|
constructor(compiledContract: CompiledContract, classHash: string, account: AccountInterface, abi?: Abi);
|
|
2411
2374
|
/**
|
|
2412
2375
|
* Deploys contract and returns new instance of the Contract
|
|
2413
2376
|
*
|
|
2414
|
-
* @param
|
|
2377
|
+
* @param args - Array of the constructor arguments for deployment
|
|
2415
2378
|
* @param addressSalt (optional) - Address Salt for deployment
|
|
2416
2379
|
* @returns deployed Contract
|
|
2417
2380
|
*/
|
|
2418
|
-
deploy(
|
|
2381
|
+
deploy(args?: Array<any>, addressSalt?: string | undefined): Promise<Contract>;
|
|
2419
2382
|
/**
|
|
2420
2383
|
* Attaches to new Provider or Account
|
|
2421
2384
|
*
|