koilib 2.1.0 → 2.4.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.
- package/README.md +17 -8
- package/dist/koinos.js +5849 -5744
- package/dist/koinos.min.js +1 -1
- package/dist/koinos.min.js.LICENSE.txt +1 -10
- package/lib/Contract.d.ts +48 -149
- 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 +250 -2
- package/lib/utils.js +29 -34
- package/lib/utils.js.map +1 -1
- package/package.json +7 -9
package/README.md
CHANGED
|
@@ -60,20 +60,22 @@ 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
|
-
There are
|
|
72
|
+
There are 4 principal classes:
|
|
73
73
|
|
|
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
|
```
|