koilib 4.1.2 → 5.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 +74 -11
- package/dist/koinos.js +1099 -543
- package/dist/koinos.min.js +1 -1
- package/lib/Contract.d.ts +2 -0
- package/lib/Contract.js +36 -30
- package/lib/Contract.js.map +1 -1
- package/lib/Provider.d.ts +17 -5
- package/lib/Provider.js +33 -14
- package/lib/Provider.js.map +1 -1
- package/lib/Serializer.js +2 -0
- package/lib/Serializer.js.map +1 -1
- package/lib/Signer.d.ts +14 -9
- package/lib/Signer.js +23 -10
- package/lib/Signer.js.map +1 -1
- package/lib/browser/Contract.d.ts +2 -0
- package/lib/browser/Contract.js +36 -30
- package/lib/browser/Contract.js.map +1 -1
- package/lib/browser/Provider.d.ts +17 -5
- package/lib/browser/Provider.js +33 -14
- package/lib/browser/Provider.js.map +1 -1
- package/lib/browser/Serializer.js +2 -0
- package/lib/browser/Serializer.js.map +1 -1
- package/lib/browser/Signer.d.ts +14 -9
- package/lib/browser/Signer.js +23 -10
- package/lib/browser/Signer.js.map +1 -1
- package/lib/browser/index.js +5 -1
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index2.js +5 -1
- package/lib/browser/index2.js.map +1 -1
- package/lib/browser/indexUtils.js +5 -1
- package/lib/browser/indexUtils.js.map +1 -1
- package/lib/browser/interface.d.ts +68 -3
- package/lib/browser/jsonDescriptors/chain-proto.json +50 -0
- package/lib/browser/jsonDescriptors/token-proto.json +37 -8
- package/lib/browser/protoModules/protocol-proto.js +518 -201
- package/lib/browser/protoModules/protocol-proto.js.map +1 -1
- package/lib/browser/utils.js +5 -1
- package/lib/browser/utils.js.map +1 -1
- package/lib/browser/utilsNode.d.ts +50 -0
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/index2.js +5 -1
- package/lib/index2.js.map +1 -1
- package/lib/indexUtils.js +5 -1
- package/lib/indexUtils.js.map +1 -1
- package/lib/interface.d.ts +68 -3
- package/lib/jsonDescriptors/chain-proto.json +50 -0
- package/lib/jsonDescriptors/token-proto.json +37 -8
- package/lib/protoModules/protocol-proto.js +518 -201
- package/lib/protoModules/protocol-proto.js.map +1 -1
- package/lib/utils.js +5 -1
- package/lib/utils.js.map +1 -1
- package/lib/utilsNode.d.ts +50 -0
- package/package.json +29 -28
package/README.md
CHANGED
|
@@ -123,7 +123,7 @@ a transaction, and read contracts.
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
// wait to be mined
|
|
126
|
-
const blockNumber = await transaction.wait();
|
|
126
|
+
const { blockNumber } = await transaction.wait();
|
|
127
127
|
console.log(`Transaction mined. Block number: ${blockNumber}`);
|
|
128
128
|
|
|
129
129
|
// read the balance
|
|
@@ -150,13 +150,56 @@ It's also possible to upload contracts. First, follow the instructions in [koino
|
|
|
150
150
|
console.log("Transaction submitted. Receipt:");
|
|
151
151
|
console.log(receipt);
|
|
152
152
|
// wait to be mined
|
|
153
|
-
const blockNumber = await transaction.wait();
|
|
153
|
+
const { blockNumber } = await transaction.wait();
|
|
154
154
|
console.log(`Contract uploaded in block number ${blockNumber}`);
|
|
155
155
|
})();
|
|
156
156
|
```
|
|
157
157
|
|
|
158
158
|
You can also upload a contract in a new address. It is not required that this new address has funds, you just have to set your principal wallet as payer.
|
|
159
159
|
|
|
160
|
+
```typescript
|
|
161
|
+
(async () => {
|
|
162
|
+
// define signer, provider and bytecode
|
|
163
|
+
const provider = new Provider(["http://api.koinos.io:8080"]);
|
|
164
|
+
const accountWithFunds = Signer.fromSeed("this account has funds");
|
|
165
|
+
const newAccount = Signer.fromSeed("new account without funds");
|
|
166
|
+
accountWithFunds.provider = provider;
|
|
167
|
+
newAccount.provider = provider;
|
|
168
|
+
|
|
169
|
+
const bytecode = fs.readFileSync("my_contract.wasm");
|
|
170
|
+
|
|
171
|
+
// create contract. Set newAccount as signer
|
|
172
|
+
const contract = new Contract({
|
|
173
|
+
signer: newAccount,
|
|
174
|
+
provider,
|
|
175
|
+
bytecode,
|
|
176
|
+
options: {
|
|
177
|
+
// transaction options
|
|
178
|
+
// set payer
|
|
179
|
+
payer: accountWithFunds.address,
|
|
180
|
+
|
|
181
|
+
// use "beforeSend" function to sign
|
|
182
|
+
// the transaction with the payer
|
|
183
|
+
beforeSend: async (tx) => {
|
|
184
|
+
accountWithFunds.signTransaction(tx);
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// call deploy()
|
|
190
|
+
// By default it is signed by "newAccount". But, as
|
|
191
|
+
// in beforeSend it is signed by the payer then it
|
|
192
|
+
// will have 2 signatures
|
|
193
|
+
const { receipt } = await contract.deploy();
|
|
194
|
+
console.log("Transaction submitted. Receipt: ");
|
|
195
|
+
console.log(receipt);
|
|
196
|
+
const { blockNumber } = await transaction.wait();
|
|
197
|
+
console.log(`Contract uploaded in block number ${blockNumber}`);
|
|
198
|
+
})();
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
In fact, there are several ways to set a different payer and use it to upload a contract. This is another example:
|
|
202
|
+
|
|
160
203
|
```typescript
|
|
161
204
|
(async () => {
|
|
162
205
|
// define signer, provider and bytecode
|
|
@@ -193,11 +236,37 @@ You can also upload a contract in a new address. It is not required that this ne
|
|
|
193
236
|
const { receipt } = await newAccount.sendTransaction(transaction);
|
|
194
237
|
console.log("Transaction submitted. Receipt: ");
|
|
195
238
|
console.log(receipt);
|
|
196
|
-
const blockNumber = await transaction.wait();
|
|
239
|
+
const { blockNumber } = await transaction.wait();
|
|
197
240
|
console.log(`Contract uploaded in block number ${blockNumber}`);
|
|
198
241
|
})();
|
|
199
242
|
```
|
|
200
243
|
|
|
244
|
+
### Multisignatures
|
|
245
|
+
|
|
246
|
+
It can be configured to sign a single transaction with multiple accounts. Here is an example:
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
const signer2 = Signer.fromSeed("signer2");
|
|
250
|
+
const signer3 = Signer.fromSeed("signer3");
|
|
251
|
+
|
|
252
|
+
const addMoreSignatures = async (tx) => {
|
|
253
|
+
await signer2.signTransaction(tx);
|
|
254
|
+
await signer3.signTransaction(tx);
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const { transaction } = await koin.transfer(
|
|
258
|
+
{
|
|
259
|
+
from: "16MT1VQFgsVxEfJrSGinrA5buiqBsN5ViJ",
|
|
260
|
+
to: "1Gvqdo9if6v6tFomEuTuMWP1D7H7U9yksb",
|
|
261
|
+
value: "1000000",
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
payer: signer2.getAddress(),
|
|
265
|
+
beforeSend: addMoreSignatures,
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
```
|
|
269
|
+
|
|
201
270
|
### Create ABIs
|
|
202
271
|
|
|
203
272
|
ABIs are composed of 2 elements: methods and types.
|
|
@@ -209,7 +278,7 @@ To generate the types is necessary to use the dependency protobufjs. The followi
|
|
|
209
278
|
|
|
210
279
|
```js
|
|
211
280
|
const fs = require("fs");
|
|
212
|
-
const pbjs = require("protobufjs
|
|
281
|
+
const pbjs = require("protobufjs-cli/pbjs");
|
|
213
282
|
|
|
214
283
|
pbjs.main(["--target", "json", "./token.proto"], (err, output) => {
|
|
215
284
|
if (err) throw err;
|
|
@@ -245,12 +314,6 @@ const abiToken = {
|
|
|
245
314
|
};
|
|
246
315
|
```
|
|
247
316
|
|
|
248
|
-
Note that this example uses "default_output" for the method
|
|
249
|
-
"balanceOf". This is used when the smart contract returns an
|
|
250
|
-
empty response (for instance when there are no balance records
|
|
251
|
-
for a specific address) and you require a default output in
|
|
252
|
-
such cases.
|
|
253
|
-
|
|
254
317
|
## FAQ
|
|
255
318
|
|
|
256
319
|
1. Can this library be used to create smart contracts?
|
|
@@ -269,7 +332,7 @@ such cases.
|
|
|
269
332
|
For the ABI you need the .proto file and the library
|
|
270
333
|
[protobufjs](https://www.npmjs.com/package/protobufjs). Then follow the format
|
|
271
334
|
for the ABI as described in the previous section. It's important to note that
|
|
272
|
-
this ABI has a
|
|
335
|
+
this ABI has a difference with respect to the ABI used in [koinos-cli](https://docs.koinos.io/architecture/contract-abi.html).
|
|
273
336
|
In particular, koilib takes the descriptor from `koilib_types`, which is a
|
|
274
337
|
descriptor in json format, while the ABI in koinos-cli takes the descriptor from
|
|
275
338
|
`types`, which is a descriptor in binary format.
|