koilib 6.0.0 → 7.1.1

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.
Files changed (45) hide show
  1. package/README.md +39 -40
  2. package/dist/koinos.js +1675 -84
  3. package/dist/koinos.min.js +1 -1
  4. package/lib/Contract.d.ts +12 -24
  5. package/lib/Contract.js +11 -23
  6. package/lib/Contract.js.map +1 -1
  7. package/lib/Provider.d.ts +257 -12
  8. package/lib/Provider.js +288 -10
  9. package/lib/Provider.js.map +1 -1
  10. package/lib/Signer.d.ts +75 -6
  11. package/lib/Signer.js +87 -6
  12. package/lib/Signer.js.map +1 -1
  13. package/lib/Transaction.d.ts +4 -3
  14. package/lib/Transaction.js +13 -10
  15. package/lib/Transaction.js.map +1 -1
  16. package/lib/browser/Contract.d.ts +12 -24
  17. package/lib/browser/Contract.js +11 -23
  18. package/lib/browser/Contract.js.map +1 -1
  19. package/lib/browser/Provider.d.ts +257 -12
  20. package/lib/browser/Provider.js +288 -10
  21. package/lib/browser/Provider.js.map +1 -1
  22. package/lib/browser/Signer.d.ts +75 -6
  23. package/lib/browser/Signer.js +87 -6
  24. package/lib/browser/Signer.js.map +1 -1
  25. package/lib/browser/Transaction.d.ts +4 -3
  26. package/lib/browser/Transaction.js +13 -10
  27. package/lib/browser/Transaction.js.map +1 -1
  28. package/lib/browser/interface.d.ts +34 -0
  29. package/lib/browser/utils.d.ts +39 -0
  30. package/lib/browser/utils.js +1276 -27
  31. package/lib/browser/utils.js.map +1 -1
  32. package/lib/interface.d.ts +34 -0
  33. package/lib/utils.d.ts +39 -0
  34. package/lib/utils.js +1276 -27
  35. package/lib/utils.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/Contract.ts +12 -24
  38. package/src/Provider.ts +303 -24
  39. package/src/Signer.ts +126 -7
  40. package/src/Transaction.ts +17 -16
  41. package/src/interface.ts +39 -0
  42. package/src/utils.ts +1283 -23
  43. package/lib/browser/jsonDescriptors/token-proto.json +0 -234
  44. package/lib/jsonDescriptors/token-proto.json +0 -234
  45. package/src/jsonDescriptors/token-proto.json +0 -234
package/README.md CHANGED
@@ -33,11 +33,11 @@ You can also load it directly to the browser by downloading the bunble file loca
33
33
  <script src="koinos.min.js"></script>
34
34
  <script>
