koilib 3.1.0 → 4.1.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 +24 -21
- package/dist/koinos.js +3416 -3406
- package/dist/koinos.min.js +1 -1
- package/lib/Contract.d.ts +8 -8
- package/lib/Contract.js +38 -42
- package/lib/Contract.js.map +1 -1
- package/lib/Signer.d.ts +8 -2
- package/lib/Signer.js +12 -3
- package/lib/Signer.js.map +1 -1
- package/lib/browser/Contract.d.ts +8 -8
- package/lib/browser/Contract.js +38 -42
- package/lib/browser/Contract.js.map +1 -1
- package/lib/browser/Signer.d.ts +8 -2
- package/lib/browser/Signer.js +12 -3
- package/lib/browser/Signer.js.map +1 -1
- package/lib/browser/interface.d.ts +24 -24
- package/lib/browser/utils.js +33 -28
- package/lib/browser/utils.js.map +1 -1
- package/lib/interface.d.ts +24 -24
- package/lib/utils.js +33 -28
- package/lib/utils.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -99,10 +99,12 @@ a transaction, and read contracts.
|
|
|
99
99
|
const koin = koinContract.functions;
|
|
100
100
|
|
|
101
101
|
// optional: preformat input/output
|
|
102
|
-
koinContract.abi.methods.balanceOf.
|
|
103
|
-
|
|
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.
|
|
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),
|
|
@@ -168,7 +170,7 @@ You can also upload a contract in a new address. It is not required that this ne
|
|
|
168
170
|
|
|
169
171
|
// create contract. Set newAccount as signer
|
|
170
172
|
const contract = new Contract({
|
|
171
|
-
signer: newAccount
|
|
173
|
+
signer: newAccount,
|
|
172
174
|
provider,
|
|
173
175
|
bytecode,
|
|
174
176
|
});
|
|
@@ -222,28 +224,28 @@ const tokenJson = require("./token-proto.json");
|
|
|
222
224
|
const abiToken = {
|
|
223
225
|
methods: {
|
|
224
226
|
balanceOf: {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
227
|
+
entry_point: 0x5c721497,
|
|
228
|
+
argument: "balance_of_arguments",
|
|
229
|
+
return: "balance_of_result",
|
|
230
|
+
read_only: true,
|
|
231
|
+
default_output: { value: "0" },
|
|
230
232
|
},
|
|
231
233
|
transfer: {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
234
|
+
entry_point: 0x27f576ca,
|
|
235
|
+
argument: "transfer_arguments",
|
|
236
|
+
return: "transfer_result",
|
|
235
237
|
},
|
|
236
238
|
mint: {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
239
|
+
entry_point: 0xdc6f17bb,
|
|
240
|
+
argument: "mint_argumnets",
|
|
241
|
+
return: "mint_result",
|
|
240
242
|
},
|
|
241
243
|
},
|
|
242
|
-
|
|
244
|
+
koilib_types: tokenJson,
|
|
243
245
|
};
|
|
244
246
|
```
|
|
245
247
|
|
|
246
|
-
Note that this example uses "
|
|
248
|
+
Note that this example uses "default_output" for the method
|
|
247
249
|
"balanceOf". This is used when the smart contract returns an
|
|
248
250
|
empty response (for instance when there are no balance records
|
|
249
251
|
for a specific address) and you require a default output in
|
|
@@ -267,13 +269,14 @@ such cases.
|
|
|
267
269
|
For the ABI you need the .proto file and the library
|
|
268
270
|
[protobufjs](https://www.npmjs.com/package/protobufjs). Then follow the format
|
|
269
271
|
for the ABI as described in the previous section. It's important to note that
|
|
270
|
-
this ABI
|
|
271
|
-
In particular,
|
|
272
|
-
|
|
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.
|
|
273
276
|
|
|
274
277
|
4. Can this library be used to interact with smart contracts?
|
|
275
278
|
|
|
276
|
-
Yes. You can use it to call
|
|
279
|
+
Yes. You can use it to call read_only functions, or send transactions
|
|
277
280
|
to the contract by calling write functions.
|
|
278
281
|
|
|
279
282
|
## Documentation
|