suidouble 0.0.51 → 1.0.4-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.
package/README.md CHANGED
@@ -51,31 +51,31 @@ You can initialize it directly, if you have keypair, secret phrase and can use i
51
51
  const suiMaster = new SuiMaster({
52
52
  keypair: Ed25519Keypair || Secp256r1Keypair || Secp256k1Keypair,
53
53
  debug: true, // echo testing messages to console
54
- provider: 'test', // 'test', 'dev', 'local', 'main' or instance of this lib's SuiLocalTestValidator, or instance of Sui's JsonRpcProvider
54
+ client: 'test', // 'test', 'dev', 'local', 'main' or instance of this lib's SuiLocalTestValidator
55
55
  });
56
56
  const suiMaster = new SuiMaster({
57
57
  debug: false,
58
58
  phrase: 'thrive mean two thrive mean two thrive mean two thrive mean two', // secret phrase to generate keypair
59
- provider: 'dev',
59
+ client: 'dev',
60
60
  });
61
61
  const suiMaster = new SuiMaster({
62
62
  debug: false,
63
63
  phrase: 'thrive mean two thrive mean two thrive mean two thrive mean two', // secret phrase to generate keypair
64
64
  accountIndex: 1, // derive path index (you can generate few addresses with same seed phrase)
65
- provider: 'dev',
65
+ client: 'dev',
66
66
  });
67
67
  const suiMaster = new SuiMaster({
68
68
  debug: false,
69
69
  phrase: 'thrive mean two thrive mean two thrive mean two thrive mean two', // secret phrase to generate keypair
70
70
  keypairAlgo: 'secp256k1', // 'secp256r1' or 'secp256r1' or 'ed25519' default is ed25519
71
- provider: 'dev',
71
+ client: 'dev',
72
72
  });
73
73
  ```
74
74
 
75
75
  Also, there's option to generate pseudo-random phrases and wallets from strings, works like a charm for testing:
76
76
  ```javascript
77
- const suiMasterAsAdmin = new SuiMaster({ as: 'admin', provider: 'dev', });
78
- const suiMasterAsUser = new SuiMaster({ as: 'user', provider: 'dev', });
77
+ const suiMasterAsAdmin = new SuiMaster({ as: 'admin', client: 'dev', });
78
+ const suiMasterAsUser = new SuiMaster({ as: 'user', client: 'dev', });
79
79
  ```
80
80
 
81
81
  On browser side, you'd probably want to use Sui wallets extensions adapters to sign message and don't store any keypairs or secret phrases in your code. So there's SuiInBrowser class for this, which can setup suiMaster instance for you. See 'Sui Move Connect in browser' section or sample UI application's code for more details.
@@ -199,7 +199,7 @@ await module.unsubscribeEvents();
199
199
 
200
200
  ```javascript
201
201
  // executing method with parameters of (chat_shop: &ChatShop, metadata: vector<u8>, text: vector<u8>)
202
- const res = await contract.moveCall('chat', 'post', ['0x10cded4f9df05e37b44e3be2ffa9004dec77786950719fad6083694fdca45bf2', [3,24,55], 'anotherparam']);
202
+ const res = await contract.moveCall('chat', 'post', ['0x10cded4f9df05e37b44e3be2ffa9004dec77786950719fad6083694fdca45bf2', contract.arg('vector<u8>', [3,24,55]), contract.arg('string', 'anotherparam') ]);
203
203
  // or await contract.modules.chat.moveCall('methodname', ['somedata', [3,24,55], 'anotherparam']);
204
204
  console.log(res);