35
35
  (async () => {
36
- const provider = new Provider(["http://api.koinos.io:8080"]);
37
- const signer = Signer.fromSeed("my seed");
36
+ const provider = new Provider(["http://api.koinos.io"]);
37
+ const signer = Signer.fromWif("Kzl...");
38
38
  signer.provider = provider;
39
39
  const koinContract = new Contract({
40
- id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
40
+ id: "15DJN4a8SgrbGhhGksSBASiSYjGnMU8dGL",
41
41
  abi: utils.tokenAbi,
42
42
  provider,
43
43
  signer,
@@ -103,60 +103,54 @@ a transaction, and read contracts.
103
103
  ```typescript
104
104
  (async () => {
105
105
  // define signer, provider, and contract
106
- const provider = new Provider(["http://api.koinos.io:8080"]);
107
- const signer = Signer.fromSeed("my seed");
106
+ const provider = new Provider(["http://api.koinos.io"]);
107
+ const signer = Signer.fromWif("KwkAq...");
108
108
  signer.provider = provider;
109
109
  const koinContract = new Contract({
110
- id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
110
+ id: "15DJN4a8SgrbGhhGksSBASiSYjGnMU8dGL",
111
111
  abi: utils.tokenAbi,
112
112
  provider,
113
113
  signer,
114
114
  });
115
115
  const koin = koinContract.functions;
116
116
 
117
- // optional: preformat input/output
118
- koinContract.abi.methods.balanceOf.preformat_argument = (owner) => ({
119
- owner,
120
- });
121
- koinContract.abi.methods.balanceOf.preformat_return = (res) =>
122
- utils.formatUnits(res.value, 8);
123
- koinContract.abi.methods.transfer.preformat_argument = (input) => ({
124
- from: signer.getAddress(),
125
- to: input.to,
126
- value: utils.parseUnits(input.value, 8),
127
- });
128
-
129
117
  // Transfer
130
118
  const { transaction, receipt } = await koin.transfer({
119
+ from: signer.getAddress(),
131
120
  to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
132
- value: "10.0001",
121
+ value: "1012345678", // 10.12345678 koin
133
122
  });
134
123
  console.log(`Transaction id ${transaction.id} submitted. Receipt:`);
135
124
  console.log(receipt);
136
125
 
137
- if (receipt.logs) {
138
- console.log(`Transfer failed. Logs: ${receipt.logs.join(",")}`);
139
- }
140
-
141
126
  // wait to be mined
142
127
  const { blockNumber } = await transaction.wait();
143
128
  console.log(`Transaction mined. Block number: ${blockNumber}`);
144
129
 
145
130
  // read the balance
146
- const { result } = await koin.balanceOf(signer.getAddress());
131
+ const { result } = await koin.balanceOf({
132
+ owner: signer.getAddress(),
133
+ });
147
134
  console.log(result);
148
135
  })();
149
136
  ```
150
137
 
151
138
  #### Upload contract
152
139
 
153
- It's also possible to upload contracts. First, follow the instructions in [koinos-sdk](https://github.com/koinos/koinos-sdk-cpp) (for C++ developers) or [koinos-as-sdk-examples](https://github.com/roaminroe/koinos-as-sdk-examples) (for TypeScript developers) to compile the contracts as wasm files. Then you can use koilib to deploy them.
140
+ It's also possible to upload contracts using koilib. You need the wasm file for that. There are several tools that can help you to develop smart contracts on Koinos:
141
+
142
+ - [Arkinos](https://www.npmjs.com/package/arkinos): Complete tool to develop contracts in Assembly Script and bootstrap a website to interact with them.
143
+ - [koinos/sdk-as-cli](https://www.npmjs.com/@koinos/sdk-as-cli): SDK to develop contracts in Assembly Script.
144
+ - [koinos-sdk-cpp](https://github.com/koinos/koinos-sdk-cpp): SDK to develop contracts in C++.
145
+ - [koinosbox/contracts](https://github.com/joticajulian/koinos-contracts-as/tree/main/contracts): Contract examples created in Assembly Script. You can also import them in your project by using the [npm package](https://www.npmjs.com/package/@koinosbox/contracts).
146
+
147
+ Here is an example on how deploy a contract:
154
148
 
155
149
  ```typescript
156
150
  (async () => {
157
151
  // define signer, provider and bytecode
158
- const provider = new Provider(["http://api.koinos.io:8080"]);
159
- const signer = Signer.fromSeed("my seed");
152
+ const provider = new Provider(["http://api.koinos.io"]);
153
+ const signer = Signer.fromWif("KwkAq...");
160
154
  signer.provider = provider;
161
155
  const bytecode = fs.readFileSync("my_contract.wasm");
162
156
 
@@ -176,9 +170,9 @@ You can also upload a contract in a new address. It is not required that this ne
176
170
  ```typescript
177
171
  (async () => {
178
172
  // define signer, provider and bytecode
179
- const provider = new Provider(["http://api.koinos.io:8080"]);
180
- const accountWithFunds = Signer.fromSeed("this account has funds");
181
- const newAccount = Signer.fromSeed("new account without funds");
173
+ const provider = new Provider(["http://api.koinos.io"]);
174
+ const accountWithFunds = Signer.fromWif("K... this account has funds");
175
+ const newAccount = Signer.fromWif("L... new account without funds");
182
176
  accountWithFunds.provider = provider;
183
177
  newAccount.provider = provider;
184
178
 
@@ -219,9 +213,9 @@ In fact, there are several ways to set a different payer and use it to upload a
219
213
  ```typescript
220
214
  (async () => {
221
215
  // define signer, provider and bytecode
222
- const provider = new Provider(["http://api.koinos.io:8080"]);
223
- const accountWithFunds = Signer.fromSeed("this account has funds");
224
- const newAccount = Signer.fromSeed("new account without funds");
216
+ const provider = new Provider(["http://api.koinos.io"]);
217
+ const accountWithFunds = Signer.fromWif("K... this account has funds");
218
+ const newAccount = Signer.fromWif("L... new account without funds");
225
219
  accountWithFunds.provider = provider;
226
220
  newAccount.provider = provider;
227
221
 
@@ -262,8 +256,8 @@ In fact, there are several ways to set a different payer and use it to upload a
262
256
  It can be configured to sign a single transaction with multiple accounts. Here is an example:
263
257
 
264
258
  ```ts
265
- const signer2 = Signer.fromSeed("signer2");
266
- const signer3 = Signer.fromSeed("signer3");
259
+ const signer2 = Signer.fromWif("KzP1...");
260
+ const signer3 = Signer.fromWif("L1t...");
267
261
 
268
262
  const addMoreSignatures = async (tx) => {
269
263
  await signer2.signTransaction(tx);
@@ -399,9 +393,7 @@ const abiToken = {
399
393
 
400
394
  1. Can this library be used to create smart contracts?
401
395
 
402
- No. You need to install [koinos-sdk](https://github.com/koinos/koinos-sdk-cpp)
403
- (for C++ developers) or [koinos-as-sdk-examples](https://github.com/roaminroe/koinos-as-sdk-examples)
404
- (for TypeScript developers) for this purpose.
396
+ No. There are another tools for that. Like [Arkinos](https://www.npmjs.com/package/arkinos) or [koinos/sdk-as-cli](https://www.npmjs.com/@koinos/sdk-as-cli) for Assembly Script, or [koinos-sdk](https://github.com/koinos/koinos-sdk-cpp) for C++.
405
397
 
406
398
  2. Can this library be used to deploy smart contracts?
407
399
 
@@ -413,16 +405,21 @@ const abiToken = {
413
405
  For the ABI you need the .proto file and the library
414
406
  [protobufjs](https://www.npmjs.com/package/protobufjs). Then follow the format
415
407
  for the ABI as described in the previous section. It's important to note that
416
- this ABI has a difference with respect to the ABI used in [koinos-cli](https://docs.koinos.io/architecture/contract-abi.html).
408
+ this ABI has some differences with respect to the ABI used in [koinos-cli](https://docs.koinos.io/architecture/contract-abi).
417
409
  In particular, koilib takes the descriptor from `koilib_types`, which is a
418
410
  descriptor in json format, while the ABI in koinos-cli takes the descriptor from
419
- `types`, which is a descriptor in binary format.
411
+ `types`, which is a descriptor in binary format. There are also some differences
412
+ in the format of "entry point" and "read only".
420
413
 
421
414
  4. Can this library be used to interact with smart contracts?
422
415
 
423
416
  Yes. You can use it to call read_only functions, or send transactions
424
417
  to the contract by calling write functions.
425
418
 
419
+ 5. How to generate random keys?
420
+
421
+ To generate random mnemonic phrases and private keys use [@koinosbox/hdKoinos](https://www.npmjs.com/package/@koinosbox/hdkoinos).
422
+
426
423
  ## Documentation
427
424
 
428
425
  The complete documentation can be found at https://joticajulian.github.io/koilib/
@@ -433,6 +430,8 @@ Many thanks to the sponsors of this library: @levineam, @Amikob, @motoeng, @isaa
433
430
 
434
431
  If you would like to contribute to the development of this library consider becoming a sponsor in https://github.com/sponsors/joticajulian.
435
432
 
433
+ You can also send a donation to the koinos nickname [@julian.donation](https://koinosbox.com/nicknames/@julian.donation).
434
+
436
435
  ## License
437
436
 
438
437
  MIT License