koilib 2.6.1 → 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.
Files changed (66) hide show
  1. package/README.md +66 -12
  2. package/dist/koinos.js +8533 -274
  3. package/dist/koinos.min.js +1 -1
  4. package/lib/Contract.d.ts +53 -16
  5. package/lib/Contract.js +99 -31
  6. package/lib/Contract.js.map +1 -1
  7. package/lib/Provider.d.ts +39 -19
  8. package/lib/Provider.js +119 -87
  9. package/lib/Provider.js.map +1 -1
  10. package/lib/Serializer.d.ts +8 -3
  11. package/lib/Serializer.js +60 -41
  12. package/lib/Serializer.js.map +1 -1
  13. package/lib/Signer.d.ts +53 -39
  14. package/lib/Signer.js +320 -91
  15. package/lib/Signer.js.map +1 -1
  16. package/lib/browser/Contract.d.ts +53 -16
  17. package/lib/browser/Contract.js +99 -31
  18. package/lib/browser/Contract.js.map +1 -1
  19. package/lib/browser/Provider.d.ts +39 -19
  20. package/lib/browser/Provider.js +119 -87
  21. package/lib/browser/Provider.js.map +1 -1
  22. package/lib/browser/Serializer.d.ts +8 -3
  23. package/lib/browser/Serializer.js +60 -41
  24. package/lib/browser/Serializer.js.map +1 -1
  25. package/lib/browser/Signer.d.ts +53 -39
  26. package/lib/browser/Signer.js +320 -91
  27. package/lib/browser/Signer.js.map +1 -1
  28. package/lib/browser/index.d.ts +1 -1
  29. package/lib/browser/index.js +1 -1
  30. package/lib/browser/index.js.map +1 -1
  31. package/lib/browser/indexUtils.d.ts +2 -0
  32. package/lib/browser/indexUtils.js +15 -0
  33. package/lib/browser/indexUtils.js.map +1 -0
  34. package/lib/browser/interface.d.ts +242 -65
  35. package/lib/browser/jsonDescriptors/chain-proto.json +676 -0
  36. package/lib/browser/jsonDescriptors/krc20-proto.json +47 -4
  37. package/lib/browser/protoModules/protocol-proto.d.ts +2 -0
  38. package/lib/browser/protoModules/protocol-proto.js +6336 -0
  39. package/lib/browser/protoModules/protocol-proto.js.map +1 -0
  40. package/lib/browser/utils.d.ts +18 -254
  41. package/lib/browser/utils.js +140 -12
  42. package/lib/browser/utils.js.map +1 -1
  43. package/lib/browser/utilsNode.d.ts +1021 -0
  44. package/lib/browser/utilsNode.js +346 -0
  45. package/lib/browser/utilsNode.js.map +1 -0
  46. package/lib/index.d.ts +1 -1
  47. package/lib/index.js +1 -1
  48. package/lib/index.js.map +1 -1
  49. package/lib/indexUtils.d.ts +2 -0
  50. package/lib/indexUtils.js +15 -0
  51. package/lib/indexUtils.js.map +1 -0
  52. package/lib/interface.d.ts +242 -65
  53. package/lib/jsonDescriptors/chain-proto.json +676 -0
  54. package/lib/jsonDescriptors/krc20-proto.json +47 -4
  55. package/lib/protoModules/protocol-proto.d.ts +2 -0
  56. package/lib/protoModules/protocol-proto.js +6336 -0
  57. package/lib/protoModules/protocol-proto.js.map +1 -0
  58. package/lib/utils.d.ts +18 -254
  59. package/lib/utils.js +140 -12
  60. package/lib/utils.js.map +1 -1
  61. package/lib/utilsNode.d.ts +1021 -0
  62. package/lib/utilsNode.js +346 -0
  63. package/lib/utilsNode.js.map +1 -0
  64. package/package.json +1 -1
  65. package/lib/browser/jsonDescriptors/protocol-proto.json +0 -246
  66. package/lib/jsonDescriptors/protocol-proto.json +0 -246
package/README.md CHANGED
@@ -77,6 +77,10 @@ There are 4 principal classes:
77
77
  - **Serializer**: Class with the protocol buffers definitions to
78
78
  serialize/deserialize data types.
79
79
 
80
+ ### Examples
81
+
82
+ #### Send tokens, get balance
83
+
80
84
  The following code shows how to sign a transaction, broadcast
81
85
  a transaction, and read contracts.
82
86
 
@@ -105,23 +109,25 @@ a transaction, and read contracts.
105
109
  });
106
110
 
107
111
  // Transfer
108
- const { transaction, transactionResponse } = await koin.transfer({
112
+ const { transaction } = await koin.transfer({
109
113
  to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
110
114
  value: "10.0001",
111
115
  });
112
116
  console.log(`Transaction id ${transaction.id} submitted`);
113
117
 
114
118
  // wait to be mined
115
- const blockNumber = await transactionResponse.wait();
119
+ const blockNumber = await transaction.wait();
116
120
  console.log(`Transaction mined. Block number: ${blockNumber}`);
117
121
 
118
122
  // read the balance
119
123
  const { result } = await koin.balanceOf(signer.getAddress());
120
- console.log(balance.result);
124
+ console.log(result);
121
125
  })();
