koilib 2.0.0 → 2.4.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 +49 -7
- package/dist/koinos.js +4910 -4762
- package/dist/koinos.min.js +1 -1
- package/dist/koinos.min.js.LICENSE.txt +1 -10
- package/lib/Contract.d.ts +48 -140
- package/lib/Contract.js +82 -156
- package/lib/Contract.js.map +1 -1
- package/lib/Provider.d.ts +2 -5
- package/lib/Provider.js +42 -11
- package/lib/Provider.js.map +1 -1
- package/lib/Serializer.d.ts +81 -0
- package/lib/Serializer.js +169 -0
- package/lib/Serializer.js.map +1 -0
- package/lib/Signer.d.ts +130 -24
- package/lib/Signer.js +162 -59
- package/lib/Signer.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/index2.js +2 -0
- package/lib/index2.js.map +1 -1
- package/lib/interface.d.ts +161 -24
- package/lib/{krc20-proto.json → jsonDescriptors/krc20-proto.json} +1 -1
- package/lib/{protocol-proto.json → jsonDescriptors/protocol-proto.json} +22 -18
- package/lib/utils.d.ts +270 -2
- package/lib/utils.js +72 -34
- package/lib/utils.js.map +1 -1
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -60,13 +60,13 @@ You can also load it directly to the browser by downloading the bunble file loca
|
|
|
60
60
|
With Typescript import the library
|
|
61
61
|
|
|
62
62
|
```typescript
|
|
63
|
-
import { Signer, Contract, Provider, utils } from "koilib";
|
|
63
|
+
import { Signer, Contract, Provider, Serializer, utils } from "koilib";
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
With Javascript import the library with require
|
|
67
67
|
|
|
68
68
|
```javascript
|
|
69
|
-
const { Signer, Contract, Provider, utils } = require("koilib");
|
|
69
|
+
const { Signer, Contract, Provider, Serializer, utils } = require("koilib");
|
|
70
70
|
```
|
|
71
71
|
|
|
72
72
|
There are 4 principal classes:
|
|
@@ -74,6 +74,8 @@ There are 4 principal classes:
|
|
|
74
74
|
- **Signer**: Class containing the private key. It is used to sign.
|
|
75
75
|
- **Provider**: Class to connect with the RPC node.
|
|
76
76
|
- **Contract**: Class defining the contract to interact with.
|
|
77
|
+
- **Serializer**: Class with the protocol buffers definitions to
|
|
78
|
+
serialize/deserialize data types.
|
|
77
79
|
|
|
78
80
|
The following code shows how to sign a transaction, broadcast
|
|
79
81
|
a transaction, and read contracts.
|
|
@@ -92,11 +94,20 @@ a transaction, and read contracts.
|
|
|
92
94
|
});
|
|
93
95
|
const koin = koinContract.functions;
|
|
94
96
|
|
|
97
|
+
// optional: preformat input/output
|
|
98
|
+
koinContract.abi.methods.balanceOf.preformatInput = (owner) => ({ owner });
|
|
99
|
+
koinContract.abi.methods.balanceOf.preformatOutput = (res) =>
|
|
100
|
+
utils.formatUnits(res.value, 8);
|
|
101
|
+
koinContract.abi.methods.transfer.preformatInput = (input) => ({
|
|
102
|
+
from: signer.getAddress(),
|
|
103
|
+
to: input.to,
|
|
104
|
+
value: utils.parseUnits(input.value, 8),
|
|
105
|
+
});
|
|
106
|
+
|
|
95
107
|
// Transfer
|
|
96
108
|
const { transaction, transactionResponse } = await koin.transfer({
|
|
97
|
-
from: signer.getAddress(),
|
|
98
109
|
to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
|
|
99
|
-
value: "
|
|
110
|
+
value: "10.0001",
|
|
100
111
|
});
|
|
101
112
|
console.log(`Transaction id ${transaction.id} submitted`);
|
|
102
113
|
|
|
@@ -105,9 +116,7 @@ a transaction, and read contracts.
|
|
|
105
116
|
console.log(`Transaction mined. Block id: ${blockId}`);
|
|
106
117
|
|
|
107
118
|
// read the balance
|
|
108
|
-
const { result } = await koin.balanceOf(
|
|
109
|
-
owner: signer.getAddress(),
|
|
110
|
-
});
|
|
119
|
+
const { result } = await koin.balanceOf(signer.getAddress());
|
|
111
120
|
console.log(balance.result);
|
|
112
121
|
})();
|
|
113
122
|
```
|
|
@@ -161,6 +170,7 @@ const abiToken = {
|
|
|
161
170
|
inputs: "balance_of_arguments",
|
|
162
171
|
outputs: "balance_of_result",
|
|
163
172
|
readOnly: true,
|
|
173
|
+
defaultOutput: { value: "0" },
|
|
164
174
|
},
|
|
165
175
|
transfer: {
|
|
166
176
|
entryPoint: 0x62efa292,
|
|
@@ -177,6 +187,38 @@ const abiToken = {
|
|
|
177
187
|
};
|
|
178
188
|
```
|
|
179
189
|
|
|
190
|
+
Note that this example uses "defaultOutput" for the method
|
|
191
|
+
"balanceOf". This is used when the smart contract returns an
|
|
192
|
+
empty response (for instance when there are no balance records
|
|
193
|
+
for a specific address) and you require a default output in
|
|
194
|
+
such cases.
|
|
195
|
+
|
|
196
|
+
## FAQ
|
|
197
|
+
|
|
198
|
+
1. Can this library be used to create smart contracts?
|
|
199
|
+
|
|
200
|
+
No. You need to install [koinos-cdt](https://github.com/koinos/koinos-cdt) for
|
|
201
|
+
this purpose.
|
|
202
|
+
|
|
203
|
+
2. Can this library be used to deploy smart contracts?
|
|
204
|
+
|
|
205
|
+
Yes. If you already have the contract compiled as a .wasm file you can use
|
|
206
|
+
the Contract class to load the bytecode and deploy it.
|
|
207
|
+
|
|
208
|
+
3. Can this library be used to create the ABI for any smart contract?
|
|
209
|
+
|
|
210
|
+
For the ABI you need the .proto file and the library
|
|
211
|
+
[protobufjs](https://www.npmjs.com/package/protobufjs). Then follow the format
|
|
212
|
+
for the ABI as described in the previous section. It's important to note that
|
|
213
|
+
this ABI is not the same ABI used in [koinos-cli](https://docs.koinos.io/architecture/contract-abi.html).
|
|
214
|
+
In particular, descriptors use different format (koilib using json format, cli
|
|
215
|
+
using binary format).
|
|
216
|
+
|
|
217
|
+
4. Can this library be used to interact with smart contracts?
|
|
218
|
+
|
|
219
|
+
Yes. You can use it to call readOnly functions, or send transactions
|
|
220
|
+
to the contract by calling write functions.
|
|
221
|
+
|
|
180
222
|
## Documentation
|
|
181
223
|
|
|
182
224
|
The complete documentation can be found at https://joticajulian.github.io/koilib/
|