starknet 3.10.1 → 3.11.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 +26 -0
- package/__tests__/account.test.ts +3 -1
- package/__tests__/accountContract.test.ts +3 -1
- package/__tests__/provider.test.ts +7 -7
- package/__tests__/utils/address.test.ts +30 -1
- package/dist/provider/default.d.ts +2 -6
- package/dist/provider/default.js +15 -11
- package/dist/provider/interface.d.ts +2 -5
- package/dist/signer/index.d.ts +0 -1
- package/dist/signer/index.js +0 -1
- package/dist/types/api.d.ts +10 -2
- package/dist/utils/address.d.ts +5 -2
- package/dist/utils/address.js +24 -5
- package/dist/utils/encode.js +1 -1
- package/package.json +2 -4
- package/provider/default.d.ts +2 -9
- package/provider/default.js +19 -22
- package/provider/interface.d.ts +2 -8
- package/signer/index.d.ts +0 -1
- package/signer/index.js +0 -1
- package/src/provider/default.ts +17 -15
- package/src/provider/interface.ts +2 -8
- package/src/signer/index.ts +0 -1
- package/src/types/api.ts +11 -2
- package/src/utils/address.ts +29 -8
- package/src/utils/encode.ts +1 -1
- package/types/api.d.ts +11 -2
- package/utils/address.d.ts +5 -2
- package/utils/address.js +35 -5
- package/utils/encode.js +3 -1
- package/www/code-examples/account.js +8 -5
- package/www/code-examples/amm.js +13 -18
- package/www/code-examples/erc20.js +6 -3
- package/www/docs/API/account.md +94 -0
- package/www/docs/API/changelog.md +15 -0
- package/www/docs/API/contract.md +73 -2
- package/www/docs/API/contractFacotry.md +42 -0
- package/www/docs/API/index.md +0 -1
- package/www/docs/API/provider.md +204 -1
- package/www/docs/API/signer.md +35 -0
- package/www/docs/API/utils.md +34 -0
- package/www/docusaurus.config.js +3 -4
- package/www/guides/account.md +1 -1
- package/www/guides/erc20.md +7 -0
- package/www/guides/intro.md +1 -0
- package/www/sidebars.js +1 -1
- package/dist/signer/ledger.d.ts +0 -12
- package/dist/signer/ledger.js +0 -140
- package/signer/ledger.d.ts +0 -15
- package/signer/ledger.js +0 -250
- package/src/signer/ledger.ts +0 -86
package/src/utils/address.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
/* eslint-disable no-bitwise */
|
|
2
|
+
import { arrayify } from '@ethersproject/bytes';
|
|
3
|
+
|
|
1
4
|
import { MASK_251, ZERO } from '../constants';
|
|
2
5
|
import { addHexPrefix, removeHexPrefix } from './encode';
|
|
3
|
-
import {
|
|
6
|
+
import { pedersen } from './hash';
|
|
7
|
+
import { BigNumberish, assertInRange, toBN, toHex } from './number';
|
|
4
8
|
|
|
5
|
-
export function addAddressPadding(address:
|
|
6
|
-
return addHexPrefix(removeHexPrefix(address).padStart(64, '0'));
|
|
9
|
+
export function addAddressPadding(address: BigNumberish): string {
|
|
10
|
+
return addHexPrefix(removeHexPrefix(toHex(toBN(address))).padStart(64, '0'));
|
|
7
11
|
}
|
|
8
12
|
|
|
9
|
-
export function validateAndParseAddress(address:
|
|
10
|
-
if (typeof address !== 'string') {
|
|
11
|
-
throw new Error('Invalid Address Type');
|
|
12
|
-
}
|
|
13
|
-
|
|
13
|
+
export function validateAndParseAddress(address: BigNumberish): string {
|
|
14
14
|
assertInRange(address, ZERO, MASK_251, 'Starknet Address');
|
|
15
15
|
|
|
16
16
|
const result = addAddressPadding(address);
|
|
@@ -21,3 +21,24 @@ export function validateAndParseAddress(address: string): string {
|
|
|
21
21
|
|
|
22
22
|
return result;
|
|
23
23
|
}
|
|
24
|
+
|
|
25
|
+
// from https://github.com/ethers-io/ethers.js/blob/fc1e006575d59792fa97b4efb9ea2f8cca1944cf/packages/address/src.ts/index.ts#L12
|
|
26
|
+
export function getChecksumAddress(address: BigNumberish): string {
|
|
27
|
+
const chars = removeHexPrefix(validateAndParseAddress(address)).toLowerCase().split('');
|
|
28
|
+
const hashed = arrayify(pedersen([0, address]), { hexPad: 'left' }); // as the hash will be 251 bits (63 chars) we need to pad it to 64 chars without changing the number value ("left")
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < chars.length; i += 2) {
|
|
31
|
+
if (hashed[i >> 1] >> 4 >= 8) {
|
|
32
|
+
chars[i] = chars[i].toUpperCase();
|
|
33
|
+
}
|
|
34
|
+
if ((hashed[i >> 1] & 0x0f) >= 8) {
|
|
35
|
+
chars[i + 1] = chars[i + 1].toUpperCase();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return addHexPrefix(chars.join(''));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function validateChecksumAddress(address: string): boolean {
|
|
43
|
+
return getChecksumAddress(address) === address;
|
|
44
|
+
}
|
package/src/utils/encode.ts
CHANGED
|
@@ -4,7 +4,7 @@ export const IS_BROWSER = typeof window !== 'undefined';
|
|
|
4
4
|
const STRING_ZERO = '0';
|
|
5
5
|
|
|
6
6
|
export function arrayBufferToString(array: ArrayBuffer): string {
|
|
7
|
-
return
|
|
7
|
+
return new Uint8Array(array).reduce((data, byte) => data + String.fromCharCode(byte), '');
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export function btoaUniversal(b: ArrayBuffer): string {
|
package/types/api.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import BN from 'bn.js';
|
|
2
|
+
|
|
1
3
|
import { BlockIdentifier } from '../provider/utils';
|
|
2
4
|
import { BigNumberish } from '../utils/number';
|
|
3
5
|
import {
|
|
@@ -42,6 +44,13 @@ export declare type Endpoints = {
|
|
|
42
44
|
REQUEST: never;
|
|
43
45
|
RESPONSE: GetTransactionTraceResponse;
|
|
44
46
|
};
|
|
47
|
+
get_transaction_receipt: {
|
|
48
|
+
QUERY: {
|
|
49
|
+
transactionHash: string;
|
|
50
|
+
};
|
|
51
|
+
REQUEST: never;
|
|
52
|
+
RESPONSE: TransactionReceiptResponse;
|
|
53
|
+
};
|
|
45
54
|
get_storage_at: {
|
|
46
55
|
QUERY: {
|
|
47
56
|
contractAddress: string;
|
|
@@ -201,7 +210,7 @@ export declare type AddTransactionResponse = {
|
|
|
201
210
|
transaction_hash: string;
|
|
202
211
|
address?: string;
|
|
203
212
|
};
|
|
204
|
-
export declare type
|
|
213
|
+
export declare type TransactionReceiptResponse = {
|
|
205
214
|
status: Status;
|
|
206
215
|
transaction_hash: string;
|
|
207
216
|
transaction_index: number;
|
|
@@ -211,7 +220,7 @@ export declare type TransactionReceipt = {
|
|
|
211
220
|
events: string[];
|
|
212
221
|
};
|
|
213
222
|
export declare type EstimateFeeResponse = {
|
|
214
|
-
amount:
|
|
223
|
+
amount: BN;
|
|
215
224
|
unit: string;
|
|
216
225
|
};
|
|
217
226
|
export declare type RawArgs = {
|
package/utils/address.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
1
|
+
import { BigNumberish } from './number';
|
|
2
|
+
export declare function addAddressPadding(address: BigNumberish): string;
|
|
3
|
+
export declare function validateAndParseAddress(address: BigNumberish): string;
|
|
4
|
+
export declare function getChecksumAddress(address: BigNumberish): string;
|
|
5
|
+
export declare function validateChecksumAddress(address: string): boolean;
|
package/utils/address.js
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.validateChecksumAddress =
|
|
4
|
+
exports.getChecksumAddress =
|
|
5
|
+
exports.validateAndParseAddress =
|
|
6
|
+
exports.addAddressPadding =
|
|
7
|
+
void 0;
|
|
8
|
+
/* eslint-disable no-bitwise */
|
|
9
|
+
var bytes_1 = require('@ethersproject/bytes');
|
|
4
10
|
var constants_1 = require('../constants');
|
|
5
11
|
var encode_1 = require('./encode');
|
|
12
|
+
var hash_1 = require('./hash');
|
|
6
13
|
var number_1 = require('./number');
|
|
7
14
|
function addAddressPadding(address) {
|
|
8
|
-
return (0, encode_1.addHexPrefix)(
|
|
15
|
+
return (0, encode_1.addHexPrefix)(
|
|
16
|
+
(0, encode_1.removeHexPrefix)((0, number_1.toHex)((0, number_1.toBN)(address))).padStart(
|
|
17
|
+
64,
|
|
18
|
+
'0'
|
|
19
|
+
)
|
|
20
|
+
);
|
|
9
21
|
}
|
|
10
22
|
exports.addAddressPadding = addAddressPadding;
|
|
11
23
|
function validateAndParseAddress(address) {
|
|
12
|
-
if (typeof address !== 'string') {
|
|
13
|
-
throw new Error('Invalid Address Type');
|
|
14
|
-
}
|
|
15
24
|
(0, number_1.assertInRange)(address, constants_1.ZERO, constants_1.MASK_251, 'Starknet Address');
|
|
16
25
|
var result = addAddressPadding(address);
|
|
17
26
|
if (!result.match(/^(0x)?[0-9a-fA-F]{64}$/)) {
|
|
@@ -20,3 +29,24 @@ function validateAndParseAddress(address) {
|
|
|
20
29
|
return result;
|
|
21
30
|
}
|
|
22
31
|
exports.validateAndParseAddress = validateAndParseAddress;
|
|
32
|
+
// from https://github.com/ethers-io/ethers.js/blob/fc1e006575d59792fa97b4efb9ea2f8cca1944cf/packages/address/src.ts/index.ts#L12
|
|
33
|
+
function getChecksumAddress(address) {
|
|
34
|
+
var chars = (0, encode_1.removeHexPrefix)(validateAndParseAddress(address))
|
|
35
|
+
.toLowerCase()
|
|
36
|
+
.split('');
|
|
37
|
+
var hashed = (0, bytes_1.arrayify)((0, hash_1.pedersen)([0, address]), { hexPad: 'left' }); // as the hash will be 251 bits (63 chars) we need to pad it to 64 chars without changing the number value ("left")
|
|
38
|
+
for (var i = 0; i < chars.length; i += 2) {
|
|
39
|
+
if (hashed[i >> 1] >> 4 >= 8) {
|
|
40
|
+
chars[i] = chars[i].toUpperCase();
|
|
41
|
+
}
|
|
42
|
+
if ((hashed[i >> 1] & 0x0f) >= 8) {
|
|
43
|
+
chars[i + 1] = chars[i + 1].toUpperCase();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return (0, encode_1.addHexPrefix)(chars.join(''));
|
|
47
|
+
}
|
|
48
|
+
exports.getChecksumAddress = getChecksumAddress;
|
|
49
|
+
function validateChecksumAddress(address) {
|
|
50
|
+
return getChecksumAddress(address) === address;
|
|
51
|
+
}
|
|
52
|
+
exports.validateChecksumAddress = validateChecksumAddress;
|
package/utils/encode.js
CHANGED
|
@@ -50,7 +50,9 @@ exports.utf8ToArray =
|
|
|
50
50
|
exports.IS_BROWSER = typeof window !== 'undefined';
|
|
51
51
|
var STRING_ZERO = '0';
|
|
52
52
|
function arrayBufferToString(array) {
|
|
53
|
-
return
|
|
53
|
+
return new Uint8Array(array).reduce(function (data, byte) {
|
|
54
|
+
return data + String.fromCharCode(byte);
|
|
55
|
+
}, '');
|
|
54
56
|
}
|
|
55
57
|
exports.arrayBufferToString = arrayBufferToString;
|
|
56
58
|
function btoaUniversal(b) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
1
|
// Install the latest version of starknet with npm install starknet@next and import starknet
|
|
3
|
-
import * as starknet from
|
|
2
|
+
import * as starknet from 'starknet';
|
|
4
3
|
|
|
5
4
|
// Generate public and private key pair.
|
|
6
5
|
|
|
@@ -8,7 +7,11 @@ const keyPair = starknet.ec.genKeyPair();
|
|
|
8
7
|
const starkKey = starknet.ec.getStarkKey(keyPair);
|
|
9
8
|
const starkKeyInt = starknet.number.toBN(starknet.encode.removeHexPrefix(starkKey), 16);
|
|
10
9
|
|
|
11
|
-
const { address: walletAddressLocal } = await provider.deployContract({
|
|
10
|
+
const { address: walletAddressLocal } = await provider.deployContract({
|
|
11
|
+
contract: COMPILED_WALLET_CONTRACT_JSON,
|
|
12
|
+
constructorCallData: [starkKeyInt],
|
|
13
|
+
addressSalt: 0,
|
|
14
|
+
});
|
|
12
15
|
|
|
13
16
|
walletAddress = walletAddressLocal;
|
|
14
17
|
|
|
@@ -28,7 +31,7 @@ const balanceBeforeTransfer = await erc20.call('balance_of', {
|
|
|
28
31
|
user: walletAddress,
|
|
29
32
|
}).res;
|
|
30
33
|
|
|
31
|
-
console.log(number.toBN(res).toString())
|
|
34
|
+
console.log(number.toBN(res).toString());
|
|
32
35
|
|
|
33
36
|
const { nonce } = await wallet.call('get_nonce');
|
|
34
37
|
const msgHash = encode.addHexPrefix(
|
|
@@ -59,4 +62,4 @@ const balanceAfterTransfer = await erc20.call('balance_of', {
|
|
|
59
62
|
user: walletAddress,
|
|
60
63
|
}).res;
|
|
61
64
|
|
|
62
|
-
console.log('Balance after transfer', balanceAfterTransfer)
|
|
65
|
+
console.log('Balance after transfer', balanceAfterTransfer);
|
package/www/code-examples/amm.js
CHANGED
|
@@ -1,37 +1,33 @@
|
|
|
1
1
|
import { defaultProvider, stark } from 'starknet';
|
|
2
2
|
const { getSelectorFromName } = stark;
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* !! IMPORTANT NOTE !! When fees are introduced all function invocations will go through the account account contract and this example will be deprecated.
|
|
7
|
-
**/
|
|
6
|
+
**/
|
|
8
7
|
|
|
9
|
-
const CONTRACT_ADDRESS =
|
|
10
|
-
"0x03e19baa6cb2078631bcdb34844f3f7879449a544c9ce722681a54af08cff4b9";
|
|
8
|
+
const CONTRACT_ADDRESS = '0x03e19baa6cb2078631bcdb34844f3f7879449a544c9ce722681a54af08cff4b9';
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* invokeFunction() example
|
|
14
|
-
**/
|
|
12
|
+
**/
|
|
15
13
|
|
|
16
14
|
/** Reset the liquidity pool **/
|
|
17
|
-
const addLiquidityResponse = await defaultProvider.LEGACYinvokeFunction(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
);
|
|
15
|
+
const addLiquidityResponse = await defaultProvider.LEGACYinvokeFunction({
|
|
16
|
+
contractAddress: CONTRACT_ADDRESS,
|
|
17
|
+
entrypoint: 'init_pool',
|
|
18
|
+
calldata: ['1000000', '1000000'],
|
|
19
|
+
});
|
|
24
20
|
console.log(addLiquidityResponse);
|
|
25
21
|
|
|
26
22
|
/**
|
|
27
23
|
* callContract() example
|
|
28
|
-
**/
|
|
24
|
+
**/
|
|
29
25
|
|
|
30
26
|
/** Get the balance of the liquidity pool of token A **/
|
|
31
27
|
const poolBalanceTokenA = await defaultProvider.callContract({
|
|
32
28
|
contractAddress: CONTRACT_ADDRESS,
|
|
33
|
-
entrypoint:
|
|
34
|
-
calldata: [
|
|
29
|
+
entrypoint: 'get_pool_token_balance',
|
|
30
|
+
calldata: ['1'], // Account 1 (no account implemented)
|
|
35
31
|
});
|
|
36
32
|
const balanceA = poolBalanceTokenA.result[0];
|
|
37
33
|
console.log('token a liquidity pool balance: ', parseInt(balanceA, 16));
|
|
@@ -39,11 +35,10 @@ console.log('token a liquidity pool balance: ', parseInt(balanceA, 16));
|
|
|
39
35
|
/** Get the balance of the liquidity pool of token B **/
|
|
40
36
|
const poolBalanceTokenB = await defaultProvider.callContract({
|
|
41
37
|
contractAddress: CONTRACT_ADDRESS,
|
|
42
|
-
entrypoint:
|
|
43
|
-
calldata: [
|
|
38
|
+
entrypoint: 'get_pool_token_balance',
|
|
39
|
+
calldata: ['2'],
|
|
44
40
|
});
|
|
45
41
|
const balanceB = poolBalanceTokenB.result[0];
|
|
46
42
|
console.log('token b liquidity pool balance: ', parseInt(balanceB, 16));
|
|
47
43
|
|
|
48
|
-
|
|
49
44
|
/** Make a swap */
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import * as starknet from
|
|
1
|
+
import * as starknet from 'starknet';
|
|
2
2
|
|
|
3
3
|
const keyPair = starknet.ec.genKeyPair();
|
|
4
4
|
const starkKey = starknet.ec.getStarkKey(keyPair);
|
|
5
5
|
const starkKeyInt = starknet.number.toBN(starknet.encode.removeHexPrefix(starkKey), 16);
|
|
6
6
|
|
|
7
|
-
const deployWalletTx = await provider.deployContract({
|
|
7
|
+
const deployWalletTx = await provider.deployContract({
|
|
8
|
+
contract: COMPILED_WALLET_CONTRACT_JSON,
|
|
9
|
+
constructorCallData: [starkKeyInt],
|
|
10
|
+
addressSalt: 0,
|
|
11
|
+
});
|
|
8
12
|
|
|
9
13
|
await defaultProvider.waitForTx(deployWalletTx.transaction_hash);
|
|
10
|
-
|
package/www/docs/API/account.md
CHANGED
|
@@ -9,3 +9,97 @@ An Account extends <ins>[`Provider`](/docs/API/provider)</ins> and inherits all
|
|
|
9
9
|
It also introduces new methods that allow Accounts to create and verify signatures with a custom <ins>[`Signer`](/docs/API/signer)</ins>.
|
|
10
10
|
|
|
11
11
|
This API is the primary way to interact with an account contract on StarkNet.
|
|
12
|
+
|
|
13
|
+
## Creating an instance
|
|
14
|
+
|
|
15
|
+
For creating new instance of Account, account contract must be deployed. Also there needs to be a Provider instance that will be passed in the constructor and key pair for the account.
|
|
16
|
+
|
|
17
|
+
`new starknet.Account(Provider, address, starkKeyPair)`
|
|
18
|
+
|
|
19
|
+
## Account Properties
|
|
20
|
+
|
|
21
|
+
contract.**address** => _string_
|
|
22
|
+
|
|
23
|
+
The address of the account contract
|
|
24
|
+
|
|
25
|
+
## Account methods
|
|
26
|
+
|
|
27
|
+
account.**getNonce()** => _Promise < string >_
|
|
28
|
+
|
|
29
|
+
Gets new Nonce for the next transaction
|
|
30
|
+
|
|
31
|
+
<hr />
|
|
32
|
+
|
|
33
|
+
account.**estimateFee**(calls [ , options ]) => _Promise < EstimateFeeResponse >_
|
|
34
|
+
|
|
35
|
+
Gets the estimated fee for the call(s)
|
|
36
|
+
|
|
37
|
+
The _options_ object may include any of:
|
|
38
|
+
|
|
39
|
+
- options.**blockIdentifier** - Block Identifier for the transaction
|
|
40
|
+
- options.**nonce** - Nonce for the transaction
|
|
41
|
+
|
|
42
|
+
###### EstimateFeeResponse
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
{
|
|
46
|
+
amount: number;
|
|
47
|
+
unit: string;
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
<hr />
|
|
52
|
+
|
|
53
|
+
account.**execute**(calls [ , abi , transactionsDetail ]) => _Promise < AddTransactionResponse >_
|
|
54
|
+
|
|
55
|
+
Executes one or multiple calls using the account contract
|
|
56
|
+
|
|
57
|
+
The _transactionsDetail_ object may include any of:
|
|
58
|
+
|
|
59
|
+
- transactionsDetail.**maxFee** - Max Fee that that will be used to execute the call(s)
|
|
60
|
+
- transactionsDetail.**nonce** - Nonce for the transaction
|
|
61
|
+
- transactionsDetail.**version** - Version for the transaction (default is 0)
|
|
62
|
+
|
|
63
|
+
###### AddTransactionResponse
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
{
|
|
67
|
+
code: 'TRANSACTION_RECEIVED';
|
|
68
|
+
transaction_hash: string;
|
|
69
|
+
address?: string;
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
<hr />
|
|
74
|
+
|
|
75
|
+
account.**signMessage**(typedData) => _Promise < Signature >_
|
|
76
|
+
|
|
77
|
+
Creates a signature from the passed data
|
|
78
|
+
|
|
79
|
+
###### Signature
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
string[];
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
<hr />
|
|
86
|
+
|
|
87
|
+
account.**hashMessage**(typedData) => _Promise < string >_
|
|
88
|
+
|
|
89
|
+
Creates a hash from the passed data
|
|
90
|
+
|
|
91
|
+
<hr />
|
|
92
|
+
|
|
93
|
+
account.**verifyMessageHash**(hash, signature) => _Promise < boolean >_
|
|
94
|
+
|
|
95
|
+
Verify a signature of a given hash
|
|
96
|
+
|
|
97
|
+
**WARNING** This method is not recommended, use verifyMessage instead
|
|
98
|
+
|
|
99
|
+
<hr />
|
|
100
|
+
|
|
101
|
+
account.**verifyMessage**(typedData, signature) => _Promise < boolean >_
|
|
102
|
+
|
|
103
|
+
Verify a signature of a JSON object
|
|
104
|
+
|
|
105
|
+
<hr />
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 7
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# CHANGELOG
|
|
6
|
+
|
|
7
|
+
### Release 3.10.2 (21.04.2022)
|
|
8
|
+
|
|
9
|
+
- New hash formula for the new account contract version.
|
|
10
|
+
|
|
11
|
+
**NOTE**: Update your accounts, old ones will not be supported anymore. For updating with Argent X extension you can check this [link](https://github.com/argentlabs/argent-x/pull/522)
|
|
12
|
+
|
|
13
|
+
- BUGFIX: [#165](https://github.com/0xs34n/starknet.js/issues/165)
|
|
14
|
+
- BUGFIX: [#151](https://github.com/0xs34n/starknet.js/issues/151)
|
|
15
|
+
- BUGFIX: [#158](https://github.com/0xs34n/starknet.js/issues/158)
|
package/www/docs/API/contract.md
CHANGED
|
@@ -8,7 +8,78 @@ Contracts can do data transformations in JavaScript based on an ABI. They can al
|
|
|
8
8
|
|
|
9
9
|
Contracts allow you to transform Cairo values, like `Uint256` to `BigNumber`. It could also allow users to pass their own transformers, similar to `JSON.parse`.
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Creating an instance
|
|
12
12
|
|
|
13
|
-
Contract
|
|
13
|
+
`new starknet.Contract(abi, address, providerOrAccount)`
|
|
14
14
|
|
|
15
|
+
`contract.attach(providerOrAccount)` _for changing the provider or account_
|
|
16
|
+
|
|
17
|
+
`contract.connect(address)` _for changing the address of the connected contract_
|
|
18
|
+
|
|
19
|
+
## Contract properties
|
|
20
|
+
|
|
21
|
+
contract.**address** => _string_
|
|
22
|
+
|
|
23
|
+
The address the contract was constructed/connected with
|
|
24
|
+
|
|
25
|
+
contract.**providerOrAcount** => _Provider | Account_
|
|
26
|
+
|
|
27
|
+
Provider or Account that are used to interact with the network
|
|
28
|
+
|
|
29
|
+
contract.**deployTransactionHash** => _string | null_
|
|
30
|
+
|
|
31
|
+
If the Contract object is the result of a ContractFactory deployment, this is the transaction which was used to deploy the contract.
|
|
32
|
+
|
|
33
|
+
contract.**abi** => _Abi_
|
|
34
|
+
|
|
35
|
+
The ABI the contract was constructed with
|
|
36
|
+
|
|
37
|
+
## Contract methods
|
|
38
|
+
|
|
39
|
+
contract.**deployed**() => _Promise < Contract >_
|
|
40
|
+
|
|
41
|
+
If the Contract object is the result of a ContractFactory deployment, this method will wait for the transaction to be resolved.
|
|
42
|
+
|
|
43
|
+
## Meta-Class
|
|
44
|
+
|
|
45
|
+
A Meta-Class is a Class which has any of its properties determined at run-time. The Contract object uses a Contract's ABI to determine what methods are available, so the following sections describe the generic ways to interact with the properties added at run-time during the Contract constructor.
|
|
46
|
+
|
|
47
|
+
### Read-Only Methods(constant)
|
|
48
|
+
|
|
49
|
+
A constant method (denoted view in Cairo) is read-only and evaluates a small amount of EVM code against the current blockchain state. It is therefore free and does not require any fee, but cannot make changes to the blockchain state...
|
|
50
|
+
|
|
51
|
+
contract.**METHOD_NAME**(...args [ , overrides ]) => _Promise < Result >_
|
|
52
|
+
|
|
53
|
+
The type of the result depends on the ABI. Result object will be returned with each parameter available positionally and if the parameter is named, it will also be available by its name.
|
|
54
|
+
|
|
55
|
+
The _overrides_ object for a read-only method may include any of:
|
|
56
|
+
|
|
57
|
+
- overrides.**blockIdentifier**
|
|
58
|
+
|
|
59
|
+
### Write Methods (non-constant)
|
|
60
|
+
|
|
61
|
+
A non-constant method requires a transaction to be signed and requires payment in the form of a fee to be paid.
|
|
62
|
+
|
|
63
|
+
contract.**METHOD_NAME**(...args [ , overrides ]) => _Promise < AddTransactionResponse >_
|
|
64
|
+
|
|
65
|
+
Returns a AddTransactionResponse for the transaction after it is sent to the network. This requires the Contract has a signer.
|
|
66
|
+
|
|
67
|
+
The _overrides_ object for write methods may include any of:
|
|
68
|
+
|
|
69
|
+
- overrides.**signature** - Signature that will be used for the transaction
|
|
70
|
+
- overrides.**maxFee** - Max Fee for the transaction
|
|
71
|
+
- overrides.**nonce** - Nonce for the transaction
|
|
72
|
+
|
|
73
|
+
### Write Methods Analysis
|
|
74
|
+
|
|
75
|
+
There are several options to analyze properties and results of a write method without actually executing it.
|
|
76
|
+
|
|
77
|
+
contract.estimateGas.**METHOD_NAME**( ...args ) => _Promise < EstimateFeeResponse >_
|
|
78
|
+
|
|
79
|
+
Returns the estimate units of gas that would be required to execute the METHOD_NAME with args and overrides.
|
|
80
|
+
|
|
81
|
+
contract.populateTransaction.**METHOD_NAME**( ...args [ , overrides ] ) ⇒ _Invocation_
|
|
82
|
+
|
|
83
|
+
Returns an _Invocation_ object which represents the transaction that would need to be signed and submitted to the network to execute METHOD_NAME with args and overrides.
|
|
84
|
+
|
|
85
|
+
The overrides are identical to the overrides above for write methods.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 5
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Contract Factory
|
|
6
|
+
|
|
7
|
+
Contract Factory allow you to deploy contracts onto StarkNet. To deploy a Contract, additional information is needed that is not available on a Contract object itself.
|
|
8
|
+
|
|
9
|
+
## Creating an instance
|
|
10
|
+
|
|
11
|
+
`new starknet.ContractFactory( compiledContract , providerOrAccount, [ , abi ] )`
|
|
12
|
+
|
|
13
|
+
Creates a new instance of a ContractFactory for the contract described by the _compiledContract_.
|
|
14
|
+
|
|
15
|
+
`contractFactory.connect(providerOrAccount)` _for changing the provider or account_
|
|
16
|
+
|
|
17
|
+
`contractFactory.attach(address)` _for changing the address of the connected contract factory_
|
|
18
|
+
|
|
19
|
+
## Properties
|
|
20
|
+
|
|
21
|
+
contractFactory.**abi** => _Abi_;
|
|
22
|
+
|
|
23
|
+
The ABI the contractFactory was constructed with
|
|
24
|
+
|
|
25
|
+
contractFactory.**compiledContract** => _CompiledContract_;
|
|
26
|
+
|
|
27
|
+
The compiled contract the contractFactory was constructed with
|
|
28
|
+
|
|
29
|
+
contractFactory.**providerOrAccount** => _Provider | Account_;
|
|
30
|
+
|
|
31
|
+
Provider or Account that are used to interact with the network
|
|
32
|
+
|
|
33
|
+
## Methods
|
|
34
|
+
|
|
35
|
+
contractFactory.**attach**( address ) ⇒ _Contract_
|
|
36
|
+
|
|
37
|
+
Return an instance of a Contract attached to address. This is the same as using the Contract constructor with address and this _compiledContract_ and _providerOrAccount_ passed in when creating the ContractFactory.
|
|
38
|
+
|
|
39
|
+
contractFactory.deploy( constructorCalldata, addressSalt ) ⇒ Promise< Contract >
|
|
40
|
+
Uses the provider to deploy the Contract with constructorCalldata passed into the constructor and returns a Contract which is attached to the address where this contract will be deployed.
|
|
41
|
+
|
|
42
|
+
The transaction hash can be found at contract.deployTransactionHash, and no interactions should be made until the transaction is resolved.
|
package/www/docs/API/index.md
CHANGED