koilib 3.0.0 → 4.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.
package/README.md CHANGED
@@ -37,7 +37,7 @@ You can also load it directly to the browser by downloading the bunble file loca
37
37
  signer.provider = provider;
38
38
  const koinContract = new Contract({
39
39
  id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
40
- abi: utils.Krc20Abi,
40
+ abi: utils.tokenAbi,
41
41
  provider,
42
42
  signer,
43
43
  });
@@ -92,28 +92,35 @@ a transaction, and read contracts.
92
92
  signer.provider = provider;
93
93
  const koinContract = new Contract({
94
94
  id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
95
- abi: utils.Krc20Abi,
95
+ abi: utils.tokenAbi,
96
96
  provider,
97
97
  signer,
98
98
  });
99
99
  const koin = koinContract.functions;
100
100
 
101
101
  // optional: preformat input/output
102
- koinContract.abi.methods.balanceOf.preformatInput = (owner) => ({ owner });
103
- koinContract.abi.methods.balanceOf.preformatOutput = (res) =>
102
+ koinContract.abi.methods.balanceOf.preformat_argument = (owner) => ({
103
+ owner,
104
+ });
105
+ koinContract.abi.methods.balanceOf.preformat_return = (res) =>
104
106
  utils.formatUnits(res.value, 8);
105
- koinContract.abi.methods.transfer.preformatInput = (input) => ({
107
+ koinContract.abi.methods.transfer.preformat_argument = (input) => ({
106
108
  from: signer.getAddress(),
107
109
  to: input.to,
108
110
  value: utils.parseUnits(input.value, 8),
109
111
  });
110
112
 
111
113
  // Transfer
112
- const { transaction } = await koin.transfer({
114
+ const { transaction, receipt } = await koin.transfer({
113
115
  to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
114
116
  value: "10.0001",
115
117
  });
116
- console.log(`Transaction id ${transaction.id} submitted`);
118
+ console.log(`Transaction id ${transaction.id} submitted. Receipt:`);
119
+ console.log(receipt);
120
+
121
+ if (receipt.logs) {
122
+ console.log(`Transfer failed. Logs: ${receipt.logs.join(",")}`);
123
+ }
117
124
 
118
125
  // wait to be mined
119
126
  const blockNumber = await transaction.wait();
@@ -139,7 +146,9 @@ It's also possible to upload contracts. First, follow the instructions in [koino
139
146
 
140
147
  // create contract and deploy
141
148
  const contract = new Contract({ signer, provider, bytecode });
142
- const { transaction } = await contract.deploy();
149
+ const { transaction, receipt } = await contract.deploy();
150
+ console.log("Transaction submitted. Receipt:");
151
+ console.log(receipt);
143
152
  // wait to be mined
144
153
  const blockNumber = await transaction.wait();
145
154
  console.log(`Contract uploaded in block number ${blockNumber}`);
@@ -161,7 +170,7 @@ You can also upload a contract in a new address. It is not required that this ne
161
170
 
162
171
  // create contract. Set newAccount as signer
163
172
  const contract = new Contract({
164
- signer: newAccount.address,
173
+ signer: newAccount,
165
174
  provider,
166
175
  bytecode,
167
176
  });
@@ -181,7 +190,9 @@ You can also upload a contract in a new address. It is not required that this ne
181
190
  // - signature of accountWithFunds
182
191
 
183
192
  // now broadcast the transaction to deploy
184
- transaction = await newAccount.sendTransaction(transaction);
193
+ const { receipt } = await newAccount.sendTransaction(transaction);
194
+ console.log("Transaction submitted. Receipt: ");
195
+ console.log(receipt);
185
196
  const blockNumber = await transaction.wait();
186
197
  console.log(`Contract uploaded in block number ${blockNumber}`);
187
198
  })();
@@ -213,28 +224,28 @@ const tokenJson = require("./token-proto.json");
213
224
  const abiToken = {
214
225
  methods: {
215
226
  balanceOf: {
216
- entryPoint: 0x5c721497,
217
- inputs: "balance_of_arguments",
218
- outputs: "balance_of_result",
219
- readOnly: true,
220
- defaultOutput: { value: "0" },
227
+ entry_point: 0x5c721497,
228
+ argument: "balance_of_arguments",
229
+ return: "balance_of_result",
230
+ read_only: true,
231
+ default_output: { value: "0" },
221
232
  },
222
233
  transfer: {
223
- entryPoint: 0x27f576ca,
224
- inputs: "transfer_arguments",
225
- outputs: "transfer_result",
234
+ entry_point: 0x27f576ca,
235
+ argument: "transfer_arguments",
236
+ return: "transfer_result",
226
237
  },
227
238
  mint: {
228
- entryPoint: 0xdc6f17bb,
229
- inputs: "mint_argumnets",
230
- outputs: "mint_result",
239
+ entry_point: 0xdc6f17bb,
240
+ argument: "mint_argumnets",
241
+ return: "mint_result",
231
242
  },
232
243
  },
233
- types: tokenJson,
244
+ koilib_types: tokenJson,
234
245
  };
235
246
  ```
236
247
 
237
- Note that this example uses "defaultOutput" for the method
248
+ Note that this example uses "default_output" for the method
238
249
  "balanceOf". This is used when the smart contract returns an
239
250
  empty response (for instance when there are no balance records
240
251
  for a specific address) and you require a default output in
@@ -258,13 +269,14 @@ such cases.
258
269
  For the ABI you need the .proto file and the library
259
270
  [protobufjs](https://www.npmjs.com/package/protobufjs). Then follow the format
260
271
  for the ABI as described in the previous section. It's important to note that
261
- this ABI is not the same ABI used in [koinos-cli](https://docs.koinos.io/architecture/contract-abi.html).
262
- In particular, descriptors use different format (koilib using json format, cli
263
- using binary format).
272
+ this ABI has a diffence with respect to the ABI used in [koinos-cli](https://docs.koinos.io/architecture/contract-abi.html).
273
+ In particular, koilib takes the descriptor from `koilib_types`, which is a
274
+ descriptor in json format, while the ABI in koinos-cli takes the descriptor from
275
+ `types`, which is a descriptor in binary format.
264
276
 
265
277
  4. Can this library be used to interact with smart contracts?
266
278
 
267
- Yes. You can use it to call readOnly functions, or send transactions
279
+ Yes. You can use it to call read_only functions, or send transactions
268
280
  to the contract by calling write functions.
269
281
 
270
282
  ## Documentation