koilib 2.2.0 → 2.5.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
@@ -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 3 principal classes:
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: "1000",
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
  ```