@alephium/web3 0.29.0 → 0.29.2

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.
@@ -157,6 +157,8 @@ export interface BuildDeployContractTx {
157
157
  initialTokenAmounts?: Token[];
158
158
  /** @format uint256 */
159
159
  issueTokenAmount?: string;
160
+ /** @format address */
161
+ issueTokenTo?: string;
160
162
  /** @format gas */
161
163
  gasAmount?: number;
162
164
  /** @format uint256 */
@@ -213,6 +215,13 @@ export interface BuildInfo {
213
215
  releaseVersion: string;
214
216
  commit: string;
215
217
  }
218
+ export interface BuildMultiAddressesTransaction {
219
+ from: Source[];
220
+ /** @format uint256 */
221
+ gasPrice?: string;
222
+ /** @format block-hash */
223
+ targetBlockHash?: string;
224
+ }
216
225
  export interface BuildMultisig {
217
226
  /** @format address */
218
227
  fromAddress: string;
@@ -329,6 +338,7 @@ export interface CallContractSucceeded {
329
338
  txInputs: string[];
330
339
  txOutputs: Output[];
331
340
  events: ContractEventByTxId[];
341
+ debugMessages: DebugMessage[];
332
342
  type: string;
333
343
  }
334
344
  export interface ChainInfo {
@@ -670,6 +680,16 @@ export interface SignResult {
670
680
  /** @format signature */
671
681
  signature: string;
672
682
  }
683
+ export interface Source {
684
+ /** @format hex-string */
685
+ fromPublicKey: string;
686
+ destinations: Destination[];
687
+ /** @format hex-string */
688
+ fromPublicKeyType?: string;
689
+ /** @format gas */
690
+ gasAmount?: number;
691
+ utxos?: OutputRef[];
692
+ }
673
693
  export interface SubmitMultisig {
674
694
  unsignedTx: string;
675
695
  signatures: string[];
@@ -963,7 +983,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
963
983
  }
964
984
  /**
965
985
  * @title Alephium API
966
- * @version 2.5.5
986
+ * @version 2.8.2
967
987
  * @baseUrl ../
968
988
  */
969
989
  export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -1431,6 +1451,15 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1431
1451
  * @request POST:/transactions/build
1432
1452
  */
1433
1453
  postTransactionsBuild: (data: BuildTransaction, params?: RequestParams) => Promise<BuildTransactionResult>;
1454
+ /**
1455
+ * No description
1456
+ *
1457
+ * @tags Transactions
1458
+ * @name PostTransactionsBuildMultiAddresses
1459
+ * @summary Build an unsigned transaction with multiple addresses to a number of recipients
1460
+ * @request POST:/transactions/build-multi-addresses
1461
+ */
1462
+ postTransactionsBuildMultiAddresses: (data: BuildMultiAddressesTransaction, params?: RequestParams) => Promise<BuildTransactionResult>;
1434
1463
  /**
1435
1464
  * No description
1436
1465
  *
@@ -151,7 +151,7 @@ class HttpClient {
151
151
  exports.HttpClient = HttpClient;
152
152
  /**
153
153
  * @title Alephium API
154
- * @version 2.5.5
154
+ * @version 2.8.2
155
155
  * @baseUrl ../
156
156
  */
157
157
  class Api extends HttpClient {
@@ -811,6 +811,22 @@ class Api extends HttpClient {
811
811
  format: 'json',
812
812
  ...params
813
813
  }).then(utils_1.convertHttpResponse),
814
+ /**
815
+ * No description
816
+ *
817
+ * @tags Transactions
818
+ * @name PostTransactionsBuildMultiAddresses
819
+ * @summary Build an unsigned transaction with multiple addresses to a number of recipients
820
+ * @request POST:/transactions/build-multi-addresses
821
+ */
822
+ postTransactionsBuildMultiAddresses: (data, params = {}) => this.request({
823
+ path: `/transactions/build-multi-addresses`,
824
+ method: 'POST',
825
+ body: data,
826
+ type: ContentType.Json,
827
+ format: 'json',
828
+ ...params
829
+ }).then(utils_1.convertHttpResponse),
814
830
  /**
815
831
  * No description
816
832
  *
@@ -99,10 +99,11 @@ export declare abstract class Artifact {
99
99
  readonly name: string;
100
100
  readonly functions: FunctionSig[];
101
101
  constructor(version: string, name: string, functions: FunctionSig[]);
102
- abstract buildByteCodeToDeploy(initialFields?: Fields): string;
102
+ abstract buildByteCodeToDeploy(initialFields: Fields, isDevnet: boolean): string;
103
103
  publicFunctions(): string[];
104
104
  usingPreapprovedAssetsFunctions(): string[];
105
105
  usingAssetsInContractFunctions(): string[];
106
+ isDevnet(signer: SignerProvider): Promise<boolean>;
106
107
  }
107
108
  export declare class Contract extends Artifact {
108
109
  readonly bytecode: string;
@@ -138,7 +139,7 @@ export declare class Contract extends Artifact {
138
139
  static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined, txId: string, getContractByCodeHash?: (codeHash: string) => Contract): ContractEvent;
139
140
  fromApiTestContractResult(methodName: string, result: node.TestContractResult, txId: string): TestContractResult<unknown>;
140
141
  txParamsForDeployment<P extends Fields>(signer: SignerProvider, params: DeployContractParams<P>): Promise<SignDeployContractTxParams>;
141
- buildByteCodeToDeploy(initialFields: Fields): string;
142
+ buildByteCodeToDeploy(initialFields: Fields, isDevnet: boolean): string;
142
143
  static fromApiEvents(events: node.ContractEventByTxId[], addressToCodeHash: Map<string, string>, txId: string, getContractByCodeHash?: (codeHash: string) => Contract): ContractEvent[];
143
144
  toApiCallContract<T extends Arguments>(params: CallContractParams<T>, groupIndex: number, contractAddress: string, methodIndex: number): node.CallContract;
144
145
  fromApiCallContractResult(result: node.CallContractResult, txId: string, methodIndex: number, getContractByCodeHash?: (codeHash: string) => Contract): CallContractResult<unknown>;
@@ -224,6 +225,7 @@ export interface DeployContractParams<P extends Fields = Fields> {
224
225
  initialAttoAlphAmount?: Number256;
225
226
  initialTokenAmounts?: Token[];
226
227
  issueTokenAmount?: Number256;
228
+ issueTokenTo?: string;
227
229
  gasAmount?: number;
228
230
  gasPrice?: Number256;
229
231
  }
@@ -271,6 +273,7 @@ export interface CallContractResult<R> {
271
273
  txInputs: string[];
272
274
  txOutputs: Output[];
273
275
  events: ContractEvent[];
276
+ debugMessages: DebugMessage[];
274
277
  }
275
278
  export declare const CreateContractEventAddress: string;
276
279
  export declare const DestroyContractEventAddress: string;
@@ -494,6 +494,13 @@ class Artifact {
494
494
  usingAssetsInContractFunctions() {
495
495
  return this.functions.filter((func) => func.useAssetsInContract).map((func) => func.name);
496
496
  }
497
+ async isDevnet(signer) {
498
+ if (!signer.nodeProvider) {
499
+ return false;
500
+ }
501
+ const chainParams = await signer.nodeProvider.infos.getInfosChainParams();
502
+ return (0, utils_1.isDevnet)(chainParams.networkId);
503
+ }
497
504
  }
498
505
  exports.Artifact = Artifact;
499
506
  class Contract extends Artifact {
@@ -587,7 +594,7 @@ class Contract extends Artifact {
587
594
  printDebugMessages(funcName, messages) {
588
595
  if (messages.length != 0) {
589
596
  console.log(`Testing ${this.name}.${funcName}:`);
590
- messages.forEach((m) => console.log(`Debug - ${m.contractAddress} - ${m.message}`));
597
+ messages.forEach((m) => console.log(`> Contract @ ${m.contractAddress} - ${m.message}`));
591
598
  }
592
599
  }
593
600
  toApiFields(fields) {
@@ -701,8 +708,9 @@ class Contract extends Artifact {
701
708
  };
702
709
  }
703
710
  async txParamsForDeployment(signer, params) {
711
+ const isDevnet = await this.isDevnet(signer);
704
712
  const initialFields = params.initialFields ?? {};
705
- const bytecode = this.buildByteCodeToDeploy(addStdIdToFields(this, initialFields));
713
+ const bytecode = this.buildByteCodeToDeploy(addStdIdToFields(this, initialFields), isDevnet);
706
714
  const selectedAccount = await signer.getSelectedAccount();
707
715
  const signerParams = {
708
716
  signerAddress: selectedAccount.address,
@@ -716,9 +724,9 @@ class Contract extends Artifact {
716
724
  };
717
725
  return signerParams;
718
726
  }
719
- buildByteCodeToDeploy(initialFields) {
727
+ buildByteCodeToDeploy(initialFields, isDevnet) {
720
728
  try {
721
- return ralph.buildContractByteCode(this.bytecode, initialFields, this.fieldsSig);
729
+ return ralph.buildContractByteCode(isDevnet ? this.bytecodeDebug : this.bytecode, initialFields, this.fieldsSig);
722
730
  }
723
731
  catch (error) {
724
732
  throw new Error(`Failed to build bytecode for contract ${this.name}, error: ${error}`);
@@ -760,7 +768,8 @@ class Contract extends Artifact {
760
768
  contracts: callResult.contracts.map((state) => Contract.fromApiContractState(state, getContractByCodeHash)),
761
769
  txInputs: callResult.txInputs,
762
770
  txOutputs: callResult.txOutputs.map((output) => fromApiOutput(output)),
763
- events: Contract.fromApiEvents(callResult.events, addressToCodeHash, txId, getContractByCodeHash)
771
+ events: Contract.fromApiEvents(callResult.events, addressToCodeHash, txId, getContractByCodeHash),
772
+ debugMessages: callResult.debugMessages
764
773
  };
765
774
  }
766
775
  }
@@ -1154,6 +1163,7 @@ async function callMethod(contract, instance, methodName, params, getContractByC
1154
1163
  const callParams = contract.contract.toApiCallContract({ ...params, txId: txId, args: params.args === undefined ? {} : params.args }, instance.groupIndex, instance.address, methodIndex);
1155
1164
  const result = await (0, global_1.getCurrentNodeProvider)().contracts.postContractsCallContract(callParams);
1156
1165
  const callResult = contract.contract.fromApiCallContractResult(result, txId, methodIndex, getContractByCodeHash);
1166
+ contract.contract.printDebugMessages(methodName, callResult.debugMessages);
1157
1167
  return callResult;
1158
1168
  }
1159
1169
  exports.callMethod = callMethod;
@@ -45,6 +45,7 @@ export interface SignDeployContractTxParams {
45
45
  initialAttoAlphAmount?: Number256;
46
46
  initialTokenAmounts?: Token[];
47
47
  issueTokenAmount?: Number256;
48
+ issueTokenTo?: string;
48
49
  gasAmount?: number;
49
50
  gasPrice?: Number256;
50
51
  }
@@ -39,6 +39,7 @@ export declare function blockChainIndex(blockHash: HexString): {
39
39
  export declare function stringToHex(str: string): string;
40
40
  export declare function hexToString(str: string): string;
41
41
  export declare function sleep(ms: number): Promise<void>;
42
+ export declare function isDevnet(networkId?: number): boolean;
42
43
  type _Eq<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
43
44
  export type Eq<X, Y> = _Eq<{
44
45
  [P in keyof X]: X[P];
@@ -20,7 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
20
20
  return (mod && mod.__esModule) ? mod : { "default": mod };
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.assertType = exports.sleep = exports.hexToString = exports.stringToHex = exports.blockChainIndex = exports.subContractId = exports.contractIdFromTx = exports.addressFromTokenId = exports.addressFromContractId = exports.addressFromScript = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.groupOfPrivateKey = exports.binToHex = exports.hexToBinUnsafe = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.AddressType = exports.toNonNegativeBigInt = exports.isHexString = exports.xorByte = exports.signatureDecode = exports.encodeHexSignature = exports.encodeSignature = exports.networkIds = void 0;
23
+ exports.assertType = exports.isDevnet = exports.sleep = exports.hexToString = exports.stringToHex = exports.blockChainIndex = exports.subContractId = exports.contractIdFromTx = exports.addressFromTokenId = exports.addressFromContractId = exports.addressFromScript = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.groupOfPrivateKey = exports.binToHex = exports.hexToBinUnsafe = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.AddressType = exports.toNonNegativeBigInt = exports.isHexString = exports.xorByte = exports.signatureDecode = exports.encodeHexSignature = exports.encodeSignature = exports.networkIds = void 0;
24
24
  const elliptic_1 = require("elliptic");
25
25
  const bn_js_1 = __importDefault(require("bn.js"));
26
26
  const blakejs_1 = __importDefault(require("blakejs"));
@@ -257,6 +257,10 @@ function sleep(ms) {
257
257
  return new Promise((resolve) => setTimeout(resolve, ms));
258
258
  }
259
259
  exports.sleep = sleep;
260
+ function isDevnet(networkId) {
261
+ return networkId !== 0 && networkId !== 1;
262
+ }
263
+ exports.isDevnet = isDevnet;
260
264
  // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
261
265
  function assertType() { }
262
266
  exports.assertType = assertType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.29.0",
3
+ "version": "0.29.2",
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,7 +27,7 @@
27
27
  },
28
28
  "author": "Alephium dev <dev@alephium.org>",
29
29
  "config": {
30
- "alephium_version": "2.5.5",
30
+ "alephium_version": "2.8.2",
31
31
  "explorer_backend_version": "1.16.1"
32
32
  },
33
33
  "type": "commonjs",
@@ -185,6 +185,8 @@ export interface BuildDeployContractTx {
185
185
  initialTokenAmounts?: Token[]
186
186
  /** @format uint256 */
187
187
  issueTokenAmount?: string
188
+ /** @format address */
189
+ issueTokenTo?: string
188
190
  /** @format gas */
189
191
  gasAmount?: number
190
192
  /** @format uint256 */
@@ -246,6 +248,14 @@ export interface BuildInfo {
246
248
  commit: string
247
249
  }
248
250
 
251
+ export interface BuildMultiAddressesTransaction {
252
+ from: Source[]
253
+ /** @format uint256 */
254
+ gasPrice?: string
255
+ /** @format block-hash */
256
+ targetBlockHash?: string
257
+ }
258
+
249
259
  export interface BuildMultisig {
250
260
  /** @format address */
251
261
  fromAddress: string
@@ -373,6 +383,7 @@ export interface CallContractSucceeded {
373
383
  txInputs: string[]
374
384
  txOutputs: Output[]
375
385
  events: ContractEventByTxId[]
386
+ debugMessages: DebugMessage[]
376
387
  type: string
377
388
  }
378
389
 
@@ -773,6 +784,17 @@ export interface SignResult {
773
784
  signature: string
774
785
  }
775
786
 
787
+ export interface Source {
788
+ /** @format hex-string */
789
+ fromPublicKey: string
790
+ destinations: Destination[]
791
+ /** @format hex-string */
792
+ fromPublicKeyType?: string
793
+ /** @format gas */
794
+ gasAmount?: number
795
+ utxos?: OutputRef[]
796
+ }
797
+
776
798
  export interface SubmitMultisig {
777
799
  unsignedTx: string
778
800
  signatures: string[]
@@ -1256,7 +1278,7 @@ export class HttpClient<SecurityDataType = unknown> {
1256
1278
 
1257
1279
  /**
1258
1280
  * @title Alephium API
1259
- * @version 2.5.5
1281
+ * @version 2.8.2
1260
1282
  * @baseUrl ../
1261
1283
  */
1262
1284
  export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -2114,6 +2136,27 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
2114
2136
  ...params
2115
2137
  }).then(convertHttpResponse),
2116
2138
 
2139
+ /**
2140
+ * No description
2141
+ *
2142
+ * @tags Transactions
2143
+ * @name PostTransactionsBuildMultiAddresses
2144
+ * @summary Build an unsigned transaction with multiple addresses to a number of recipients
2145
+ * @request POST:/transactions/build-multi-addresses
2146
+ */
2147
+ postTransactionsBuildMultiAddresses: (data: BuildMultiAddressesTransaction, params: RequestParams = {}) =>
2148
+ this.request<
2149
+ BuildTransactionResult,
2150
+ BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable
2151
+ >({
2152
+ path: `/transactions/build-multi-addresses`,
2153
+ method: 'POST',
2154
+ body: data,
2155
+ type: ContentType.Json,
2156
+ format: 'json',
2157
+ ...params
2158
+ }).then(convertHttpResponse),
2159
+
2117
2160
  /**
2118
2161
  * No description
2119
2162
  *
@@ -55,7 +55,8 @@ import {
55
55
  groupOfAddress,
56
56
  addressFromContractId,
57
57
  WebCrypto,
58
- hexToBinUnsafe
58
+ hexToBinUnsafe,
59
+ isDevnet
59
60
  } from '../utils'
60
61
  import { getCurrentNodeProvider } from '../global'
61
62
  import * as path from 'path'
@@ -715,7 +716,7 @@ export abstract class Artifact {
715
716
  this.functions = functions
716
717
  }
717
718
 
718
- abstract buildByteCodeToDeploy(initialFields?: Fields): string
719
+ abstract buildByteCodeToDeploy(initialFields: Fields, isDevnet: boolean): string
719
720
 
720
721
  publicFunctions(): string[] {
721
722
  return this.functions.filter((func) => func.isPublic).map((func) => func.name)
@@ -728,6 +729,14 @@ export abstract class Artifact {
728
729
  usingAssetsInContractFunctions(): string[] {
729
730
  return this.functions.filter((func) => func.useAssetsInContract).map((func) => func.name)
730
731
  }
732
+
733
+ async isDevnet(signer: SignerProvider): Promise<boolean> {
734
+ if (!signer.nodeProvider) {
735
+ return false
736
+ }
737
+ const chainParams = await signer.nodeProvider.infos.getInfosChainParams()
738
+ return isDevnet(chainParams.networkId)
739
+ }
731
740
  }
732
741
 
733
742
  export class Contract extends Artifact {
@@ -884,7 +893,7 @@ export class Contract extends Artifact {
884
893
  printDebugMessages(funcName: string, messages: DebugMessage[]) {
885
894
  if (messages.length != 0) {
886
895
  console.log(`Testing ${this.name}.${funcName}:`)
887
- messages.forEach((m) => console.log(`Debug - ${m.contractAddress} - ${m.message}`))
896
+ messages.forEach((m) => console.log(`> Contract @ ${m.contractAddress} - ${m.message}`))
888
897
  }
889
898
  }
890
899
 
@@ -1039,8 +1048,9 @@ export class Contract extends Artifact {
1039
1048
  signer: SignerProvider,
1040
1049
  params: DeployContractParams<P>
1041
1050
  ): Promise<SignDeployContractTxParams> {
1051
+ const isDevnet = await this.isDevnet(signer)
1042
1052
  const initialFields: Fields = params.initialFields ?? {}
1043
- const bytecode = this.buildByteCodeToDeploy(addStdIdToFields(this, initialFields))
1053
+ const bytecode = this.buildByteCodeToDeploy(addStdIdToFields(this, initialFields), isDevnet)
1044
1054
  const selectedAccount = await signer.getSelectedAccount()
1045
1055
  const signerParams: SignDeployContractTxParams = {
1046
1056
  signerAddress: selectedAccount.address,
@@ -1055,9 +1065,9 @@ export class Contract extends Artifact {
1055
1065
  return signerParams
1056
1066
  }
1057
1067
 
1058
- buildByteCodeToDeploy(initialFields: Fields): string {
1068
+ buildByteCodeToDeploy(initialFields: Fields, isDevnet: boolean): string {
1059
1069
  try {
1060
- return ralph.buildContractByteCode(this.bytecode, initialFields, this.fieldsSig)
1070
+ return ralph.buildContractByteCode(isDevnet ? this.bytecodeDebug : this.bytecode, initialFields, this.fieldsSig)
1061
1071
  } catch (error) {
1062
1072
  throw new Error(`Failed to build bytecode for contract ${this.name}, error: ${error}`)
1063
1073
  }
@@ -1116,7 +1126,8 @@ export class Contract extends Artifact {
1116
1126
  contracts: callResult.contracts.map((state) => Contract.fromApiContractState(state, getContractByCodeHash)),
1117
1127
  txInputs: callResult.txInputs,
1118
1128
  txOutputs: callResult.txOutputs.map((output) => fromApiOutput(output)),
1119
- events: Contract.fromApiEvents(callResult.events, addressToCodeHash, txId, getContractByCodeHash)
1129
+ events: Contract.fromApiEvents(callResult.events, addressToCodeHash, txId, getContractByCodeHash),
1130
+ debugMessages: callResult.debugMessages
1120
1131
  }
1121
1132
  }
1122
1133
  }
@@ -1410,6 +1421,7 @@ export interface DeployContractParams<P extends Fields = Fields> {
1410
1421
  initialAttoAlphAmount?: Number256
1411
1422
  initialTokenAmounts?: Token[]
1412
1423
  issueTokenAmount?: Number256
1424
+ issueTokenTo?: string
1413
1425
  gasAmount?: number
1414
1426
  gasPrice?: Number256
1415
1427
  }
@@ -1502,6 +1514,7 @@ export interface CallContractResult<R> {
1502
1514
  txInputs: string[]
1503
1515
  txOutputs: Output[]
1504
1516
  events: ContractEvent[]
1517
+ debugMessages: DebugMessage[]
1505
1518
  }
1506
1519
 
1507
1520
  function specialContractAddress(n: number): string {
@@ -1766,6 +1779,7 @@ export async function callMethod<I extends ContractInstance, F extends Fields, A
1766
1779
  )
1767
1780
  const result = await getCurrentNodeProvider().contracts.postContractsCallContract(callParams)
1768
1781
  const callResult = contract.contract.fromApiCallContractResult(result, txId, methodIndex, getContractByCodeHash)
1782
+ contract.contract.printDebugMessages(methodName, callResult.debugMessages)
1769
1783
  return callResult as CallContractResult<R>
1770
1784
  }
1771
1785
 
@@ -73,6 +73,7 @@ export interface SignDeployContractTxParams {
73
73
  initialAttoAlphAmount?: Number256
74
74
  initialTokenAmounts?: Token[]
75
75
  issueTokenAmount?: Number256
76
+ issueTokenTo?: string
76
77
  gasAmount?: number
77
78
  gasPrice?: Number256
78
79
  }
@@ -265,6 +265,10 @@ export function sleep(ms: number): Promise<void> {
265
265
  return new Promise((resolve) => setTimeout(resolve, ms))
266
266
  }
267
267
 
268
+ export function isDevnet(networkId?: number): boolean {
269
+ return networkId !== 0 && networkId !== 1
270
+ }
271
+
268
272
  type _Eq<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false
269
273
  export type Eq<X, Y> = _Eq<{ [P in keyof X]: X[P] }, { [P in keyof Y]: Y[P] }>
270
274
  // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars