@alephium/web3 0.3.0-rc.5 → 0.3.0-rc.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.3.0-rc.5",
3
+ "version": "0.3.0-rc.7",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
@@ -27,8 +27,8 @@
27
27
  },
28
28
  "author": "Alephium dev <dev@alephium.org>",
29
29
  "config": {
30
- "alephium_version": "1.6.1",
31
- "explorer_backend_version": "1.11.2"
30
+ "alephium_version": "1.6.2",
31
+ "explorer_backend_version": "1.12.0-rc2"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "rm -rf dist/* && npx tsc --build . && webpack",
@@ -1332,7 +1332,7 @@ export class HttpClient<SecurityDataType = unknown> {
1332
1332
 
1333
1333
  /**
1334
1334
  * @title Alephium API
1335
- * @version 1.6.1
1335
+ * @version 1.6.2
1336
1336
  * @baseUrl ../
1337
1337
  */
1338
1338
  export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -96,6 +96,7 @@ export interface ConfirmedTransaction {
96
96
 
97
97
  /** @format uint256 */
98
98
  gasPrice: string
99
+ coinbase: boolean
99
100
  type: string
100
101
  }
101
102
 
@@ -116,6 +117,20 @@ export interface ContractOutput {
116
117
  type: string
117
118
  }
118
119
 
120
+ export interface Event {
121
+ /** @format block-hash */
122
+ blockHash: string
123
+
124
+ /** @format 32-byte-hash */
125
+ txHash: string
126
+ contractAddress: string
127
+ inputAddress?: string
128
+
129
+ /** @format int32 */
130
+ eventIndex: number
131
+ fields?: Val[]
132
+ }
133
+
119
134
  export interface ExplorerInfo {
120
135
  releaseVersion: string
121
136
  commit: string
@@ -147,6 +162,11 @@ export interface InternalServerError {
147
162
  detail: string
148
163
  }
149
164
 
165
+ export enum IntervalType {
166
+ Daily = 'daily',
167
+ Hourly = 'hourly'
168
+ }
169
+
150
170
  export interface ListBlocks {
151
171
  /** @format int32 */
152
172
  total: number
@@ -275,6 +295,7 @@ export interface Transaction {
275
295
 
276
296
  /** @format uint256 */
277
297
  gasPrice: string
298
+ coinbase: boolean
278
299
  }
279
300
 
280
301
  export type TransactionLike = ConfirmedTransaction | UnconfirmedTransaction
@@ -306,6 +327,42 @@ export interface UnconfirmedTransaction {
306
327
  type: string
307
328
  }
308
329
 
330
+ export type Val = ValAddress | ValArray | ValBool | ValByteVec | ValI256 | ValU256
331
+
332
+ export interface ValAddress {
333
+ /** @format address */
334
+ value: string
335
+ type: string
336
+ }
337
+
338
+ export interface ValArray {
339
+ value: Val[]
340
+ type: string
341
+ }
342
+
343
+ export interface ValBool {
344
+ value: boolean
345
+ type: string
346
+ }
347
+
348
+ export interface ValByteVec {
349
+ /** @format hex-string */
350
+ value: string
351
+ type: string
352
+ }
353
+
354
+ export interface ValI256 {
355
+ /** @format bigint */
356
+ value: string
357
+ type: string
358
+ }
359
+
360
+ export interface ValU256 {
361
+ /** @format uint256 */
362
+ value: string
363
+ type: string
364
+ }
365
+
309
366
  import 'cross-fetch/polyfill'
310
367
  import { convertHttpResponse } from './utils'
311
368
 
@@ -587,21 +644,6 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
587
644
  method: 'GET',
588
645
  format: 'json',
589
646
  ...params
590
- }).then(convertHttpResponse),
591
-
592
- /**
593
- * @description Get a transaction from a output reference key
594
- *
595
- * @tags Transactions
596
- * @name GetTransactionsByOutputRefKeyOutputRefKey
597
- * @request GET:/transactions/by/output-ref-key/{output_ref_key}
598
- */
599
- getTransactionsByOutputRefKeyOutputRefKey: (outputRefKey: string, params: RequestParams = {}) =>
600
- this.request<Transaction, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
601
- path: `/transactions/by/output-ref-key/${outputRefKey}`,
602
- method: 'GET',
603
- format: 'json',
604
- ...params
605
647
  }).then(convertHttpResponse)
606
648
  }
