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 +39 -27
- package/dist/koinos.js +252 -200
- package/dist/koinos.min.js +1 -1
- package/lib/Contract.d.ts +28 -19
- package/lib/Contract.js +47 -52
- package/lib/Contract.js.map +1 -1
- package/lib/Provider.d.ts +7 -5
- package/lib/Provider.js +24 -15
- package/lib/Provider.js.map +1 -1
- package/lib/Serializer.d.ts +2 -1
- package/lib/Serializer.js +96 -89
- package/lib/Serializer.js.map +1 -1
- package/lib/Signer.d.ts +17 -5
- package/lib/Signer.js +15 -6
- package/lib/Signer.js.map +1 -1
- package/lib/browser/Contract.d.ts +28 -19
- package/lib/browser/Contract.js +47 -52
- package/lib/browser/Contract.js.map +1 -1
- package/lib/browser/Provider.d.ts +7 -5
- package/lib/browser/Provider.js +24 -15
- package/lib/browser/Provider.js.map +1 -1
- package/lib/browser/Serializer.d.ts +2 -1
- package/lib/browser/Serializer.js +96 -89
- package/lib/browser/Serializer.js.map +1 -1
- package/lib/browser/Signer.d.ts +17 -5
- package/lib/browser/Signer.js +15 -6
- package/lib/browser/Signer.js.map +1 -1
- package/lib/browser/interface.d.ts +45 -25
- package/lib/browser/jsonDescriptors/{krc20-proto.json → token-proto.json} +0 -0
- package/lib/browser/utils.d.ts +3 -3
- package/lib/browser/utils.js +69 -37
- package/lib/browser/utils.js.map +1 -1
- package/lib/interface.d.ts +45 -25
- package/lib/jsonDescriptors/{krc20-proto.json → token-proto.json} +0 -0
- package/lib/utils.d.ts +3 -3
- package/lib/utils.js +69 -37
- package/lib/utils.js.map +1 -1
- package/package.json +1 -1
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.
|
|
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.
|
|
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.
|
|
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),
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
-
|
|
224
|
-
|
|
225
|
-
|
|
234
|
+
entry_point: 0x27f576ca,
|
|
235
|
+
argument: "transfer_arguments",
|
|
236
|
+
return: "transfer_result",
|
|
226
237
|
},
|
|
227
238
|
mint: {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
239
|
+
entry_point: 0xdc6f17bb,
|
|
240
|
+
argument: "mint_argumnets",
|
|
241
|
+
return: "mint_result",
|
|
231
242
|
},
|
|
232
243
|
},
|
|
233
|
-
|
|
244
|
+
koilib_types: tokenJson,
|
|
234
245
|
};
|
|
235
246
|
```
|
|
236
247
|
|
|
237
|
-
Note that this example uses "
|
|
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
|
|
262
|
-
In particular,
|
|
263
|
-
|
|
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
|
|
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
|