starknet 4.13.2 → 4.15.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 +39 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/README.md +2 -2
- package/__mocks__/naming_compiled.json +53283 -0
- package/__mocks__/starknetId_compiled.json +44703 -0
- package/__tests__/account.test.ts +100 -15
- package/__tests__/contract.test.ts +70 -57
- package/__tests__/defaultProvider.test.ts +14 -13
- package/__tests__/fixtures.ts +27 -26
- package/__tests__/rpcProvider.test.ts +19 -16
- package/__tests__/sequencerProvider.test.ts +47 -55
- package/__tests__/utils/starknetId.test.ts +53 -0
- package/__tests__/utils/utils.test.ts +10 -0
- package/dist/index.d.ts +116 -30
- package/dist/index.global.js +660 -463
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +247 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +247 -51
- package/dist/index.mjs.map +1 -1
- package/index.d.ts +116 -30
- package/index.global.js +660 -463
- package/index.global.js.map +1 -1
- package/index.js +247 -51
- package/index.js.map +1 -1
- package/index.mjs +247 -51
- package/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/account/default.ts +81 -8
- package/src/account/interface.ts +71 -5
- package/src/contract/contractFactory.ts +20 -13
- package/src/contract/default.ts +11 -2
- package/src/provider/default.ts +26 -11
- package/src/provider/interface.ts +9 -3
- package/src/provider/rpc.ts +15 -11
- package/src/provider/sequencer.ts +32 -20
- package/src/provider/utils.ts +19 -11
- package/src/types/account.ts +21 -1
- package/src/types/lib.ts +5 -2
- package/src/types/provider.ts +0 -5
- package/src/utils/events.ts +32 -0
- package/src/utils/number.ts +6 -0
- package/src/utils/starknetId.ts +116 -0
- package/www/docs/API/account.md +176 -2
- package/www/docs/API/contractFactory.md +7 -11
- package/www/docs/API/provider.md +5 -9
- package/www/docs/API/utils.md +8 -0
- package/www/guides/account.md +89 -38
- package/www/guides/erc20.md +115 -59
- package/www/guides/intro.md +11 -4
|
@@ -45,6 +45,16 @@ import { Block, BlockIdentifier } from './utils';
|
|
|
45
45
|
|
|
46
46
|
type NetworkName = 'mainnet-alpha' | 'goerli-alpha' | 'goerli-alpha-2';
|
|
47
47
|
|
|
48
|
+
export type SequencerProviderOptions =
|
|
49
|
+
| { network: NetworkName | StarknetChainId }
|
|
50
|
+
| {
|
|
51
|
+
baseUrl: string;
|
|
52
|
+
feederGatewayUrl?: string;
|
|
53
|
+
gatewayUrl?: string;
|
|
54
|
+
chainId?: StarknetChainId;
|
|
55
|
+
headers?: object;
|
|
56
|
+
};
|
|
57
|
+
|
|
48
58
|
function isEmptyQueryObject(obj?: Record<any, any>): obj is undefined {
|
|
49
59
|
return (
|
|
50
60
|
obj === undefined ||
|
|
@@ -54,15 +64,9 @@ function isEmptyQueryObject(obj?: Record<any, any>): obj is undefined {
|
|
|
54
64
|
);
|
|
55
65
|
}
|
|
56
66
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
baseUrl: string;
|
|
61
|
-
feederGatewayUrl?: string;
|
|
62
|
-
gatewayUrl?: string;
|
|
63
|
-
chainId?: StarknetChainId;
|
|
64
|
-
headers?: object;
|
|
65
|
-
};
|
|
67
|
+
const defaultOptions: SequencerProviderOptions = {
|
|
68
|
+
network: 'goerli-alpha-2',
|
|
69
|
+
};
|
|
66
70
|
|
|
67
71
|
export class SequencerProvider implements ProviderInterface {
|
|
68
72
|
public baseUrl: string;
|
|
@@ -77,7 +81,7 @@ export class SequencerProvider implements ProviderInterface {
|
|
|
77
81
|
|
|
78
82
|
private responseParser = new SequencerAPIResponseParser();
|
|
79
83
|
|
|
80
|
-
constructor(optionsOrProvider: SequencerProviderOptions =
|
|
84
|
+
constructor(optionsOrProvider: SequencerProviderOptions = defaultOptions) {
|
|
81
85
|
if ('network' in optionsOrProvider) {
|
|
82
86
|
this.baseUrl = SequencerProvider.getNetworkFromName(optionsOrProvider.network);
|
|
83
87
|
this.chainId = SequencerProvider.getChainIdFromBaseUrl(this.baseUrl);
|
|
@@ -100,13 +104,13 @@ export class SequencerProvider implements ProviderInterface {
|
|
|
100
104
|
}
|
|
101
105
|
}
|
|
102
106
|
|
|
103
|
-
protected static getNetworkFromName(name: NetworkName) {
|
|
107
|
+
protected static getNetworkFromName(name: NetworkName | StarknetChainId) {
|
|
104
108
|
switch (name) {
|
|
105
|
-
case 'mainnet-alpha':
|
|
109
|
+
case 'mainnet-alpha' || StarknetChainId.MAINNET:
|
|
106
110
|
return 'https://alpha-mainnet.starknet.io';
|
|
107
|
-
case 'goerli-alpha':
|
|
111
|
+
case 'goerli-alpha' || StarknetChainId.TESTNET:
|
|
108
112
|
return 'https://alpha4.starknet.io';
|
|
109
|
-
case 'goerli-alpha-2':
|
|
113
|
+
case 'goerli-alpha-2' || StarknetChainId.TESTNET2:
|
|
110
114
|
return 'https://alpha4-2.starknet.io';
|
|
111
115
|
default:
|
|
112
116
|
return 'https://alpha4.starknet.io';
|
|
@@ -119,6 +123,9 @@ export class SequencerProvider implements ProviderInterface {
|
|
|
119
123
|
if (url.host.includes('mainnet.starknet.io')) {
|
|
120
124
|
return StarknetChainId.MAINNET;
|
|
121
125
|
}
|
|
126
|
+
if (url.host.includes('alpha4-2.starknet.io')) {
|
|
127
|
+
return StarknetChainId.TESTNET2;
|
|
128
|
+
}
|
|
122
129
|
} catch {
|
|
123
130
|
// eslint-disable-next-line no-console
|
|
124
131
|
console.error(`Could not parse baseUrl: ${baseUrl}`);
|
|
@@ -256,7 +263,7 @@ export class SequencerProvider implements ProviderInterface {
|
|
|
256
263
|
);
|
|
257
264
|
}
|
|
258
265
|
|
|
259
|
-
public async
|
|
266
|
+
public async getNonceForAddress(
|
|
260
267
|
contractAddress: string,
|
|
261
268
|
blockIdentifier: BlockIdentifier = 'pending'
|
|
262
269
|
): Promise<BigNumberish> {
|
|
@@ -447,17 +454,20 @@ export class SequencerProvider implements ProviderInterface {
|
|
|
447
454
|
return this.fetchEndpoint('get_code', { contractAddress, blockIdentifier });
|
|
448
455
|
}
|
|
449
456
|
|
|
450
|
-
public async waitForTransaction(
|
|
457
|
+
public async waitForTransaction(
|
|
458
|
+
txHash: BigNumberish,
|
|
459
|
+
retryInterval: number = 8000,
|
|
460
|
+
successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING']
|
|
461
|
+
) {
|
|
462
|
+
const errorStates = ['REJECTED', 'NOT_RECEIVED'];
|
|
451
463
|
let onchain = false;
|
|
464
|
+
let res;
|
|
452
465
|
|
|
453
466
|
while (!onchain) {
|
|
454
467
|
// eslint-disable-next-line no-await-in-loop
|
|
455
468
|
await wait(retryInterval);
|
|
456
469
|
// eslint-disable-next-line no-await-in-loop
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
const successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING'];
|
|
460
|
-
const errorStates = ['REJECTED', 'NOT_RECEIVED'];
|
|
470
|
+
res = await this.getTransactionStatus(txHash);
|
|
461
471
|
|
|
462
472
|
if (successStates.includes(res.tx_status)) {
|
|
463
473
|
onchain = true;
|
|
@@ -470,6 +480,8 @@ export class SequencerProvider implements ProviderInterface {
|
|
|
470
480
|
throw error;
|
|
471
481
|
}
|
|
472
482
|
}
|
|
483
|
+
const txReceipt = await this.getTransactionReceipt(txHash);
|
|
484
|
+
return txReceipt;
|
|
473
485
|
}
|
|
474
486
|
|
|
475
487
|
/**
|
package/src/provider/utils.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/* eslint-disable max-classes-per-file */
|
|
2
|
+
import { BN } from 'bn.js';
|
|
3
|
+
|
|
2
4
|
import type { BlockNumber } from '../types';
|
|
3
5
|
import { BigNumberish, isHex, toBN, toHex } from '../utils/number';
|
|
4
6
|
|
|
@@ -34,6 +36,7 @@ export function txIdentifier(txHash?: BigNumberish, txId?: BigNumberish): string
|
|
|
34
36
|
// null appends nothing to the request url
|
|
35
37
|
|
|
36
38
|
export type BlockIdentifier = BlockNumber | BigNumberish;
|
|
39
|
+
export const validBlockTags = ['latest', 'pending'];
|
|
37
40
|
|
|
38
41
|
export class Block {
|
|
39
42
|
hash: BlockIdentifier = null;
|
|
@@ -42,22 +45,26 @@ export class Block {
|
|
|
42
45
|
|
|
43
46
|
tag: BlockIdentifier = null;
|
|
44
47
|
|
|
45
|
-
private setIdentifier
|
|
48
|
+
private setIdentifier(__identifier: BlockIdentifier) {
|
|
49
|
+
if (typeof __identifier === 'string' && isHex(__identifier)) {
|
|
50
|
+
this.hash = __identifier;
|
|
51
|
+
} else if (BN.isBN(__identifier)) {
|
|
52
|
+
this.hash = toHex(__identifier);
|
|
53
|
+
} else if (typeof __identifier === 'number') {
|
|
54
|
+
this.number = __identifier;
|
|
55
|
+
} else if (typeof __identifier === 'string' && validBlockTags.includes(__identifier)) {
|
|
56
|
+
this.tag = __identifier;
|
|
57
|
+
} else {
|
|
58
|
+
// default
|
|
59
|
+
this.tag = 'pending';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
46
62
|
|
|
47
63
|
constructor(_identifier: BlockIdentifier) {
|
|
48
|
-
this.setIdentifier = function (__identifier: BlockIdentifier) {
|
|
49
|
-
if (typeof __identifier === 'string' && isHex(__identifier)) {
|
|
50
|
-
this.hash = __identifier;
|
|
51
|
-
} else if (typeof __identifier === 'number') {
|
|
52
|
-
this.number = __identifier;
|
|
53
|
-
} else {
|
|
54
|
-
this.tag = __identifier;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
64
|
this.setIdentifier(_identifier);
|
|
59
65
|
}
|
|
60
66
|
|
|
67
|
+
// TODO: fix any
|
|
61
68
|
get queryIdentifier(): any {
|
|
62
69
|
if (this.number !== null) {
|
|
63
70
|
return `blockNumber=${this.number}`;
|
|
@@ -70,6 +77,7 @@ export class Block {
|
|
|
70
77
|
return `blockNumber=${this.tag}`;
|
|
71
78
|
}
|
|
72
79
|
|
|
80
|
+
// TODO: fix any
|
|
73
81
|
get identifier(): any {
|
|
74
82
|
if (this.number !== null) {
|
|
75
83
|
return { block_number: this.number };
|
package/src/types/account.ts
CHANGED
|
@@ -2,7 +2,7 @@ import BN from 'bn.js';
|
|
|
2
2
|
|
|
3
3
|
import { BlockIdentifier } from '../provider/utils';
|
|
4
4
|
import { BigNumberish } from '../utils/number';
|
|
5
|
-
import { EstimateFeeResponse } from './provider';
|
|
5
|
+
import { DeclareTransactionReceiptResponse, EstimateFeeResponse } from './provider';
|
|
6
6
|
|
|
7
7
|
export interface EstimateFee extends EstimateFeeResponse {
|
|
8
8
|
suggestedMaxFee: BN;
|
|
@@ -12,3 +12,23 @@ export interface EstimateFeeDetails {
|
|
|
12
12
|
nonce?: BigNumberish;
|
|
13
13
|
blockIdentifier?: BlockIdentifier;
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
export interface DeployContractResponse {
|
|
17
|
+
contract_address: string;
|
|
18
|
+
transaction_hash: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface DeployContractUDCResponse extends DeployContractResponse {
|
|
22
|
+
address: string;
|
|
23
|
+
deployer: string;
|
|
24
|
+
unique: string;
|
|
25
|
+
classHash: string;
|
|
26
|
+
calldata_len: string;
|
|
27
|
+
calldata: Array<string>;
|
|
28
|
+
salt: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type DeclareDeployContractResponse = {
|
|
32
|
+
declare: DeclareTransactionReceiptResponse;
|
|
33
|
+
deploy: DeployContractUDCResponse;
|
|
34
|
+
};
|
package/src/types/lib.ts
CHANGED
|
@@ -21,8 +21,8 @@ export interface ContractClass {
|
|
|
21
21
|
|
|
22
22
|
export type UniversalDeployerContractPayload = {
|
|
23
23
|
classHash: BigNumberish;
|
|
24
|
-
salt
|
|
25
|
-
unique
|
|
24
|
+
salt?: string;
|
|
25
|
+
unique?: boolean;
|
|
26
26
|
constructorCalldata?: RawArgs;
|
|
27
27
|
additionalCalls?: AllowArray<Call>; // support multicall
|
|
28
28
|
};
|
|
@@ -52,6 +52,9 @@ export type DeclareContractPayload = {
|
|
|
52
52
|
classHash: BigNumberish; // Once the classHash is included in CompiledContract, this can be removed
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
+
export type DeclareDeployContractPayload = DeclareContractPayload &
|
|
56
|
+
UniversalDeployerContractPayload;
|
|
57
|
+
|
|
55
58
|
export type DeclareContractTransaction = {
|
|
56
59
|
contractDefinition: ContractClass;
|
|
57
60
|
senderAddress: string;
|
package/src/types/provider.ts
CHANGED
|
@@ -106,11 +106,6 @@ export interface InvokeFunctionResponse {
|
|
|
106
106
|
transaction_hash: string;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
export interface DeployContractResponse {
|
|
110
|
-
contract_address: string;
|
|
111
|
-
transaction_hash: string;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
109
|
export interface DeclareContractResponse {
|
|
115
110
|
transaction_hash: string;
|
|
116
111
|
class_hash: string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { UDC } from '../constants';
|
|
2
|
+
import { InvokeTransactionReceiptResponse } from '../types/provider';
|
|
3
|
+
import { cleanHex } from './number';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parse Transaction Receipt Event from UDC invoke transaction and
|
|
7
|
+
* create DeployContractResponse compatibile response with adition of UDC Event data
|
|
8
|
+
*
|
|
9
|
+
* @param txReceipt
|
|
10
|
+
* @returns DeployContractResponse | UDC Event Response data
|
|
11
|
+
*/
|
|
12
|
+
export function parseUDCEvent(txReceipt: InvokeTransactionReceiptResponse) {
|
|
13
|
+
if (!txReceipt.events) {
|
|
14
|
+
throw new Error('UDC emited event is empty');
|
|
15
|
+
}
|
|
16
|
+
const event = txReceipt.events.find(
|
|
17
|
+
(it) => cleanHex(it.from_address) === cleanHex(UDC.ADDRESS)
|
|
18
|
+
) || {
|
|
19
|
+
data: [],
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
transaction_hash: txReceipt.transaction_hash,
|
|
23
|
+
contract_address: event.data[0],
|
|
24
|
+
address: event.data[0],
|
|
25
|
+
deployer: event.data[1],
|
|
26
|
+
unique: event.data[2],
|
|
27
|
+
classHash: event.data[3],
|
|
28
|
+
calldata_len: event.data[4],
|
|
29
|
+
calldata: event.data.slice(5, 5 + parseInt(event.data[4], 16)),
|
|
30
|
+
salt: event.data[event.data.length - 1],
|
|
31
|
+
};
|
|
32
|
+
}
|
package/src/utils/number.ts
CHANGED
|
@@ -34,6 +34,12 @@ export function toFelt(num: BigNumberish): string {
|
|
|
34
34
|
return toBN(num).toString();
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Remove hex string leading zero and lower case '0x01A'.. -> '0x1a..'
|
|
39
|
+
* @param hex string
|
|
40
|
+
*/
|
|
41
|
+
export const cleanHex = (hex: string) => hex.toLowerCase().replace(/^(0x)0+/, '$1');
|
|
42
|
+
|
|
37
43
|
/*
|
|
38
44
|
Asserts input is equal to or greater then lowerBound and lower then upperBound.
|
|
39
45
|
Assert message specifies inputName.
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
2
|
+
import BN from 'bn.js';
|
|
3
|
+
|
|
4
|
+
import { StarknetChainId } from '../constants';
|
|
5
|
+
|
|
6
|
+
const basicAlphabet = 'abcdefghijklmnopqrstuvwxyz0123456789-';
|
|
7
|
+
const basicSizePlusOne = new BN(basicAlphabet.length + 1);
|
|
8
|
+
const bigAlphabet = '这来';
|
|
9
|
+
const basicAlphabetSize = new BN(basicAlphabet.length);
|
|
10
|
+
const bigAlphabetSize = new BN(bigAlphabet.length);
|
|
11
|
+
const bigAlphabetSizePlusOne = new BN(bigAlphabet.length + 1);
|
|
12
|
+
|
|
13
|
+
function extractStars(str: string): [string, number] {
|
|
14
|
+
let k = 0;
|
|
15
|
+
while (str.endsWith(bigAlphabet[bigAlphabet.length - 1])) {
|
|
16
|
+
str = str.substring(0, str.length - 1);
|
|
17
|
+
k += 1;
|
|
18
|
+
}
|
|
19
|
+
return [str, k];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function useDecoded(encoded: BN[]): string {
|
|
23
|
+
let decoded = '';
|
|
24
|
+
|
|
25
|
+
encoded.forEach((subdomain) => {
|
|
26
|
+
while (!subdomain.isZero()) {
|
|
27
|
+
const code = subdomain.mod(basicSizePlusOne).toNumber();
|
|
28
|
+
subdomain = subdomain.div(basicSizePlusOne);
|
|
29
|
+
if (code === basicAlphabet.length) {
|
|
30
|
+
const nextSubdomain = subdomain.div(bigAlphabetSizePlusOne);
|
|
31
|
+
if (nextSubdomain.isZero()) {
|
|
32
|
+
const code2 = subdomain.mod(bigAlphabetSizePlusOne).toNumber();
|
|
33
|
+
subdomain = nextSubdomain;
|
|
34
|
+
if (code2 === 0) decoded += basicAlphabet[0];
|
|
35
|
+
else decoded += bigAlphabet[code2 - 1];
|
|
36
|
+
} else {
|
|
37
|
+
const code2 = subdomain.mod(bigAlphabetSize).toNumber();
|
|
38
|
+
decoded += bigAlphabet[code2];
|
|
39
|
+
subdomain = subdomain.div(bigAlphabetSize);
|
|
40
|
+
}
|
|
41
|
+
} else decoded += basicAlphabet[code];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const [str, k] = extractStars(decoded);
|
|
45
|
+
if (k)
|
|
46
|
+
decoded =
|
|
47
|
+
str +
|
|
48
|
+
(k % 2 === 0
|
|
49
|
+
? bigAlphabet[bigAlphabet.length - 1].repeat(k / 2 - 1) +
|
|
50
|
+
bigAlphabet[0] +
|
|
51
|
+
basicAlphabet[1]
|
|
52
|
+
: bigAlphabet[bigAlphabet.length - 1].repeat((k - 1) / 2 + 1));
|
|
53
|
+
decoded += '.';
|
|
54
|
+
});
|
|
55
|
+
return decoded.concat('stark');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function useEncoded(decoded: string): BN {
|
|
59
|
+
let encoded = new BN(0);
|
|
60
|
+
let multiplier = new BN(1);
|
|
61
|
+
|
|
62
|
+
if (decoded.endsWith(bigAlphabet[0] + basicAlphabet[1])) {
|
|
63
|
+
const [str, k] = extractStars(decoded.substring(0, decoded.length - 2));
|
|
64
|
+
decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(2 * (k + 1));
|
|
65
|
+
} else {
|
|
66
|
+
const [str, k] = extractStars(decoded);
|
|
67
|
+
if (k) decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(1 + 2 * (k - 1));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
for (let i = 0; i < decoded.length; i += 1) {
|
|
71
|
+
const char = decoded[i];
|
|
72
|
+
const index = basicAlphabet.indexOf(char);
|
|
73
|
+
const bnIndex = new BN(basicAlphabet.indexOf(char));
|
|
74
|
+
|
|
75
|
+
if (index !== -1) {
|
|
76
|
+
// add encoded + multiplier * index
|
|
77
|
+
if (i === decoded.length - 1 && decoded[i] === basicAlphabet[0]) {
|
|
78
|
+
encoded = encoded.add(multiplier.mul(basicAlphabetSize));
|
|
79
|
+
multiplier = multiplier.mul(basicSizePlusOne);
|
|
80
|
+
// add 0
|
|
81
|
+
multiplier = multiplier.mul(basicSizePlusOne);
|
|
82
|
+
} else {
|
|
83
|
+
encoded = encoded.add(multiplier.mul(bnIndex));
|
|
84
|
+
multiplier = multiplier.mul(basicSizePlusOne);
|
|
85
|
+
}
|
|
86
|
+
} else if (bigAlphabet.indexOf(char) !== -1) {
|
|
87
|
+
// add encoded + multiplier * (basicAlphabetSize)
|
|
88
|
+
encoded = encoded.add(multiplier.mul(basicAlphabetSize));
|
|
89
|
+
multiplier = multiplier.mul(basicSizePlusOne);
|
|
90
|
+
// add encoded + multiplier * index
|
|
91
|
+
const newid = (i === decoded.length - 1 ? 1 : 0) + bigAlphabet.indexOf(char);
|
|
92
|
+
encoded = encoded.add(multiplier.mul(new BN(newid)));
|
|
93
|
+
multiplier = multiplier.mul(bigAlphabetSize);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return encoded;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function getStarknetIdContract(chainId: StarknetChainId): string {
|
|
101
|
+
const starknetIdMainnetContract =
|
|
102
|
+
'0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678';
|
|
103
|
+
const starknetIdTestnetContract =
|
|
104
|
+
'0x05cf267a0af6101667013fc6bd3f6c11116a14cda9b8c4b1198520d59f900b17';
|
|
105
|
+
|
|
106
|
+
switch (chainId) {
|
|
107
|
+
case StarknetChainId.MAINNET:
|
|
108
|
+
return starknetIdMainnetContract;
|
|
109
|
+
|
|
110
|
+
case StarknetChainId.TESTNET:
|
|
111
|
+
return starknetIdTestnetContract;
|
|
112
|
+
|
|
113
|
+
default:
|
|
114
|
+
throw new Error('Starknet.id is not yet deployed on this network');
|
|
115
|
+
}
|
|
116
|
+
}
|
package/www/docs/API/account.md
CHANGED
|
@@ -6,7 +6,7 @@ sidebar_position: 2
|
|
|
6
6
|
|
|
7
7
|
An Account extends <ins>[`Provider`](/docs/API/provider)</ins> and inherits all of its methods.
|
|
8
8
|
|
|
9
|
-
It also introduces new methods that allow Accounts to create and verify signatures with a custom <ins>[`Signer`](/docs/API/signer)</ins
|
|
9
|
+
It also introduces new methods that allow Accounts to create and verify signatures with a custom <ins>[`Signer`](/docs/API/signer)</ins>, declare and deploy Contract and deploy new Account
|
|
10
10
|
|
|
11
11
|
This API is the primary way to interact with an account contract on StarkNet.
|
|
12
12
|
|
|
@@ -89,7 +89,7 @@ The _estimateFeeDetails_ object may include any of:
|
|
|
89
89
|
|
|
90
90
|
account.**estimateAccountDeployFee**(contractPayload [ , estimateFeeDetails ]) => _Promise < EstimateFeeResponse >_
|
|
91
91
|
|
|
92
|
-
Estimate Fee for executing a DEPLOY_ACCOUNT transaction on
|
|
92
|
+
Estimate Fee for executing a DEPLOY_ACCOUNT transaction on StarkNet
|
|
93
93
|
|
|
94
94
|
The _contractPayload_ object structure:
|
|
95
95
|
|
|
@@ -142,6 +142,8 @@ The _transactionsDetail_ object may include any of:
|
|
|
142
142
|
|
|
143
143
|
<hr />
|
|
144
144
|
|
|
145
|
+
### Declare
|
|
146
|
+
|
|
145
147
|
account.**declare**(contractPayload [ , transactionsDetail ]) => _Promise < DeclareContractResponse >_
|
|
146
148
|
|
|
147
149
|
Declares a given compiled contract (json) to starknet.
|
|
@@ -180,6 +182,158 @@ const declareTx = await account.declare({
|
|
|
180
182
|
|
|
181
183
|
<hr />
|
|
182
184
|
|
|
185
|
+
### Deploy
|
|
186
|
+
|
|
187
|
+
Deploys a given compiled contract (json) to starknet, wrapper around _execute_ invoke function
|
|
188
|
+
|
|
189
|
+
**deploy**(deployContractPayload [ , transactionsDetail ]) => _Promise < InvokeFunctionResponse >_
|
|
190
|
+
|
|
191
|
+
@param object **_deployContractPayload_**
|
|
192
|
+
|
|
193
|
+
- **classHash**: computed class hash of compiled contract
|
|
194
|
+
- **constructorCalldata**: constructor calldata
|
|
195
|
+
- optional salt: address salt - default random
|
|
196
|
+
- optional unique: bool if true ensure unique salt - default true
|
|
197
|
+
- optional additionalCalls - optional additional calls array to support multi-call
|
|
198
|
+
|
|
199
|
+
@param object **transactionsDetail** Invocation Details
|
|
200
|
+
|
|
201
|
+
- optional nonce
|
|
202
|
+
- optional version
|
|
203
|
+
- optional maxFee
|
|
204
|
+
|
|
205
|
+
@returns **transaction_hash**
|
|
206
|
+
|
|
207
|
+
Example:
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
const deployment = await account.deploy({
|
|
211
|
+
classHash: erc20ClassHash,
|
|
212
|
+
constructorCalldata: [
|
|
213
|
+
encodeShortString('Token'),
|
|
214
|
+
encodeShortString('ERC20'),
|
|
215
|
+
account.address,
|
|
216
|
+
],
|
|
217
|
+
salt: randomAddress(),
|
|
218
|
+
unique: true, // Using true here so as not to clash with normal erc20 deploy in account and provider test
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
await provider.waitForTransaction(deployment.transaction_hash);
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Example multi-call:
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
TODO Example with multi-call
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
<hr />
|
|
231
|
+
|
|
232
|
+
### DeployContract
|
|
233
|
+
|
|
234
|
+
✅ NEW
|
|
235
|
+
High level wrapper for deploy. Doesn't require waitForTransaction. Response similar to deprecated provider deployContract.
|
|
236
|
+
|
|
237
|
+
**deployContract**(payload [ , details ]) => _Promise < DeployContractUDCResponse >_
|
|
238
|
+
|
|
239
|
+
@param object **_payload_** UniversalDeployerContractPayload
|
|
240
|
+
|
|
241
|
+
- **classHash**: computed class hash of compiled contract
|
|
242
|
+
- **constructorCalldata**: constructor calldata
|
|
243
|
+
- optional salt: address salt - default random
|
|
244
|
+
- optional unique: bool if true ensure unique salt - default true
|
|
245
|
+
- optional additionalCalls - optional additional calls array to support multi-call
|
|
246
|
+
|
|
247
|
+
@param object **details** InvocationsDetails
|
|
248
|
+
|
|
249
|
+
- optional nonce
|
|
250
|
+
- optional version
|
|
251
|
+
- optional maxFee
|
|
252
|
+
|
|
253
|
+
@returns Promise DeployContractUDCResponse
|
|
254
|
+
|
|
255
|
+
- contract_address
|
|
256
|
+
- transaction_hash
|
|
257
|
+
- address
|
|
258
|
+
- deployer
|
|
259
|
+
- unique
|
|
260
|
+
- classHash
|
|
261
|
+
- calldata_len
|
|
262
|
+
- calldata
|
|
263
|
+
- salt
|
|
264
|
+
|
|
265
|
+
Example:
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
const deployResponse = await account.deployContract({
|
|
269
|
+
classHash: erc20ClassHash,
|
|
270
|
+
constructorCalldata: [
|
|
271
|
+
encodeShortString('Token'),
|
|
272
|
+
encodeShortString('ERC20'),
|
|
273
|
+
account.address,
|
|
274
|
+
],
|
|
275
|
+
});
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
<hr />
|
|
279
|
+
|
|
280
|
+
### DeclareDeploy
|
|
281
|
+
|
|
282
|
+
✅ NEW
|
|
283
|
+
High level wrapper for declare & deploy. Doesn't require waitForTransaction. Functionality similar to deprecated provider deployContract. Declare and Deploy contract using single function.
|
|
284
|
+
|
|
285
|
+
**declareDeploy**(payload [ , details ]) => _Promise < DeclareDeployContractResponse >_
|
|
286
|
+
|
|
287
|
+
@param object **_payload_** DeclareDeployContractPayload
|
|
288
|
+
|
|
289
|
+
- **contract**: compiled contract code
|
|
290
|
+
- **classHash**: computed class hash of compiled contract
|
|
291
|
+
- optional constructorCalldata: constructor calldata
|
|
292
|
+
- optional salt: address salt - default random
|
|
293
|
+
- optional unique: bool if true ensure unique salt - default true
|
|
294
|
+
- optional additionalCalls - optional additional calls array to support multi-call
|
|
295
|
+
|
|
296
|
+
@param object **details** InvocationsDetails
|
|
297
|
+
|
|
298
|
+
- optional nonce
|
|
299
|
+
- optional version
|
|
300
|
+
- optional maxFee
|
|
301
|
+
|
|
302
|
+
@returns Promise object DeclareDeployContractResponse
|
|
303
|
+
|
|
304
|
+
- declare: CommonTransactionReceiptResponse
|
|
305
|
+
- transaction_hash
|
|
306
|
+
- deploy: DeployContractUDCResponse;
|
|
307
|
+
- contract_address
|
|
308
|
+
- transaction_hash
|
|
309
|
+
- address
|
|
310
|
+
- deployer
|
|
311
|
+
- unique
|
|
312
|
+
- classHash
|
|
313
|
+
- calldata_len
|
|
314
|
+
- calldata
|
|
315
|
+
- salt
|
|
316
|
+
<hr />
|
|
317
|
+
|
|
318
|
+
Example:
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
const declareDeploy = await account.declareDeploy({
|
|
322
|
+
contract: compiledErc20,
|
|
323
|
+
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
|
|
324
|
+
constructorCalldata: [
|
|
325
|
+
encodeShortString('Token'),
|
|
326
|
+
encodeShortString('ERC20'),
|
|
327
|
+
account.address,
|
|
328
|
+
],
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
const declareTransactionHash = declareDeploy.declare.transaction_hash
|
|
332
|
+
const erc20Address = declareDeploy.deploy.contract_address;
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### deployAccount
|
|
336
|
+
|
|
183
337
|
account.**deployAccount**(contractPayload [ , transactionsDetail ]) => _Promise < DeployContractResponse >_
|
|
184
338
|
|
|
185
339
|
Declares a given compiled contract (json) to starknet.
|
|
@@ -263,3 +417,23 @@ The _details_ object may include any of:
|
|
|
263
417
|
|
|
264
418
|
- details.**blockIdentifier**
|
|
265
419
|
- details.**nonce**
|
|
420
|
+
|
|
421
|
+
<hr />
|
|
422
|
+
|
|
423
|
+
account.**getStarkName**(StarknetIdContract) => _Promise<string | Error>_
|
|
424
|
+
|
|
425
|
+
Gets starknet.id stark name with the address of the account
|
|
426
|
+
|
|
427
|
+
The _StarknetIdContract_ argument can be undefined, if it is, the function will automatically use official starknet id contracts of your network (It currently supports TESTNET 1 only).
|
|
428
|
+
|
|
429
|
+
Returns directly a string (Example: `vitalik.stark`).
|
|
430
|
+
|
|
431
|
+
<hr />
|
|
432
|
+
|
|
433
|
+
account.**getAddressFromStarkName**(name, StarknetIdContract) => _Promise<string | Error>_
|
|
434
|
+
|
|
435
|
+
Gets account address with the starknet id stark name.
|
|
436
|
+
|
|
437
|
+
The _StarknetIdContract_ argument can be undefined, if it is, the function will automatically use official starknet id contracts of your network (It currently supports TESTNET 1 only).
|
|
438
|
+
|
|
439
|
+
Returns directly the address in a string (Example: `0xff...34`).
|
|
@@ -8,33 +8,29 @@ Contract Factory allow you to deploy contracts to StarkNet. To deploy a Contract
|
|
|
8
8
|
|
|
9
9
|
## Creating an instance
|
|
10
10
|
|
|
11
|
-
`new starknet.ContractFactory( compiledContract ,
|
|
11
|
+
`new starknet.ContractFactory( compiledContract, classHash, account, [ , abi ] )`
|
|
12
12
|
|
|
13
13
|
Creates a new instance of a ContractFactory for the contract described by the _compiledContract_.
|
|
14
14
|
|
|
15
|
-
`contractFactory.connect(
|
|
15
|
+
`contractFactory.connect(account)` _for changing the provider or account_
|
|
16
16
|
|
|
17
17
|
`contractFactory.attach(address)` _for changing the address of the connected contract factory_
|
|
18
18
|
|
|
19
19
|
## Properties
|
|
20
20
|
|
|
21
|
-
contractFactory.**
|
|
21
|
+
contractFactory.**compiledContract** => _CompiledContract_ (the compiled contract the contractFactory was constructed with)
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
contractFactory.**classHash** => _string_ (contract classHash can be obtained using tool for compiling contract)
|
|
24
24
|
|
|
25
|
-
contractFactory.**
|
|
25
|
+
contractFactory.**account** => _AccountInterface_ (account that are used to interact with the network)
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
contractFactory.**providerOrAccount** => _ProviderInterface | AccountInterface_
|
|
30
|
-
|
|
31
|
-
Provider or account that are used to interact with the network.
|
|
27
|
+
contractFactory.**abi** => _Abi_ (the ABI the contractFactory was constructed with)
|
|
32
28
|
|
|
33
29
|
## Methods
|
|
34
30
|
|
|
35
31
|
contractFactory.**attach**( address ) ⇒ _Contract_
|
|
36
32
|
|
|
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
|
|
33
|
+
Return an instance of a _Contract_ attached to address. This is the same as using the _Contract_ constructor with address and this _compiledContract_ and _account_ passed in when creating the ContractFactory.
|
|
38
34
|
|
|
39
35
|
<hr />
|
|
40
36
|
|
package/www/docs/API/provider.md
CHANGED
|
@@ -141,9 +141,9 @@ Estimate fee for invoke transaction.
|
|
|
141
141
|
|
|
142
142
|
<hr/>
|
|
143
143
|
|
|
144
|
-
provider.**
|
|
144
|
+
provider.**getNonceForAddress**(contractAddress, blockIdentifier) => _Promise < BigNumberish >_
|
|
145
145
|
|
|
146
|
-
Gets the nonce of the provided contractAddress.
|
|
146
|
+
Gets the nonce of the provided contractAddress. This was renamed from `getNonce` to `getNonceForAddress` to avoid confusion when inheriting an Account from the Provider class.
|
|
147
147
|
|
|
148
148
|
<hr/>
|
|
149
149
|
|
|
@@ -242,7 +242,9 @@ Estimate fee for declare transaction.
|
|
|
242
242
|
|
|
243
243
|
<hr/>
|
|
244
244
|
|
|
245
|
-
|
|
245
|
+
### waitForTransaction
|
|
246
|
+
|
|
247
|
+
provider.**waitForTransaction**(txHash [ , retryInterval]) => _Promise < GetTransactionReceiptResponse >_
|
|
246
248
|
|
|
247
249
|
Wait for the transaction to be accepted on L2 or L1.
|
|
248
250
|
|
|
@@ -476,12 +478,6 @@ Gets the latest block number.
|
|
|
476
478
|
|
|
477
479
|
<hr/>
|
|
478
480
|
|
|
479
|
-
provider.**getNonce**(contractAddress, blockIdentifier) => _Promise < BigNumberish >_
|
|
480
|
-
|
|
481
|
-
Gets the nonce of the provided contractAddress
|
|
482
|
-
|
|
483
|
-
<hr/>
|
|
484
|
-
|
|
485
481
|
provider.**getPendingTransactions**() => _Promise < PendingTransactions >_
|
|
486
482
|
|
|
487
483
|
###### _PendingTransactions_
|