@stacks/network 2.0.1-beta.2 → 3.0.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 +8 -0
- package/README.md +18 -16
- package/dist/esm/index.d.ts +6 -9
- package/dist/esm/index.js +3 -15
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +6 -9
- package/dist/index.js +4 -17
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +9 -18
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.0.1](https://github.com/blockstack/blockstack.js/compare/v2.0.1-beta.2...v2.0.1) (2021-08-09)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @stacks/network
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [2.0.1-beta.2](https://github.com/blockstack/blockstack.js/compare/v2.0.1-beta.1...v2.0.1-beta.2) (2021-08-06)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @stacks/network
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ npm install @stacks/network
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
Creating a Stacks mainnet, testnet
|
|
13
|
+
Creating a Stacks mainnet, testnet or mocknet network
|
|
14
14
|
|
|
15
15
|
```typescript
|
|
16
16
|
import { StacksMainnet, StacksTestnet, StacksMocknet } from '@stacks/network';
|
|
@@ -19,15 +19,13 @@ const network = new StacksMainnet();
|
|
|
19
19
|
|
|
20
20
|
const testnet = new StacksTestnet();
|
|
21
21
|
|
|
22
|
-
const regtest = new StacksRegtest();
|
|
23
|
-
|
|
24
22
|
const mocknet = new StacksMocknet();
|
|
25
23
|
```
|
|
26
24
|
|
|
27
25
|
Setting a custom node URL
|
|
28
26
|
|
|
29
27
|
```typescript
|
|
30
|
-
network
|
|
28
|
+
const network = new StacksMainnet({ url: 'https://www.mystacksnode.com/' });
|
|
31
29
|
```
|
|
32
30
|
|
|
33
31
|
Check if network is mainnet
|
|
@@ -54,22 +52,26 @@ const transaction = await makeSTXTokenTransfer(txOptions);
|
|
|
54
52
|
Get various API URLs
|
|
55
53
|
|
|
56
54
|
```typescript
|
|
57
|
-
|
|
55
|
+
const txBroadcastUrl = network.getBroadcastApiUrl();
|
|
58
56
|
|
|
59
|
-
|
|
57
|
+
const feeEstimateUrl = network.getTransferFeeEstimateApiUrl();
|
|
60
58
|
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
const address = 'SP2BS6HD7TN34V8Z5BNF8Q2AW3K8K2DPV4264CF26';
|
|
60
|
+
const accountInfoUrl = network.getAccountApiUrl(address);
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
const contractName = 'hello_world';
|
|
63
|
+
const abiUrl = network.getAbiApiUrl(address, contractName);
|
|
66
64
|
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
const functionName = 'hello';
|
|
66
|
+
const readOnlyFunctionCallUrl = network.getReadOnlyFunctionCallApiUrl(
|
|
67
|
+
address,
|
|
68
|
+
contractName,
|
|
69
|
+
functionName
|
|
70
|
+
);
|
|
69
71
|
|
|
70
|
-
|
|
72
|
+
const nodeInfoUrl = network.getInfoUrl();
|
|
71
73
|
|
|
72
|
-
|
|
74
|
+
const blockTimeUrl = network.getBlockTimeInfoUrl();
|
|
73
75
|
|
|
74
|
-
|
|
75
|
-
```
|
|
76
|
+
const poxInfoUrl = network.getPoxInfoUrl();
|
|
77
|
+
```
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { TransactionVersion, ChainID } from '@stacks/common';
|
|
2
2
|
export declare const HIRO_MAINNET_DEFAULT = "https://stacks-node-api.mainnet.stacks.co";
|
|
3
|
-
export declare const HIRO_REGTEST_DEFAULT = "https://stacks-node-api.regtest.stacks.co";
|
|
4
3
|
export declare const HIRO_TESTNET_DEFAULT = "https://stacks-node-api.testnet.stacks.co";
|
|
5
4
|
export declare const HIRO_MOCKNET_DEFAULT = "http://localhost:3999";
|
|
6
5
|
export interface NetworkConfig {
|
|
@@ -10,14 +9,17 @@ export interface StacksNetwork {
|
|
|
10
9
|
version: TransactionVersion;
|
|
11
10
|
chainId: ChainID;
|
|
12
11
|
bnsLookupUrl: string;
|
|
12
|
+
readonly coreApiUrl: string;
|
|
13
13
|
broadcastEndpoint: string;
|
|
14
14
|
transferFeeEstimateEndpoint: string;
|
|
15
|
+
transactionFeeEstimateEndpoint: string;
|
|
15
16
|
accountEndpoint: string;
|
|
16
17
|
contractAbiEndpoint: string;
|
|
17
18
|
readOnlyFunctionCallEndpoint: string;
|
|
18
19
|
isMainnet(): boolean;
|
|
19
20
|
getBroadcastApiUrl: () => string;
|
|
20
21
|
getTransferFeeEstimateApiUrl: () => string;
|
|
22
|
+
getTransactionFeeEstimateApiUrl: () => string;
|
|
21
23
|
getAccountApiUrl: (address: string) => string;
|
|
22
24
|
getAbiApiUrl: (address: string, contract: string) => string;
|
|
23
25
|
getReadOnlyFunctionCallApiUrl: (contractAddress: string, contractName: string, functionName: string) => string;
|
|
@@ -36,16 +38,16 @@ export declare class StacksMainnet implements StacksNetwork {
|
|
|
36
38
|
bnsLookupUrl: string;
|
|
37
39
|
broadcastEndpoint: string;
|
|
38
40
|
transferFeeEstimateEndpoint: string;
|
|
41
|
+
transactionFeeEstimateEndpoint: string;
|
|
39
42
|
accountEndpoint: string;
|
|
40
43
|
contractAbiEndpoint: string;
|
|
41
44
|
readOnlyFunctionCallEndpoint: string;
|
|
42
|
-
|
|
43
|
-
get coreApiUrl(): string;
|
|
44
|
-
set coreApiUrl(_url: string);
|
|
45
|
+
readonly coreApiUrl: string;
|
|
45
46
|
constructor(networkUrl?: NetworkConfig);
|
|
46
47
|
isMainnet: () => boolean;
|
|
47
48
|
getBroadcastApiUrl: () => string;
|
|
48
49
|
getTransferFeeEstimateApiUrl: () => string;
|
|
50
|
+
getTransactionFeeEstimateApiUrl: () => string;
|
|
49
51
|
getAccountApiUrl: (address: string) => string;
|
|
50
52
|
getAbiApiUrl: (address: string, contract: string) => string;
|
|
51
53
|
getReadOnlyFunctionCallApiUrl: (contractAddress: string, contractName: string, functionName: string) => string;
|
|
@@ -68,8 +70,3 @@ export declare class StacksMocknet extends StacksMainnet implements StacksNetwor
|
|
|
68
70
|
chainId: ChainID;
|
|
69
71
|
constructor(networkUrl?: NetworkConfig);
|
|
70
72
|
}
|
|
71
|
-
export declare class StacksRegtest extends StacksMainnet implements StacksNetwork {
|
|
72
|
-
version: TransactionVersion;
|
|
73
|
-
chainId: ChainID;
|
|
74
|
-
constructor(networkUrl?: NetworkConfig);
|
|
75
|
-
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { TransactionVersion, ChainID, fetchPrivate } from '@stacks/common';
|
|
2
2
|
export const HIRO_MAINNET_DEFAULT = 'https://stacks-node-api.mainnet.stacks.co';
|
|
3
|
-
export const HIRO_REGTEST_DEFAULT = 'https://stacks-node-api.regtest.stacks.co';
|
|
4
3
|
export const HIRO_TESTNET_DEFAULT = 'https://stacks-node-api.testnet.stacks.co';
|
|
5
4
|
export const HIRO_MOCKNET_DEFAULT = 'http://localhost:3999';
|
|
6
5
|
export class StacksMainnet {
|
|
@@ -10,12 +9,14 @@ export class StacksMainnet {
|
|
|
10
9
|
this.bnsLookupUrl = 'https://stacks-node-api.mainnet.stacks.co';
|
|
11
10
|
this.broadcastEndpoint = '/v2/transactions';
|
|
12
11
|
this.transferFeeEstimateEndpoint = '/v2/fees/transfer';
|
|
12
|
+
this.transactionFeeEstimateEndpoint = '/v2/fees/transaction';
|
|
13
13
|
this.accountEndpoint = '/v2/accounts';
|
|
14
14
|
this.contractAbiEndpoint = '/v2/contracts/interface';
|
|
15
15
|
this.readOnlyFunctionCallEndpoint = '/v2/contracts/call-read';
|
|
16
16
|
this.isMainnet = () => this.version === TransactionVersion.Mainnet;
|
|
17
17
|
this.getBroadcastApiUrl = () => `${this.coreApiUrl}${this.broadcastEndpoint}`;
|
|
18
18
|
this.getTransferFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`;
|
|
19
|
+
this.getTransactionFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transactionFeeEstimateEndpoint}`;
|
|
19
20
|
this.getAccountApiUrl = (address) => `${this.coreApiUrl}${this.accountEndpoint}/${address}?proof=0`;
|
|
20
21
|
this.getAbiApiUrl = (address, contract) => `${this.coreApiUrl}${this.contractAbiEndpoint}/${address}/${contract}`;
|
|
21
22
|
this.getReadOnlyFunctionCallApiUrl = (contractAddress, contractName, functionName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}/${contractAddress}/${contractName}/${encodeURIComponent(functionName)}`;
|
|
@@ -39,13 +40,7 @@ export class StacksMainnet {
|
|
|
39
40
|
};
|
|
40
41
|
this.getStackerInfoUrl = (contractAddress, contractName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}
|
|
41
42
|
${contractAddress}/${contractName}/get-stacker-info`;
|
|
42
|
-
this.
|
|
43
|
-
}
|
|
44
|
-
get coreApiUrl() {
|
|
45
|
-
return this._coreApiUrl;
|
|
46
|
-
}
|
|
47
|
-
set coreApiUrl(_url) {
|
|
48
|
-
throw new Error('Cannot modify property `coreApiUrl` after object initialization');
|
|
43
|
+
this.coreApiUrl = networkUrl.url;
|
|
49
44
|
}
|
|
50
45
|
getNameInfo(fullyQualifiedName) {
|
|
51
46
|
const nameLookupURL = `${this.bnsLookupUrl}/v1/names/${fullyQualifiedName}`;
|
|
@@ -85,11 +80,4 @@ export class StacksMocknet extends StacksMainnet {
|
|
|
85
80
|
this.chainId = ChainID.Testnet;
|
|
86
81
|
}
|
|
87
82
|
}
|
|
88
|
-
export class StacksRegtest extends StacksMainnet {
|
|
89
|
-
constructor(networkUrl = { url: HIRO_REGTEST_DEFAULT }) {
|
|
90
|
-
super(networkUrl);
|
|
91
|
-
this.version = TransactionVersion.Testnet;
|
|
92
|
-
this.chainId = ChainID.Testnet;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
83
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE3E,MAAM,CAAC,MAAM,oBAAoB,GAAG,2CAA2C,CAAC;AAChF,MAAM,CAAC,MAAM,oBAAoB,GAAG,2CAA2C,CAAC;AAChF,MAAM,CAAC,MAAM,oBAAoB,GAAG,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE3E,MAAM,CAAC,MAAM,oBAAoB,GAAG,2CAA2C,CAAC;AAChF,MAAM,CAAC,MAAM,oBAAoB,GAAG,2CAA2C,CAAC;AAChF,MAAM,CAAC,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AA+C5D,MAAM,OAAO,aAAa;IAaxB,YAAY,aAA4B,EAAE,GAAG,EAAE,oBAAoB,EAAE;QAZrE,YAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC;QACrC,YAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC1B,iBAAY,GAAG,2CAA2C,CAAC;QAC3D,sBAAiB,GAAG,kBAAkB,CAAC;QACvC,gCAA2B,GAAG,mBAAmB,CAAC;QAClD,mCAA8B,GAAG,sBAAsB,CAAC;QACxD,oBAAe,GAAG,cAAc,CAAC;QACjC,wBAAmB,GAAG,yB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,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;aACpB;QACH,CAAC,CAAC;aACD,IAAI,CAAC,QAAQ,CAAC,EAAE;YAIf,IAAI,QAAQ,CAAC,OAAO,EAAE;gBACpB,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;aACnE;iBAAM;gBACL,OAAO,QAAQ,CAAC;aACjB;QACH,CAAC,CAAC,CAAC;IACP,CAAC;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,aAAa;IAI9C,YAAY,aAA4B,EAAE,GAAG,EAAE,oBAAoB,EAAE;QACnE,KAAK,CAAC,UAAU,CAAC,CAAC;QAJpB,YAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC;QACrC,YAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAI1B,CAAC;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,aAAa;IAI9C,YAAY,aAA4B,EAAE,GAAG,EAAE,oBAAoB,EAAE;QACnE,KAAK,CAAC,UAAU,CAAC,CAAC;QAJpB,YAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC;QACrC,YAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAI1B,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { TransactionVersion, ChainID } from '@stacks/common';
|
|
2
2
|
export declare const HIRO_MAINNET_DEFAULT = "https://stacks-node-api.mainnet.stacks.co";
|
|
3
|
-
export declare const HIRO_REGTEST_DEFAULT = "https://stacks-node-api.regtest.stacks.co";
|
|
4
3
|
export declare const HIRO_TESTNET_DEFAULT = "https://stacks-node-api.testnet.stacks.co";
|
|
5
4
|
export declare const HIRO_MOCKNET_DEFAULT = "http://localhost:3999";
|
|
6
5
|
export interface NetworkConfig {
|
|
@@ -10,14 +9,17 @@ export interface StacksNetwork {
|
|
|
10
9
|
version: TransactionVersion;
|
|
11
10
|
chainId: ChainID;
|
|
12
11
|
bnsLookupUrl: string;
|
|
12
|
+
readonly coreApiUrl: string;
|
|
13
13
|
broadcastEndpoint: string;
|
|
14
14
|
transferFeeEstimateEndpoint: string;
|
|
15
|
+
transactionFeeEstimateEndpoint: string;
|
|
15
16
|
accountEndpoint: string;
|
|
16
17
|
contractAbiEndpoint: string;
|
|
17
18
|
readOnlyFunctionCallEndpoint: string;
|
|
18
19
|
isMainnet(): boolean;
|
|
19
20
|
getBroadcastApiUrl: () => string;
|
|
20
21
|
getTransferFeeEstimateApiUrl: () => string;
|
|
22
|
+
getTransactionFeeEstimateApiUrl: () => string;
|
|
21
23
|
getAccountApiUrl: (address: string) => string;
|
|
22
24
|
getAbiApiUrl: (address: string, contract: string) => string;
|
|
23
25
|
getReadOnlyFunctionCallApiUrl: (contractAddress: string, contractName: string, functionName: string) => string;
|
|
@@ -36,16 +38,16 @@ export declare class StacksMainnet implements StacksNetwork {
|
|
|
36
38
|
bnsLookupUrl: string;
|
|
37
39
|
broadcastEndpoint: string;
|
|
38
40
|
transferFeeEstimateEndpoint: string;
|
|
41
|
+
transactionFeeEstimateEndpoint: string;
|
|
39
42
|
accountEndpoint: string;
|
|
40
43
|
contractAbiEndpoint: string;
|
|
41
44
|
readOnlyFunctionCallEndpoint: string;
|
|
42
|
-
|
|
43
|
-
get coreApiUrl(): string;
|
|
44
|
-
set coreApiUrl(_url: string);
|
|
45
|
+
readonly coreApiUrl: string;
|
|
45
46
|
constructor(networkUrl?: NetworkConfig);
|
|
46
47
|
isMainnet: () => boolean;
|
|
47
48
|
getBroadcastApiUrl: () => string;
|
|
48
49
|
getTransferFeeEstimateApiUrl: () => string;
|
|
50
|
+
getTransactionFeeEstimateApiUrl: () => string;
|
|
49
51
|
getAccountApiUrl: (address: string) => string;
|
|
50
52
|
getAbiApiUrl: (address: string, contract: string) => string;
|
|
51
53
|
getReadOnlyFunctionCallApiUrl: (contractAddress: string, contractName: string, functionName: string) => string;
|
|
@@ -68,8 +70,3 @@ export declare class StacksMocknet extends StacksMainnet implements StacksNetwor
|
|
|
68
70
|
chainId: ChainID;
|
|
69
71
|
constructor(networkUrl?: NetworkConfig);
|
|
70
72
|
}
|
|
71
|
-
export declare class StacksRegtest extends StacksMainnet implements StacksNetwork {
|
|
72
|
-
version: TransactionVersion;
|
|
73
|
-
chainId: ChainID;
|
|
74
|
-
constructor(networkUrl?: NetworkConfig);
|
|
75
|
-
}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.StacksMocknet = exports.StacksTestnet = exports.StacksMainnet = exports.HIRO_MOCKNET_DEFAULT = exports.HIRO_TESTNET_DEFAULT = exports.HIRO_MAINNET_DEFAULT = void 0;
|
|
4
4
|
const common_1 = require("@stacks/common");
|
|
5
5
|
exports.HIRO_MAINNET_DEFAULT = 'https://stacks-node-api.mainnet.stacks.co';
|
|
6
|
-
exports.HIRO_REGTEST_DEFAULT = 'https://stacks-node-api.regtest.stacks.co';
|
|
7
6
|
exports.HIRO_TESTNET_DEFAULT = 'https://stacks-node-api.testnet.stacks.co';
|
|
8
7
|
exports.HIRO_MOCKNET_DEFAULT = 'http://localhost:3999';
|
|
9
8
|
class StacksMainnet {
|
|
@@ -13,12 +12,14 @@ class StacksMainnet {
|
|
|
13
12
|
this.bnsLookupUrl = 'https://stacks-node-api.mainnet.stacks.co';
|
|
14
13
|
this.broadcastEndpoint = '/v2/transactions';
|
|
15
14
|
this.transferFeeEstimateEndpoint = '/v2/fees/transfer';
|
|
15
|
+
this.transactionFeeEstimateEndpoint = '/v2/fees/transaction';
|
|
16
16
|
this.accountEndpoint = '/v2/accounts';
|
|
17
17
|
this.contractAbiEndpoint = '/v2/contracts/interface';
|
|
18
18
|
this.readOnlyFunctionCallEndpoint = '/v2/contracts/call-read';
|
|
19
19
|
this.isMainnet = () => this.version === common_1.TransactionVersion.Mainnet;
|
|
20
20
|
this.getBroadcastApiUrl = () => `${this.coreApiUrl}${this.broadcastEndpoint}`;
|
|
21
21
|
this.getTransferFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`;
|
|
22
|
+
this.getTransactionFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transactionFeeEstimateEndpoint}`;
|
|
22
23
|
this.getAccountApiUrl = (address) => `${this.coreApiUrl}${this.accountEndpoint}/${address}?proof=0`;
|
|
23
24
|
this.getAbiApiUrl = (address, contract) => `${this.coreApiUrl}${this.contractAbiEndpoint}/${address}/${contract}`;
|
|
24
25
|
this.getReadOnlyFunctionCallApiUrl = (contractAddress, contractName, functionName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}/${contractAddress}/${contractName}/${encodeURIComponent(functionName)}`;
|
|
@@ -42,13 +43,7 @@ class StacksMainnet {
|
|
|
42
43
|
};
|
|
43
44
|
this.getStackerInfoUrl = (contractAddress, contractName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}
|
|
44
45
|
${contractAddress}/${contractName}/get-stacker-info`;
|
|
45
|
-
this.
|
|
46
|
-
}
|
|
47
|
-
get coreApiUrl() {
|
|
48
|
-
return this._coreApiUrl;
|
|
49
|
-
}
|
|
50
|
-
set coreApiUrl(_url) {
|
|
51
|
-
throw new Error('Cannot modify property `coreApiUrl` after object initialization');
|
|
46
|
+
this.coreApiUrl = networkUrl.url;
|
|
52
47
|
}
|
|
53
48
|
getNameInfo(fullyQualifiedName) {
|
|
54
49
|
const nameLookupURL = `${this.bnsLookupUrl}/v1/names/${fullyQualifiedName}`;
|
|
@@ -91,12 +86,4 @@ class StacksMocknet extends StacksMainnet {
|
|
|
91
86
|
}
|
|
92
87
|
}
|
|
93
88
|
exports.StacksMocknet = StacksMocknet;
|
|
94
|
-
class StacksRegtest extends StacksMainnet {
|
|
95
|
-
constructor(networkUrl = { url: exports.HIRO_REGTEST_DEFAULT }) {
|
|
96
|
-
super(networkUrl);
|
|
97
|
-
this.version = common_1.TransactionVersion.Testnet;
|
|
98
|
-
this.chainId = common_1.ChainID.Testnet;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
exports.StacksRegtest = StacksRegtest;
|
|
102
89
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2CAA2E;AAE9D,QAAA,oBAAoB,GAAG,2CAA2C,CAAC;AACnE,QAAA,oBAAoB,GAAG,2CAA2C,CAAC;AACnE,QAAA,oBAAoB,GAAG,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2CAA2E;AAE9D,QAAA,oBAAoB,GAAG,2CAA2C,CAAC;AACnE,QAAA,oBAAoB,GAAG,2CAA2C,CAAC;AACnE,QAAA,oBAAoB,GAAG,uBAAuB,CAAC;AA+C5D,MAAa,aAAa;IAaxB,YAAY,aAA4B,EAAE,GAAG,EAAE,4BAAoB,EAAE;QAZrE,YAAO,GAAG,2BAAkB,CAAC,OAAO,CAAC;QACrC,YAAO,GAAG,gBAAO,CAAC,OAAO,CAAC;QAC1B,iBAAY,GAAG,2CAA2C,CAAC;QAC3D,sBAAiB,GAAG,kBAAkB,CAAC;QACvC,gCAA2B,GAAG,mBAAmB,CAAC;QAClD,mCAA8B,GAAG,sBAAsB,CAAC;QACxD,oBAAe,GAAG,cAAc,CAAC;QACjC,wBAAmB,GAAG,yBAAyB,CAAC;QAChD,iCAA4B,GAAG,yBAAyB,CAAC;QAQzD,cAAS,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,KAAK,2BAAkB,CAAC,OAAO,CAAC;QAC9D,uBAAkB,GAAG,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,iBAAiB,EAAE,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AO,EAAE,CAAC,CAAC;aACnE;iBAAM;gBACL,OAAO,QAAQ,CAAC;aACjB;QACH,CAAC,CAAC,CAAC;IACP,CAAC;CACF;AAlFD,sCAkFC;AAED,MAAa,aAAc,SAAQ,aAAa;IAI9C,YAAY,aAA4B,EAAE,GAAG,EAAE,4BAAoB,EAAE;QACnE,KAAK,CAAC,UAAU,CAAC,CAAC;QAJpB,YAAO,GAAG,2BAAkB,CAAC,OAAO,CAAC;QACrC,YAAO,GAAG,gBAAO,CAAC,OAAO,CAAC;IAI1B,CAAC;CACF;AAPD,sCAOC;AAED,MAAa,aAAc,SAAQ,aAAa;IAI9C,YAAY,aAA4B,EAAE,GAAG,EAAE,4BAAoB,EAAE;QACnE,KAAK,CAAC,UAAU,CAAC,CAAC;QAJpB,YAAO,GAAG,2BAAkB,CAAC,OAAO,CAAC;QACrC,YAAO,GAAG,gBAAO,CAAC,OAAO,CAAC;IAI1B,CAAC;CACF;AAPD,sCAOC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacks/network",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Library for Stacks network operations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"stacks",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"url": "https://github.com/blockstack/blockstack.js/issues"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@stacks/common": "^
|
|
41
|
+
"@stacks/common": "^3.0.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/jest": "^26.0.22",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"typings": "dist/index.d.ts",
|
|
59
59
|
"umd:main": "dist/index.umd.js",
|
|
60
60
|
"unpkg": "dist/index.umd.js",
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "728b58358f2876d282f511ba1fc6c4fa9a1ac2f3"
|
|
62
62
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { TransactionVersion, ChainID, fetchPrivate } from '@stacks/common';
|
|
2
2
|
|
|
3
3
|
export const HIRO_MAINNET_DEFAULT = 'https://stacks-node-api.mainnet.stacks.co';
|
|
4
|
-
export const HIRO_REGTEST_DEFAULT = 'https://stacks-node-api.regtest.stacks.co';
|
|
5
4
|
export const HIRO_TESTNET_DEFAULT = 'https://stacks-node-api.testnet.stacks.co';
|
|
6
5
|
export const HIRO_MOCKNET_DEFAULT = 'http://localhost:3999';
|
|
7
6
|
|
|
@@ -13,14 +12,17 @@ export interface StacksNetwork {
|
|
|
13
12
|
version: TransactionVersion;
|
|
14
13
|
chainId: ChainID;
|
|
15
14
|
bnsLookupUrl: string;
|
|
15
|
+
readonly coreApiUrl: string;
|
|
16
16
|
broadcastEndpoint: string;
|
|
17
17
|
transferFeeEstimateEndpoint: string;
|
|
18
|
+
transactionFeeEstimateEndpoint: string;
|
|
18
19
|
accountEndpoint: string;
|
|
19
20
|
contractAbiEndpoint: string;
|
|
20
21
|
readOnlyFunctionCallEndpoint: string;
|
|
21
22
|
isMainnet(): boolean;
|
|
22
23
|
getBroadcastApiUrl: () => string;
|
|
23
24
|
getTransferFeeEstimateApiUrl: () => string;
|
|
25
|
+
getTransactionFeeEstimateApiUrl: () => string;
|
|
24
26
|
getAccountApiUrl: (address: string) => string;
|
|
25
27
|
getAbiApiUrl: (address: string, contract: string) => string;
|
|
26
28
|
getReadOnlyFunctionCallApiUrl: (
|
|
@@ -53,24 +55,22 @@ export class StacksMainnet implements StacksNetwork {
|
|
|
53
55
|
bnsLookupUrl = 'https://stacks-node-api.mainnet.stacks.co';
|
|
54
56
|
broadcastEndpoint = '/v2/transactions';
|
|
55
57
|
transferFeeEstimateEndpoint = '/v2/fees/transfer';
|
|
58
|
+
transactionFeeEstimateEndpoint = '/v2/fees/transaction';
|
|
56
59
|
accountEndpoint = '/v2/accounts';
|
|
57
60
|
contractAbiEndpoint = '/v2/contracts/interface';
|
|
58
61
|
readOnlyFunctionCallEndpoint = '/v2/contracts/call-read';
|
|
59
|
-
private _coreApiUrl: string;
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
return this._coreApiUrl;
|
|
63
|
-
}
|
|
64
|
-
set coreApiUrl(_url: string) {
|
|
65
|
-
throw new Error('Cannot modify property `coreApiUrl` after object initialization');
|
|
66
|
-
}
|
|
63
|
+
readonly coreApiUrl: string;
|
|
67
64
|
|
|
68
65
|
constructor(networkUrl: NetworkConfig = { url: HIRO_MAINNET_DEFAULT }) {
|
|
69
|
-
this.
|
|
66
|
+
this.coreApiUrl = networkUrl.url;
|
|
70
67
|
}
|
|
68
|
+
|
|
71
69
|
isMainnet = () => this.version === TransactionVersion.Mainnet;
|
|
72
70
|
getBroadcastApiUrl = () => `${this.coreApiUrl}${this.broadcastEndpoint}`;
|
|
73
71
|
getTransferFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`;
|
|
72
|
+
getTransactionFeeEstimateApiUrl = () =>
|
|
73
|
+
`${this.coreApiUrl}${this.transactionFeeEstimateEndpoint}`;
|
|
74
74
|
getAccountApiUrl = (address: string) =>
|
|
75
75
|
`${this.coreApiUrl}${this.accountEndpoint}/${address}?proof=0`;
|
|
76
76
|
getAbiApiUrl = (address: string, contract: string) =>
|
|
@@ -150,12 +150,3 @@ export class StacksMocknet extends StacksMainnet implements StacksNetwork {
|
|
|
150
150
|
super(networkUrl);
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
|
|
154
|
-
export class StacksRegtest extends StacksMainnet implements StacksNetwork {
|
|
155
|
-
version = TransactionVersion.Testnet;
|
|
156
|
-
chainId = ChainID.Testnet;
|
|
157
|
-
|
|
158
|
-
constructor(networkUrl: NetworkConfig = { url: HIRO_REGTEST_DEFAULT }) {
|
|
159
|
-
super(networkUrl);
|
|
160
|
-
}
|
|
161
|
-
}
|