205
205
  for (const object of res.created) {
@@ -213,6 +213,42 @@ const res = await contract.moveCall('chat', 'post', ['0x10cded4f9df05e37b44e3be2
213
213
  }
214
214
  ```
215
215
 
216
+ ##### move methods argumets types
217
+
218
+ Sui forces you to specify argument type in SDK v1.0, so we are going to follow this paradigm. With few little helpers. Both `SuiPackage` and `SuiPackageModule` have methods to make Inputs.Pure with bcs for you based on the desired type, you can use for executing `suiPackage.moveCall` or `suiPackageModule.moveCall`:
219
+
220
+ ```javascript
221
+ const arguments = [];
222
+ arguments.push(contract.arg('bool', true));
223
+ arguments.push(contract.arg('u8', 222));
224
+ arguments.push(contract.arg('u16', 2222));
225
+ arguments.push(contract.arg('u32', 3333));
226
+ arguments.push(contract.arg('u64', 4444));
227
+ arguments.push(contract.arg('u128', 5555));
228
+ arguments.push(contract.arg('u256', 6666));
229
+ arguments.push(contract.arg('address', '0xd9a95d7cc137f71dd7766f02791536453062a7509e9f461620cc4f583b09134c'));
230
+ arguments.push(contract.arg('string', 'some utf-8 💧string'));
231
+ arguments.push(contract.arg('vector<u8>', 222)); // works for other vectors with primitive contents, e.g. u128, bool etc
232
+ ```
233
+
234
+ Take a look at unit test covering all types arguments [here](test/different_types_args.test.js)
235
+
236
+ ##### move methods typed arguments
237
+
238
+ To specify types for move methods declared as:
239
+
240
+ ```rust
241
+ public entry fun method<T>(...)
242
+ ```
243
+
244
+ you can specify `typeArguments` as a 3rd parameter to `suiPackageModule.moveCall` or 4th to `suiPackage.moveCall`:
245
+
246
+ ```javascript
247
+ await mod.moveCall('test_method', [ store.id ], [ '0xca90beae66f23df1a830357c92e0a4348b6164d142c96b06936c5f28fdeaa99f::different_types::Store' ]);
248
+ await contract.moveCall('module_name', 'test_method', [ store.id ], [ '0xca90beae66f23df1a83036936c5f28fdeaa99f::different_types::Store' ]);
249
+ ```
250
+
251
+
216
252
  ##### sending sui / coins with smart contract methods
217
253
 
218
254
  If you need to transfer some SUI/coins as part of executing contract method, you can use a magic parameter in form of:
@@ -234,7 +270,7 @@ So executing
234
270
  const params = [
235
271
  chatShopObjectId,
236
272
  {type: '0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN', amount: '9.99'},
237
- messageText,
273
+ contract.arg('string', messageText),
238
274
  ];
239
275
  const moveCallResult = await contract.moveCall('suidouble_chat', 'post_pay', params);
240
276
  ```
@@ -247,7 +283,7 @@ Some smart contracts requires clients to send coins in form of vectors. This is
247
283
  const params = [
248
284
  chatShopObjectId,
249
285
  [{type: '0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN', amount: '9.99'}],
250
- messageText,
286
+ contract.arg('string', messageText),
251
287
  ];
252
288
  ```
253
289
 
@@ -265,7 +301,7 @@ const txb = new TransactionBlock();
265
301
  txb.moveCall({
266
302
  target: `package_id::module_id::method_name`,
267
303
  arguments: [
268
- txb.pure(something),
304
+ txb.pure(contract.arg('u256', something)),
269
305
  txb.object(someid),
270
306
  ],
271
307
  });
@@ -306,8 +342,8 @@ Builds a package and publish it to blockchain. CLI thing, as it needs `execSync`
306
342
  ```javascript
307
343
  const { SuiMaster } = require('suidouble');
308
344
 
309
- const provider = 'dev';
310
- const suiMaster = new SuiMaster({ debug: true, as: 'admin', provider: provider, });
345
+ const client = 'dev';
346
+ const suiMaster = new SuiMaster({ debug: true, as: 'admin', client: client, });
311
347
 
312
348
  await suiMaster.requestSuiFromFaucet();
313
349
  await suiMaster.getBalance();
@@ -327,9 +363,9 @@ Same, it's for CLI as it re-builds the package.
327
363
  ```javascript
328
364
  const { SuiMaster } = require('suidouble');
329
365
 
330
- const provider = 'local';// or await SuiLocalTestValidator.launch({debug: true, epochDuration: 30000});
366
+ const client = 'local';// or await SuiLocalTestValidator.launch({debug: true, epochDuration: 30000});
331
367
 
332
- const suiMaster = new SuiMaster({ debug: true, as: 'admin', provider: provider, });
368
+ const suiMaster = new SuiMaster({ debug: true, as: 'admin', client: client, });
333
369
  await suiMaster.requestSuiFromFaucet();
334
370
  await suiMaster.getBalance();
335
371
 
@@ -362,7 +398,7 @@ await testScenario.init();
362
398
 
363
399
  await testScenario.nextTx('admin', async()=>{
364
400
  const chatShop = testScenario.takeShared('ChatShop');
365
- await testScenario.moveCall('chat', 'post', [chatShop.address, 'posting a message', 'metadata']);
401
+ await testScenario.moveCall('chat', 'post', [chatShop.address, testScenario.arg('string', 'posting a message'), testScenario.arg('string', 'metadata') ]);
366
402
  const chatTopMessage = testScenario.takeShared('ChatTopMessage');
367
403
 
368
404
  assert(chatTopMessage != null);
@@ -371,7 +407,7 @@ await testScenario.nextTx('admin', async()=>{
371
407
 
372
408
  await testScenario.nextTx('somebody', async()=>{
373
409
  const chatTopMessage = testScenario.takeShared('ChatTopMessage');
374
- await testScenario.moveCall('chat', 'reply', [chatTopMessage.address, 'posting a response', 'metadata']);
410
+ await testScenario.moveCall('chat', 'reply', [chatTopMessage.address, testScenario.arg('string', 'posting a response'), testScenario.arg('string', 'metadata') ]);
375
411
  const chatResponse = testScenario.takeFromSender('ChatResponse');
376
412
 
377
413
  assert(chatResponse != null);
@@ -420,7 +456,7 @@ suiInBrowser.addEventListener('connected', async()=>{
420
456
  console.log('event', event.parsedJson);
421
457
  }
422
458
 
423
- const res = await contract.moveCall('chat', 'post', ['somedata', [3,24,55], 'anotherparam']);
459
+ const res = await contract.moveCall('chat', 'post', [contract.arg('string', 'somedata'), contract.arg('vector<u8>', 'somedata') ]);
424
460
  console.log(res);
425
461
  for (const object of res.created) {
426
462
  console.log('created', object.address, 'with type of', object.typeName); // instances of SuiObject (@todo: write documentation for it)
package/index.js CHANGED
@@ -2,9 +2,9 @@ const SuiMaster = require('./lib/SuiMaster.js');
2
2
  const SuiInBrowser = require('./lib/SuiInBrowser.js');
3
3
  const SuiTestScenario = require('./lib/SuiTestScenario.js');
4
4
  const SuiObject = require('./lib/SuiObject.js');
5
+ const SuiUtils = require('./lib/SuiUtils.js');
5
6
  const SuiLocalTestValidator = require('./lib/SuiLocalTestValidator.js');
6
-
7
- const { TransactionBlock,Transactions } = require('@mysten/sui.js/transactions');
7
+ const { Transaction, Commands } = require('@mysten/sui/transactions');
8
8
 
9
9
  module.exports = {
10
10
  SuiMaster,
@@ -13,7 +13,7 @@ module.exports = {
13
13
  SuiTestScenario,
14
14
  SuiLocalTestValidator,
15
15
  MIST_PER_SUI: SuiMaster.MIST_PER_SUI,
16
-
17
- TransactionBlock: TransactionBlock,
18
- Transactions: Transactions,
16
+ Transaction: Transaction,
17
+ Commands: Commands,
18
+ SuiUtils: SuiUtils,
19
19
  };
package/lib/SuiCoin.js CHANGED
@@ -1,4 +1,7 @@
1
- const { Transactions } = require('@mysten/sui.js/transactions');
1
+ const { Commands } = require('@mysten/sui/transactions');
2
+ const { bcs } = require('@mysten/sui/bcs');
3
+ // console.log(bcs);
4
+
2
5
 
3
6
  const safeList = {
4
7
  'sui:mainnet': {
@@ -159,7 +162,7 @@ class SuiCoin {
159
162
 
160
163
  let result = null;
161
164
  try {
162
- result = await this.suiMaster.provider.getCoinMetadata({
165
+ result = await this.suiMaster.client.getCoinMetadata({
163
166
  coinType: this.coinType,
164
167
  });
165
168
  } catch (e) {
@@ -180,7 +183,7 @@ class SuiCoin {
180
183
  let result = null;
181
184
  let cursor = null;
182
185
  do {
183
- result = await this.suiMaster.provider.getCoins({
186
+ result = await this.suiMaster.client.getCoins({
184
187
  owner: owner,
185
188
  coinType: this.coinType,
186
189
  limit: 50,
@@ -212,18 +215,24 @@ class SuiCoin {
212
215
  if (coinIds.length == 1) {
213
216
  // only one coin object enough to cover the expense
214
217
  if (this.isSUI()) {
215
- const coinInput = txb.add(Transactions.SplitCoins(txb.gas, [txb.pure(expectedAmountAsBigInt)]));
218
+ // console.log(txb.gas);
219
+ // console.log(bcs);
220
+ // console.log(txb.pure(bcs.vector(bcs.u64).serialize([expectedAmountAsBigInt])));
221
+ // console.log(txb.pure.u64(expectedAmountAsBigInt));
222
+ // txb.pure(bcs.vector(bcs.u64).serialize(['0x123']))
223
+
224
+ const coinInput = txb.add(Commands.SplitCoins(txb.gas, [txb.pure.u64(expectedAmountAsBigInt)]));
216
225
  return coinInput;
217
226
  } else {
218
227
  // some other coin
219
- const coinInput = txb.add(Transactions.SplitCoins(txb.object(coinIds[0]), [txb.pure(expectedAmountAsBigInt)]));
228
+ const coinInput = txb.add(Commands.SplitCoins(txb.object(coinIds[0]), [txb.pure(expectedAmountAsBigInt)]));
220
229
  return coinInput;
221
230
  }
222
231
  } else {
223
232
  // few coin objects to merge
224
233
  const coinIdToMergeIn = coinIds.shift();
225
- txb.add(Transactions.MergeCoins(txb.object(coinIdToMergeIn), coinIds.map((id)=>{return txb.object(id);})));
226
- const coinInputSplet = txb.add(Transactions.SplitCoins(txb.object(coinIdToMergeIn), [txb.pure(expectedAmountAsBigInt)]));
234
+ txb.add(Commands.MergeCoins(txb.object(coinIdToMergeIn), coinIds.map((id)=>{return txb.object(id);})));
235
+ const coinInputSplet = txb.add(Commands.SplitCoins(txb.object(coinIdToMergeIn), [txb.pure(expectedAmountAsBigInt)]));
227
236
 
228
237
  return coinInputSplet;
229
238
  }
@@ -238,7 +247,7 @@ class SuiCoin {
238
247
  let result = null;
239
248
  let cursor = null;
240
249
  do {
241
- result = await this.suiMaster.provider.getCoins({
250
+ result = await this.suiMaster.client.getCoins({
242
251
  owner: owner,
243
252
  coinType: this.coinType,
244
253
  limit: 50,
@@ -2,7 +2,7 @@ const SuiCommonMethods = require('./SuiCommonMethods.js');
2
2
  const SuiInBrowserAdapter = require('./SuiInBrowserAdapter.js');
3
3
  const WalletsStandardCore = require('@wallet-standard/core');
4
4
  const icons = require('./data/icons.json');
5
- const { SuiClient, getFullnodeUrl } = require('@mysten/sui.js/client');
5
+ const { SuiClient, getFullnodeUrl } = require('@mysten/sui/client');
6
6
 
7
7
  const SuiMaster = require('./SuiMaster.js');
8
8
 
@@ -22,7 +22,7 @@ class SuiInBrowser extends SuiCommonMethods {
22
22
  this._isConnected = false;
23
23
  this._isConnecting = false;
24
24
 
25
- this._provider = null;
25
+ this._client = null;
26
26
  this._suiMaster = null;
27
27
 
28
28
  setTimeout(()=>{
@@ -42,17 +42,21 @@ class SuiInBrowser extends SuiCommonMethods {
42
42
  return await this._activeAdapter.signAndExecuteTransactionBlock(params);
43
43
  }
44
44
 
45
- get provider() {
46
- return this._provider;
45
+ async signAndExecuteTransaction(params) {
46
+ return await this._activeAdapter.signAndExecuteTransaction(params);
47
47
  }
48
48
 
49
- async getProvider() {
50
- await this.initProvider();
51
- return this._provider;
49
+ get client() {
50
+ return this._client;
51
+ }
52
+
53
+ async getClient() {
54
+ await this.initClient();
55
+ return this._client;
52
56
  }
53
57
 
54
58
  async getSuiMaster() {
55
- await this.initProvider();
59
+ await this.initClient();
56
60
  return this._suiMaster;
57
61
  }
58
62
 
@@ -117,11 +121,11 @@ class SuiInBrowser extends SuiCommonMethods {
117
121
 
118
122
  if (this._connectedChain != wasConnectedToChain) {
119
123
  this.log('chain was switched');
120
- this._provider = null;
124
+ this._client = null;
121
125
  this._suiMaster = null;
122
126
  }
123
127
 
124
- this.initProvider();
128
+ this.initClient();
125
129
 
126
130
  this.emit('connected');
127
131
  }
@@ -168,8 +172,8 @@ class SuiInBrowser extends SuiCommonMethods {
168
172
  return this._connectedChain ? this._connectedChain : this._defaultChain;
169
173
  }
170
174
 
171
- async initProvider() {
172
- if (this._provider) {
175
+ async initClient() {
176
+ if (this._client) {
173
177
  return true;
174
178
  }
175
179
 
@@ -182,16 +186,17 @@ class SuiInBrowser extends SuiCommonMethods {
182
186
  throw new Error('invalid chain: '+chainName);
183
187
  }
184
188
 
185
- this._provider = new SuiClient({url: chainSettings[chainName].fullnode});
189
+ this._client = new SuiClient({url: chainSettings[chainName].fullnode});
190
+ this._client.endpoint = chainSettings[chainName].fullnode;
186
191
  this._suiMaster = new SuiMaster({
187
192
  debug: this._debug,
188
193
  signer: this,
189
- provider: this._provider,
194
+ client: this._client,
190
195
  });
191
196
  }
192
197
 
193
198
  async initialize() {
194
- await this.initProvider(); // set default provider
199
+ await this.initClient(); // set default client
195
200
 
196
201
  // create empty adapters (we need instances even if they are not installed)
197
202
  for (const possibleAdapterParams of SuiInBrowser.getPossibleWallets()) {
@@ -8,6 +8,8 @@ const Feature = {
8
8
  EVENTS: 'standard:events',
9
9
  SUI_SIGN_AND_EXECUTE_TX_BLOCK: 'sui:signAndExecuteTransactionBlock',
10
10
  SUI_SIGN_TX_BLOCK: 'sui:signTransactionBlock',
11
+ SUI_SIGN_AND_EXECUTE_TX: 'sui:signAndExecuteTransaction',
12
+ SUI_SIGN_TX: 'sui:signTransaction',
11
13
  SUI_SIGN_MESSAGE: 'sui:signMessage'
12
14
  };
13
15
 
@@ -30,10 +32,30 @@ class SuiInBrowserAdapter extends SuiCommonMethods {
30
32
  this._isConnected = false;
31
33
  }
32
34
 
35
+ async signAndExecuteTransaction(params) {
36
+ if (this.hasFeature(Feature.SUI_SIGN_AND_EXECUTE_TX)) {
37
+ return await this.getFeature(Feature.SUI_SIGN_AND_EXECUTE_TX).signAndExecuteTransaction(params);
38
+ } else {
39
+ // outdated wallet?
40
+ params.transactionBlock = params.transaction;
41
+ return await this.getFeature(Feature.SUI_SIGN_AND_EXECUTE_TX_BLOCK).signAndExecuteTransactionBlock(params);
42
+ }
43
+ }
44
+
33
45
  async signAndExecuteTransactionBlock(params) {
34
46
  return await this.getFeature(Feature.SUI_SIGN_AND_EXECUTE_TX_BLOCK).signAndExecuteTransactionBlock(params);
35
47
  }
36
48
 
49
+ async signTransactionBlock(params) {
50
+ if (this.hasFeature(Feature.SUI_SIGN_TX)) {
51
+ return await this.getFeature(Feature.SUI_SIGN_TX).signTransaction(params);
52
+ } else {
53
+ // outdated wallet?
54
+ params.transactionBlock = params.transaction;
55
+ return await this.getFeature(Feature.SUI_SIGN_TX_BLOCK).signTransactionBlock(params);
56
+ }
57
+ }
58
+
37
59
  async signTransactionBlock(params) {
38
60
  return await this.getFeature(Feature.SUI_SIGN_TX_BLOCK).signTransactionBlock(params);
39
61
  }
@@ -3,7 +3,8 @@ const SuiCliCommands = require('./SuiCliCommands.js');
3
3
  const SuiCommonMethods = require('./SuiCommonMethods.js');
4
4
  // const { JsonRpcProvider, localnetConnection, devnetConnection } = require('@mysten/sui.js');
5
5
 
6
- const { SuiClient, getFullnodeUrl } = require('@mysten/sui.js/client');
6
+ const { SuiClient, getFullnodeUrl, SuiHTTPTransport } = require('@mysten/sui/client');
7
+ const SuiUtils = require('./SuiUtils.js');
7
8
 
8
9
  class SuiLocalTestValidator extends SuiCommonMethods {
9
10
  constructor(params = {}) {
@@ -28,12 +29,20 @@ class SuiLocalTestValidator extends SuiCommonMethods {
28
29
  return this._providerName;
29
30
  }
30
31
 
31
- get provider() {
32
+ get client() {
32
33
  if (this._providerName === 'sui:localnet') {
33
- return new SuiClient({url: getFullnodeUrl('localnet')});
34
+ return new SuiClient({
35
+ transport: new SuiHTTPTransport({
36
+ url: getFullnodeUrl('localnet'),
37
+ WebSocketConstructor: SuiUtils.WebSocketConstructor(),
38
+ }),
39
+ });
34
40
  } else if (this._providerName === 'sui:devnet') {
35
41
  // if testFallbackEnabled == true and we can't start local node
36
- return new SuiClient({url: getFullnodeUrl('devnet')});//JsonRpcProvider(devnetConnection);
42
+ return new SuiClient({
43
+ url: getFullnodeUrl('devnet'),
44
+ WebSocketConstructor: SuiUtils.WebSocketConstructor(),
45
+ });
37
46
  }
38
47
  }
39
48
 
package/lib/SuiMaster.js CHANGED
@@ -7,13 +7,14 @@ const SuiObject = require('./SuiObject.js');
7
7
  const SuiTransaction = require('./SuiTransaction.js');
8
8
  const SuiEvent = require('./SuiEvent.js');
9
9
  const SuiCoins = require('./SuiCoins.js');
10
- const { SuiClient, getFullnodeUrl } = require('@mysten/sui.js/client');
11
- const { MIST_PER_SUI } = require('@mysten/sui.js/utils');
12
- const { Ed25519Keypair } = require('@mysten/sui.js/keypairs/ed25519');
13
- const { Secp256r1Keypair } = require('@mysten/sui.js/keypairs/secp256r1');
14
- const { Secp256k1Keypair } = require('@mysten/sui.js/keypairs/secp256k1');
15
- const { requestSuiFromFaucetV0, getFaucetHost } = require('@mysten/sui.js/faucet');
16
- const { TransactionBlock, Transactions } = require('@mysten/sui.js/transactions');
10
+ const SuiUtils = require('./SuiUtils.js');
11
+ const { MIST_PER_SUI } = require('@mysten/sui/utils');
12
+ const { Ed25519Keypair } = require('@mysten/sui/keypairs/ed25519');
13
+ const { Secp256r1Keypair } = require('@mysten/sui/keypairs/secp256r1');
14
+ const { Secp256k1Keypair } = require('@mysten/sui/keypairs/secp256k1');
15
+ const { requestSuiFromFaucetV0, getFaucetHost } = require('@mysten/sui/faucet');
16
+ const { Transaction, Commands } = require('@mysten/sui/transactions');
17
+
17
18
 
18
19
  class SuiMaster extends SuiCommonMethods {
19
20
  constructor(params = {}) {
@@ -65,7 +66,6 @@ class SuiMaster extends SuiCommonMethods {
65
66
  }
66
67
  }
67
68
 
68
-
69
69
  this.log('goint to use keypair of', this._keypair.getPublicKey().toSuiAddress());
70
70
  } else if (params.as) {
71
71
  // generate pseudo-random keypair
@@ -74,69 +74,12 @@ class SuiMaster extends SuiCommonMethods {
74
74
  this.log('goint to use keypair of', this._keypair.getPublicKey().toSuiAddress());
75
75
  }
76
76
 
77
- this._provider = null;
78
- this._providerName = null;
79
- if (params.provider) {
80
- if (params.provider == 'local' || (params.provider.constructor && params.provider.constructor.name && params.provider.constructor.name == 'SuiLocalTestValidator')) {
81
- if (params.provider == 'local') {
82
- this._provider = new SuiClient({url: getFullnodeUrl('localnet')});
83
- this._providerName = 'sui:localnet';
84
- } else {
85
- // SuiLocalTestValidator
86
- this._providerName = params.provider.providerName;
87
- this._provider = params.provider.provider;
88
- }
89
- // this._provider = new sui.JsonRpcProvider(sui.localnetConnection);
90
- // this._providerName = 'sui:localnet';
91
- } else if (params.provider == 'test' || params.provider == 'testnet') {
92
- this._provider = new SuiClient({url: getFullnodeUrl('testnet')});
93
- this._providerName = 'sui:testnet';
94
- } else if (params.provider == 'dev' || params.provider == 'devnet') {
95
- this._provider = new SuiClient({url: getFullnodeUrl('devnet')});
96
- this._providerName = 'sui:devnet';
97
- } else if (params.provider == 'main' || params.provider == 'mainnet') {
98
- this._provider = new SuiClient({url: getFullnodeUrl('mainnet')});
99
- this._providerName = 'sui:mainnet';
100
-
101
- this.log('we are on the mainnet, working with real money, be careful');
102
- } else {
103
- if (params.provider && params.provider.constructor && params.provider.constructor.name && params.provider.constructor.name == 'SuiClient') {
104
- this._provider = params.provider;
105
- const url = params.provider.transport.websocketClient.endpoint;
106
-
107
- if (url.indexOf('devnet') !== -1) {
108
- this._providerName = 'sui:devnet';
109
- } else if (url.indexOf('testnet') !== -1) {
110
- this._providerName = 'sui:testnet';
111
- } else if (url.indexOf('mainnet') !== -1) {
112
- this._providerName = 'sui:mainnet';
113
- } else if (url.indexOf('127.0.0.1') !== -1) {
114
- this._providerName = 'sui:localnet';
115
- } else {
116
- // just keep provider name as unique to fullnode URL to keep separate ObjectStorage instances
117
- this._providerName = url.split('//')[1];
118
- }
119
- } else if (params.provider && params.provider.connection && params.provider.connection.fullnode) {
120
- this._provider = params.provider;
121
-
122
- if (params.provider.connection.fullnode.indexOf('devnet') !== -1) {
123
- this._providerName = 'sui:devnet';
124
- } else if (params.provider.connection.fullnode.indexOf('testnet') !== -1) {
125
- this._providerName = 'sui:testnet';
126
- } else if (params.provider.connection.fullnode.indexOf('mainnet') !== -1) {
127
- this._providerName = 'sui:mainnet';
128
- } else if (params.provider.connection.fullnode.indexOf('127.0.0.1') !== -1) {
129
- this._providerName = 'sui:localnet';
130
- } else {
131
- // just keep provider name as unique to fullnode URL to keep separate ObjectStorage instances
132
- this._providerName = params.provider.connection.fullnode;
133
- }
134
- }
135
- }
136
- }
137
77
 
138
- if (!this._provider) {
139
- throw new Error('Can not do anything without provider. Set params.provider at least to `local`');
78
+ this._client = SuiUtils.normalizeClient(params.client);
79
+ this._providerName = this._client ? this._client.providerName : null;
80
+
81
+ if (!this._client) {
82
+ throw new Error('Can not do anything without SuiClient. Set params.client at least to `local`');
140
83
  }
141
84
 
142
85
  // we are differient single instances of object storage by provider name (so we can separate like devnet-testnet entities if needed)
@@ -155,6 +98,10 @@ class SuiMaster extends SuiCommonMethods {
155
98
  });
156
99
  }
157
100
 
101
+ get utils() {
102
+ return SuiUtils;
103
+ }
104
+
158
105
  get suiCoins() {
159
106
  return this._suiCoins;
160
107
  }
@@ -163,12 +110,12 @@ class SuiMaster extends SuiCommonMethods {
163
110
  return BigInt(MIST_PER_SUI);
164
111
  }
165
112
 
166
- get TransactionBlock() {
167
- return TransactionBlock;
113
+ get Transaction() {
114
+ return Transaction;
168
115
  }
169
116
 
170
- get Transactions() {
171
- return Transactions;
117
+ get Commands() {
118
+ return Commands;
172
119
  }
173
120
 
174
121
  /**
@@ -200,8 +147,8 @@ class SuiMaster extends SuiCommonMethods {
200
147
 
201
148
  static instancesCount = 0;
202
149
 
203
- get provider() {
204
- return this._provider;
150
+ get client() {
151
+ return this._client;
205
152
  }
206
153
 
207
154
  get connectedChain() {
@@ -237,9 +184,9 @@ class SuiMaster extends SuiCommonMethods {
237
184
  return suiPackage;
238
185
  }
239
186
 
240
- async getProvider() {
187
+ async getClient() {
241
188
  await this.initialize();
242
- return this._provider;
189
+ return this._client;
243
190
  }
244
191
 
245
192
  async initialize() {
@@ -253,7 +200,7 @@ class SuiMaster extends SuiCommonMethods {
253
200
 
254
201
  // this._keypair = sui.Ed25519Keypair.deriveKeypair(this._phrase);
255
202
  if (!this._signer && this._keypair) { // we may optionally go without signer, to work in read-only mode
256
- this._signer = this._keypair;//new sui.RawSigner(this._keypair, this._provider);
203
+ this._signer = this._keypair;//
257
204
  }
258
205
 
259
206
  // const publicKey = this._keypair.getPublicKey();
@@ -267,8 +214,6 @@ class SuiMaster extends SuiCommonMethods {
267
214
  this._address = await this._signer.getAddress(); // old method
268
215
  }
269
216
 
270
- // console.log(this._signer);
271
- // console.log(this._providerName);
272
217
  this.log('initialized. connected as', this._address);
273
218
  } else {
274
219
  this.log('initialized in read-only mode.');
@@ -278,22 +223,23 @@ class SuiMaster extends SuiCommonMethods {
278
223
  return true;
279
224
  }
280
225
 
281
- async signAndExecuteTransactionBlock(params) {
226
+ async signAndExecuteTransaction(params) {
282
227
  if (this._keypair) {
283
228
  params.signer = this._keypair;
284
- return this._provider.signAndExecuteTransactionBlock(params);
229
+ return this._client.signAndExecuteTransaction(params);
285
230
  } else if (this._signer) {
286
- return this._signer.signAndExecuteTransactionBlock(params);
231
+ return this._signer.signAndExecuteTransaction(params);
287
232
  }
288
233
  }
289
234
 
290
235
  async requestSuiFromFaucet() {
291
236
  await this.initialize();
292
237
  let amount = BigInt(0);
293
- const faucetHost = getFaucetHost(this._providerName.split('sui:').join(''));
294
- if (faucetHost === "mainnet") {
295
- this.log(`no faucet on ${faucetHost}`);
238
+ const provider = this._providerName.split('sui:').join('');
239
+ if (provider === "mainnet") {
240
+ this.log(`no faucet on ${provider}`);
296
241
  } else {
242
+ const faucetHost = getFaucetHost(provider);
297
243
  this.log(`requesting sui from faucet... ${faucetHost}`);
298
244
  const requested = await requestSuiFromFaucetV0({
299
245
  host: faucetHost,
@@ -418,11 +364,10 @@ class SuiMaster extends SuiCommonMethods {
418
364
 
419
365
  return paginatedResponse;
420
366
  }
421
-
422
367
  };
423
368
 
424
369
  SuiMaster.MIST_PER_SUI = BigInt(MIST_PER_SUI);
425
- SuiMaster.TransactionBlock = TransactionBlock;
426
- SuiMaster.Transactions = Transactions;
370
+ SuiMaster.Transaction = Transaction;
371
+ SuiMaster.Commands = Commands;
427
372
 
428
373
  module.exports = SuiMaster;
@@ -86,7 +86,7 @@ class SuiMemoryObjectStorage extends SuiCommonMethods {
86
86
  console.warn = (e)=>{
87
87
  consoleWarnMessage = e;
88
88
  };
89
- resultsSlice = await this._suiMaster._provider.multiGetObjects({
89
+ resultsSlice = await this._suiMaster._client.multiGetObjects({
90
90
  ids: objectIdsSlice,
91
91
  options: { showType: true, showContent: true, showOwner: true, showDisplay: true, },
92
92
  });