607
649
  addresses = {
@@ -778,6 +820,23 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
778
820
  ...params
779
821
  }).then(convertHttpResponse),
780
822
 
823
+ /**
824
+ * @description Are the addresses used (at least 1 transaction)
825
+ *
826
+ * @tags Addresses, Addresses
827
+ * @name PostAddressesUsed
828
+ * @request POST:/addresses/used
829
+ */
830
+ postAddressesUsed: (data?: string[], params: RequestParams = {}) =>
831
+ this.request<boolean[], BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
832
+ path: `/addresses/used`,
833
+ method: 'POST',
834
+ body: data,
835
+ type: ContentType.Json,
836
+ format: 'json',
837
+ ...params
838
+ }).then(convertHttpResponse),
839
+
781
840
  /**
782
841
  * No description
783
842
  *
@@ -797,24 +856,6 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
797
856
  ...params
798
857
  }).then(convertHttpResponse)
799
858
  }
800
- addressesActive = {
801
- /**
802
- * @description Are the addresses active (at least 1 transaction)
803
- *
804
- * @tags Addresses
805
- * @name PostAddressesActive
806
- * @request POST:/addresses-active
807
- */
808
- postAddressesActive: (data?: string[], params: RequestParams = {}) =>
809
- this.request<boolean[], BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
810
- path: `/addresses-active`,
811
- method: 'POST',
812
- body: data,
813
- type: ContentType.Json,
814
- format: 'json',
815
- ...params
816
- }).then(convertHttpResponse)
817
- }
818
859
  infos = {
819
860
  /**
820
861
  * @description Get explorer informations
@@ -1016,7 +1057,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
1016
1057
  * @request GET:/charts/hashrates
1017
1058
  */
1018
1059
  getChartsHashrates: (
1019
- query: { fromTs: number; toTs: number; 'interval-type': string },
1060
+ query: { fromTs: number; toTs: number; 'interval-type': IntervalType },
1020
1061
  params: RequestParams = {}
1021
1062
  ) =>
1022
1063
  this.request<Hashrate[], BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
@@ -1036,7 +1077,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
1036
1077
  * @request GET:/charts/transactions-count
1037
1078
  */
1038
1079
  getChartsTransactionsCount: (
1039
- query: { fromTs: number; toTs: number; 'interval-type': string },
1080
+ query: { fromTs: number; toTs: number; 'interval-type': IntervalType },
1040
1081
  params: RequestParams = {}
1041
1082
  ) =>
1042
1083
  this.request<TimedCount[], BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
@@ -1056,7 +1097,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
1056
1097
  * @request GET:/charts/transactions-count-per-chain
1057
1098
  */
1058
1099
  getChartsTransactionsCountPerChain: (
1059
- query: { fromTs: number; toTs: number; 'interval-type': string },
1100
+ query: { fromTs: number; toTs: number; 'interval-type': IntervalType },
1060
1101
  params: RequestParams = {}
1061
1102
  ) =>
1062
1103
  this.request<
@@ -1070,6 +1111,63 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
1070
1111
  ...params
1071
1112
  }).then(convertHttpResponse)
1072
1113
  }
1114
+ contractEvents = {
1115
+ /**
1116
+ * @description Get contract events by transaction id
1117
+ *
1118
+ * @tags Contract events
1119
+ * @name GetContractEventsTransactionIdTransactionId
1120
+ * @request GET:/contract-events/transaction-id/{transaction_id}
1121
+ */
1122
+ getContractEventsTransactionIdTransactionId: (transactionId: string, params: RequestParams = {}) =>
1123
+ this.request<Event[], BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
1124
+ path: `/contract-events/transaction-id/${transactionId}`,
1125
+ method: 'GET',
1126
+ format: 'json',
1127
+ ...params
1128
+ }).then(convertHttpResponse),
1129
+
1130
+ /**
1131
+ * @description Get contract events by contract address
1132
+ *
1133
+ * @tags Contract events
1134
+ * @name GetContractEventsContractAddressContractAddress
1135
+ * @request GET:/contract-events/contract-address/{contract_address}
1136
+ */
1137
+ getContractEventsContractAddressContractAddress: (
1138
+ contractAddress: string,
1139
+ query?: { page?: number; limit?: number; reverse?: boolean },
1140
+ params: RequestParams = {}
1141
+ ) =>
1142
+ this.request<Event[], BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
1143
+ path: `/contract-events/contract-address/${contractAddress}`,
1144
+ method: 'GET',
1145
+ query: query,
1146
+ format: 'json',
1147
+ ...params
1148
+ }).then(convertHttpResponse),
1149
+
1150
+ /**
1151
+ * @description Get contract events by contract and input addresses
1152
+ *
1153
+ * @tags Contract events
1154
+ * @name GetContractEventsContractAddressContractAddressInputAddressInputAddress
1155
+ * @request GET:/contract-events/contract-address/{contract_address}/input-address/{input_address}
1156
+ */
1157
+ getContractEventsContractAddressContractAddressInputAddressInputAddress: (
1158
+ contractAddress: string,
1159
+ inputAddress: string,
1160
+ query?: { page?: number; limit?: number; reverse?: boolean },
1161
+ params: RequestParams = {}
1162
+ ) =>
1163
+ this.request<Event[], BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
1164
+ path: `/contract-events/contract-address/${contractAddress}/input-address/${inputAddress}`,
1165
+ method: 'GET',
1166
+ query: query,
1167
+ format: 'json',
1168
+ ...params
1169
+ }).then(convertHttpResponse)
1170
+ }
1073
1171
  utils = {
1074
1172
  /**
1075
1173
  * @description Perform a sanity check
package/src/api/index.ts CHANGED
@@ -118,7 +118,6 @@ export class ExplorerProvider {
118
118
  readonly blocks = ExplorerApi['blocks']
119
119
  readonly transactions = ExplorerApi['transactions']
120
120
  readonly addresses = ExplorerApi['addresses']
121
- readonly addressesActive = ExplorerApi['addressesActive']
122
121
  readonly infos = ExplorerApi['infos']
123
122
  readonly unconfirmedTransactions = ExplorerApi['unconfirmedTransactions']
124
123
  readonly tokens = ExplorerApi['tokens']
@@ -142,7 +141,6 @@ export class ExplorerProvider {
142
141
  this.blocks = { ...explorerApi.blocks }
143
142
  this.transactions = { ...explorerApi.transactions }
144
143
  this.addresses = { ...explorerApi.addresses }
145
- this.addressesActive = { ...explorerApi.addressesActive }
146
144
  this.infos = { ...explorerApi.infos }
147
145
  this.unconfirmedTransactions = { ...explorerApi.unconfirmedTransactions }
148
146
  this.tokens = { ...explorerApi.tokens }
@@ -18,3 +18,4 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
 
19
19
  export * from './signer'
20
20
  export * from './types'
21
+ export * from './tx-builder'
@@ -17,15 +17,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
 
19
19
  import { ec as EC } from 'elliptic'
20
- import {
21
- ExplorerProvider,
22
- fromApiNumber256,
23
- fromApiTokens,
24
- NodeProvider,
25
- toApiNumber256,
26
- toApiNumber256Optional,
27
- toApiTokens
28
- } from '../api'
20
+ import { ExplorerProvider, fromApiNumber256, fromApiTokens, NodeProvider, toApiNumber256, toApiTokens } from '../api'
29
21
  import { node } from '../api'
30
22
  import * as utils from '../utils'
31
23
  import blake from 'blakejs'
@@ -46,8 +38,14 @@ import {
46
38
  SignUnsignedTxParams,
47
39
  SignUnsignedTxResult,
48
40
  SubmissionResult,
49
- SubmitTransactionParams
41
+ SubmitTransactionParams,
42
+ ExtSignTransferTxParams,
43
+ ExtSignDeployContractTxParams,
44
+ ExtSignExecuteScriptTxParams,
45
+ ExtSignUnsignedTxParams,
46
+ ExtSignMessageParams
50
47
  } from './types'
48
+ import { TransactionBuilder } from './tx-builder'
51
49
 
52
50
  const ec = new EC('secp256k1')
53
51
 
@@ -71,12 +69,19 @@ export interface SignerProvider {
71
69
  // Abstraction for interactive signer (e.g. WalletConnect instance, Extension wallet object)
72
70
  export interface InteractiveSignerProvider<EnableOptions extends EnableOptionsBase = EnableOptionsBase>
73
71
  extends SignerProvider {
74
- enable(opt?: EnableOptions): Promise<void>
72
+ enable(opt?: EnableOptions): Promise<Address>
75
73
  disconnect(): Promise<void>
74
+
75
+ // Methods inherited from SignerProvider, but require networkId in the params
76
+ signAndSubmitTransferTx(params: ExtSignTransferTxParams): Promise<SignTransferTxResult>
77
+ signAndSubmitDeployContractTx(params: ExtSignDeployContractTxParams): Promise<SignDeployContractTxResult>
78
+ signAndSubmitExecuteScriptTx(params: ExtSignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>
79
+ signAndSubmitUnsignedTx(params: ExtSignUnsignedTxParams): Promise<SignUnsignedTxResult>
80
+ signUnsignedTx(params: ExtSignUnsignedTxParams): Promise<SignUnsignedTxResult>
81
+ signMessage(params: ExtSignMessageParams): Promise<SignMessageResult>
76
82
  }
77
83
 
78
- export abstract class SignerProviderSimple implements SignerProvider {
79
- abstract get nodeProvider(): NodeProvider | undefined
84
+ export abstract class SignerProviderSimple extends TransactionBuilder implements SignerProvider {
80
85
  abstract get explorerProvider(): ExplorerProvider | undefined
81
86
 
82
87
  abstract getSelectedAccount(): Promise<Account>
@@ -86,16 +91,9 @@ export abstract class SignerProviderSimple implements SignerProvider {
86
91
  return account.address
87
92
  }
88
93
 
89
- private getNodeProvider(): NodeProvider {
90
- if (this.nodeProvider === undefined) {
91
- throw Error('The signer does not contain a node provider')
92
- }
93
- return this.nodeProvider
94
- }
95
-
96
94
  async submitTransaction(params: SubmitTransactionParams): Promise<SubmissionResult> {
97
95
  const data: node.SubmitTransaction = { unsignedTx: params.unsignedTx, signature: params.signature }
98
- return this.getNodeProvider().transactions.postTransactionsSubmit(data)
96
+ return this.nodeProvider.transactions.postTransactionsSubmit(data)
99
97
  }
100
98
 
101
99
  async signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult> {
@@ -132,67 +130,43 @@ export abstract class SignerProviderSimple implements SignerProvider {
132
130
  async signTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult> {
133
131
  const response = await this.buildTransferTx(params)
134
132
  const signature = await this.signRaw(params.signerAddress, response.txId)
135
- return { ...response, signature, gasPrice: fromApiNumber256(response.gasPrice) }
133
+ return { signature, ...response }
136
134
  }
137
135
 
138
- async buildTransferTx(params: SignTransferTxParams): Promise<node.BuildTransactionResult> {
139
- const data: node.BuildTransaction = {
140
- ...(await this.usePublicKey(params)),
141
- destinations: toApiDestinations(params.destinations),
142
- gasPrice: toApiNumber256Optional(params.gasPrice)
143
- }
144
- return this.getNodeProvider().transactions.postTransactionsBuild(data)
136
+ override async buildTransferTx(params: SignTransferTxParams): Promise<Omit<SignTransferTxResult, 'signature'>> {
137
+ return super.buildTransferTx(params, await this.getPublicKey(params.signerAddress))
145
138
  }
146
139
 
147
140
  async signDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult> {
148
- const response = await this.buildContractCreationTx(params)
141
+ const response = await this.buildDeployContractTx(params)
149
142
  const signature = await this.signRaw(params.signerAddress, response.txId)
150
- const contractId = utils.binToHex(utils.contractIdFromAddress(response.contractAddress))
151
- return { ...response, contractId, signature, gasPrice: fromApiNumber256(response.gasPrice) }
143
+ return { signature, ...response }
152
144
  }
153
145
 
154
- async buildContractCreationTx(params: SignDeployContractTxParams): Promise<node.BuildDeployContractTxResult> {
155
- const data: node.BuildDeployContractTx = {
156
- ...(await this.usePublicKey(params)),
157
- initialAttoAlphAmount: toApiNumber256Optional(params.initialAttoAlphAmount),
158
- initialTokenAmounts: toApiTokens(params.initialTokenAmounts),
159
- issueTokenAmount: toApiNumber256Optional(params.issueTokenAmount),
160
- gasPrice: toApiNumber256Optional(params.gasPrice)
161
- }
162
- return this.getNodeProvider().contracts.postContractsUnsignedTxDeployContract(data)
146
+ override async buildDeployContractTx(
147
+ params: SignDeployContractTxParams
148
+ ): Promise<Omit<SignDeployContractTxResult, 'signature'>> {
149
+ return super.buildDeployContractTx(params, await this.getPublicKey(params.signerAddress))
163
150
  }
164
151
 
165
152
  async signExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult> {
166
- const response = await this.buildScriptTx(params)
153
+ const response = await this.buildExecuteScriptTx(params)
167
154
  const signature = await this.signRaw(params.signerAddress, response.txId)
168
- return { ...response, signature, gasPrice: fromApiNumber256(response.gasPrice) }
155
+ return { signature, ...response }
169
156
  }
170
157
 
171
- async buildScriptTx(params: SignExecuteScriptTxParams): Promise<node.BuildExecuteScriptTxResult> {
172
- const data: node.BuildExecuteScriptTx = {
173
- ...(await this.usePublicKey(params)),
174
- attoAlphAmount: toApiNumber256Optional(params.attoAlphAmount),
175
- tokens: toApiTokens(params.tokens),
176
- gasPrice: toApiNumber256Optional(params.gasPrice)
177
- }
178
- return this.getNodeProvider().contracts.postContractsUnsignedTxExecuteScript(data)
158
+ override async buildExecuteScriptTx(
159
+ params: SignExecuteScriptTxParams
160
+ ): Promise<Omit<SignExecuteScriptTxResult, 'signature'>> {
161
+ return super.buildExecuteScriptTx(params, await this.getPublicKey(params.signerAddress))
179
162
  }
180
163
 
181
164
  // in general, wallet should show the decoded information to user for confirmation
182
165
  // please overwrite this function for real wallet
183
166
  async signUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult> {
184
- const data = { unsignedTx: params.unsignedTx }
185
- const decoded = await this.getNodeProvider().transactions.postTransactionsDecodeUnsignedTx(data)
186
- const signature = await this.signRaw(params.signerAddress, decoded.unsignedTx.txId)
187
- return {
188
- fromGroup: decoded.fromGroup,
189
- toGroup: decoded.toGroup,
190
- unsignedTx: params.unsignedTx,
191
- txId: decoded.unsignedTx.txId,
192
- signature,
193
- gasAmount: decoded.unsignedTx.gasAmount,
194
- gasPrice: fromApiNumber256(decoded.unsignedTx.gasPrice)
195
- }
167
+ const response = await this.buildUnsignedTx(params)
168
+ const signature = await this.signRaw(params.signerAddress, response.txId)
169
+ return { signature, ...response }
196
170
  }
197
171
 
198
172
  async signMessage(params: SignMessageParams): Promise<SignMessageResult> {
@@ -0,0 +1,121 @@
1
+ /*
2
+ Copyright 2018 - 2022 The Alephium Authors
3
+ This file is part of the alephium project.
4
+
5
+ The library is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ The library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ import { utils } from '..'
20
+ import { fromApiNumber256, node, NodeProvider, toApiNumber256Optional, toApiTokens } from '../api'
21
+ import { addressFromPublicKey } from '../utils'
22
+ import { toApiDestinations } from './signer'
23
+ import {
24
+ SignDeployContractTxParams,
25
+ SignDeployContractTxResult,
26
+ SignerAddress,
27
+ SignExecuteScriptTxParams,
28
+ SignExecuteScriptTxResult,
29
+ SignTransferTxParams,
30
+ SignTransferTxResult,
31
+ SignUnsignedTxParams,
32
+ SignUnsignedTxResult
33
+ } from './types'
34
+
35
+ export abstract class TransactionBuilder {
36
+ abstract get nodeProvider(): NodeProvider
37
+
38
+ static create(baseUrl: string, apiKey?: string) {
39
+ const nodeProvider = new NodeProvider(baseUrl, apiKey)
40
+ return new (class extends TransactionBuilder {
41
+ get nodeProvider(): NodeProvider {
42
+ return nodeProvider
43
+ }
44
+ })()
45
+ }
46
+
47
+ private static validatePublicKey(params: SignerAddress, publicKey: string) {
48
+ const address = addressFromPublicKey(publicKey)
49
+ if (address !== params.signerAddress) {
50
+ throw new Error('Unmatched public key')
51
+ }
52
+ }
53
+
54
+ async buildTransferTx(
55
+ params: SignTransferTxParams,
56
+ publicKey: string
57
+ ): Promise<Omit<SignTransferTxResult, 'signature'>> {
58
+ TransactionBuilder.validatePublicKey(params, publicKey)
59
+
60
+ const { destinations, gasPrice, ...rest } = params
61
+ const data: node.BuildTransaction = {
62
+ fromPublicKey: publicKey,
63
+ destinations: toApiDestinations(destinations),
64
+ gasPrice: toApiNumber256Optional(gasPrice),
65
+ ...rest
66
+ }
67
+ const response = await this.nodeProvider.transactions.postTransactionsBuild(data)
68
+ return { ...response, gasPrice: fromApiNumber256(response.gasPrice) }
69
+ }
70
+
71
+ async buildDeployContractTx(
72
+ params: SignDeployContractTxParams,
73
+ publicKey: string
74
+ ): Promise<Omit<SignDeployContractTxResult, 'signature'>> {
75
+ TransactionBuilder.validatePublicKey(params, publicKey)
76
+
77
+ const { initialAttoAlphAmount, initialTokenAmounts, issueTokenAmount, gasPrice, ...rest } = params
78
+ const data: node.BuildDeployContractTx = {
79
+ fromPublicKey: publicKey,
80
+ initialAttoAlphAmount: toApiNumber256Optional(initialAttoAlphAmount),
81
+ initialTokenAmounts: toApiTokens(initialTokenAmounts),
82
+ issueTokenAmount: toApiNumber256Optional(issueTokenAmount),
83
+ gasPrice: toApiNumber256Optional(gasPrice),
84
+ ...rest
85
+ }
86
+ const response = await this.nodeProvider.contracts.postContractsUnsignedTxDeployContract(data)
87
+ const contractId = utils.binToHex(utils.contractIdFromAddress(response.contractAddress))
88
+ return { ...response, contractId, gasPrice: fromApiNumber256(response.gasPrice) }
89
+ }
90
+
91
+ async buildExecuteScriptTx(
92
+ params: SignExecuteScriptTxParams,
93
+ publicKey: string
94
+ ): Promise<Omit<SignExecuteScriptTxResult, 'signature'>> {
95
+ TransactionBuilder.validatePublicKey(params, publicKey)
96
+
97
+ const { attoAlphAmount, tokens, gasPrice, ...rest } = params
98
+ const data: node.BuildExecuteScriptTx = {
99
+ fromPublicKey: publicKey,
100
+ attoAlphAmount: toApiNumber256Optional(attoAlphAmount),
101
+ tokens: toApiTokens(tokens),
102
+ gasPrice: toApiNumber256Optional(gasPrice),
103
+ ...rest
104
+ }
105
+ const response = await this.nodeProvider.contracts.postContractsUnsignedTxExecuteScript(data)
106
+ return { ...response, gasPrice: fromApiNumber256(response.gasPrice) }
107
+ }
108
+
109
+ async buildUnsignedTx(params: SignUnsignedTxParams): Promise<Omit<SignUnsignedTxResult, 'signature'>> {
110
+ const data = { unsignedTx: params.unsignedTx }
111
+ const decoded = await this.nodeProvider.transactions.postTransactionsDecodeUnsignedTx(data)
112
+ return {
113
+ fromGroup: decoded.fromGroup,
114
+ toGroup: decoded.toGroup,
115
+ unsignedTx: params.unsignedTx,
116
+ txId: decoded.unsignedTx.txId,
117
+ gasAmount: decoded.unsignedTx.gasAmount,
118
+ gasPrice: fromApiNumber256(decoded.unsignedTx.gasPrice)
119
+ }
120
+ }
121
+ }
@@ -143,6 +143,13 @@ export interface SubmissionResult {
143
143
  export interface EnableOptionsBase {
144
144
  // chainGroup - specify whether to use addresses from a specific group
145
145
  chainGroup?: number
146
+ networkId: string
146
147
  onDisconnected: () => Promise<void>
147
- onNetworkChanged: (network: { networkName: string; networkId: number }) => Promise<void>
148
148
  }
149
+
150
+ // Transaction Params for InteractiveSignerProvider
151
+ export type ExtSignTransferTxParams = SignTransferTxParams & { networkId: string }
152
+ export type ExtSignDeployContractTxParams = SignDeployContractTxParams & { networkId: string }
153
+ export type ExtSignExecuteScriptTxParams = SignExecuteScriptTxParams & { networkId: string }
154
+ export type ExtSignUnsignedTxParams = SignUnsignedTxParams & { networkId: string }
155
+ export type ExtSignMessageParams = SignMessageParams & { networkId: string }