122
126
  ```
123
127
 
124
- It's also possible to upload contracts. First, follow the instructions in [koinos-cdt](https://github.com/koinos/koinos-cdt) to compile the contracts as wasm files. Then you can use koilib to deploy them.
128
+ #### Upload contract
129
+
130
+ 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.
125
131
 
126
132
  ```typescript
127
133
  (async () => {
@@ -133,10 +139,51 @@ It's also possible to upload contracts. First, follow the instructions in [koino
133
139
 
134
140
  // create contract and deploy
135
141
  const contract = new Contract({ signer, provider, bytecode });
136
- const { transactionResponse } = await contract.deploy();
142
+ const { transaction } = await contract.deploy();
137
143
  // wait to be mined
138
- const blockNumber = await transactionResponse.wait();
139
- console.log(`Contract uploaded in block id ${blockNumber}`);
144
+ const blockNumber = await transaction.wait();
145
+ console.log(`Contract uploaded in block number ${blockNumber}`);
146
+ })();
147
+ ```
148
+
149
+ You can also upload a contract in a new address. It is not required that this new address has funds, you just have to set your principal wallet as payer.
150
+
151
+ ```typescript
152
+ (async () => {
153
+ // define signer, provider and bytecode
154
+ const provider = new Provider(["http://api.koinos.io:8080"]);
155
+ const accountWithFunds = Signer.fromSeed("this account has funds");
156
+ const newAccount = Signer.fromSeed("new account without funds");
157
+ accountWithFunds.provider = provider;
158
+ newAccount.provider = provider;
159
+
160
+ const bytecode = fs.readFileSync("my_contract.wasm");
161
+
162
+ // create contract. Set newAccount as signer
163
+ const contract = new Contract({
164
+ signer: newAccount.address,
165
+ provider,
166
+ bytecode,
167
+ });
168
+
169
+ // call deploy but do not broadcast the transaction.
170
+ // Also set the payer
171
+ const { transaction } = await contract.deploy({
172
+ payer: accountWithFunds.address,
173
+ sendTransaction: false,
174
+ });
175
+
176
+ // sign the transaction with the payer
177
+ await accountWithFunds.signTransaction(transaction);
178
+
179
+ // at this point the transaction will have 2 signatures:
180
+ // - signature of newAccount
181
+ // - signature of accountWithFunds
182
+
183
+ // now broadcast the transaction to deploy
184
+ transaction = await newAccount.sendTransaction(transaction);
185
+ const blockNumber = await transaction.wait();
186
+ console.log(`Contract uploaded in block number ${blockNumber}`);
140
187
  })();
141
188
  ```
142
189
 
@@ -166,19 +213,19 @@ const tokenJson = require("./token-proto.json");
166
213
  const abiToken = {
167
214
  methods: {
168
215
  balanceOf: {
169
- entryPoint: 0x15619248,
216
+ entryPoint: 0x5c721497,
170
217
  inputs: "balance_of_arguments",
171
218
  outputs: "balance_of_result",
172
219
  readOnly: true,
173
220
  defaultOutput: { value: "0" },
174
221
  },
175
222
  transfer: {
176
- entryPoint: 0x62efa292,
223
+ entryPoint: 0x27f576ca,
177
224
  inputs: "transfer_arguments",
178
225
  outputs: "transfer_result",
179
226
  },
180
227
  mint: {
181
- entryPoint: 0xc2f82bdc,
228
+ entryPoint: 0xdc6f17bb,
182
229
  inputs: "mint_argumnets",
183
230
  outputs: "mint_result",
184
231
  },
@@ -197,8 +244,9 @@ such cases.
197
244
 
198
245
  1. Can this library be used to create smart contracts?
199
246
 
200
- No. You need to install [koinos-cdt](https://github.com/koinos/koinos-cdt) for
201
- this purpose.
247
+ No. You need to install [koinos-sdk](https://github.com/koinos/koinos-sdk-cpp)
248
+ (for C++ developers) or [koinos-as-sdk-examples](https://github.com/roaminroe/koinos-as-sdk-examples)
249
+ (for TypeScript developers) for this purpose.
202
250
 
203
251
  2. Can this library be used to deploy smart contracts?
204
252
 
@@ -223,6 +271,12 @@ such cases.
223
271
 
224
272
  The complete documentation can be found at https://joticajulian.github.io/koilib/
225
273
 
274
+ ## Acknowledgments
275
+
276
+ Many thanks to the sponsors of this library: @levineam, @Amikob, @motoeng, @isaacdozier, @imjwalker, and the private sponsors.
277
+
278
+ If you would like to contribute to the development of this library consider becoming a sponsor in https://github.com/sponsors/joticajulian.
279
+
226
280
  ## License
227
281
 
228
282
  MIT License