koilib 2.7.0 → 3.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 +75 -12
- package/dist/koinos.js +8556 -269
- package/dist/koinos.min.js +1 -1
- package/lib/Contract.d.ts +66 -18
- package/lib/Contract.js +103 -40
- package/lib/Contract.js.map +1 -1
- package/lib/Provider.d.ts +22 -7
- package/lib/Provider.js +60 -21
- package/lib/Provider.js.map +1 -1
- package/lib/Serializer.d.ts +9 -3
- package/lib/Serializer.js +111 -85
- package/lib/Serializer.js.map +1 -1
- package/lib/Signer.d.ts +58 -38
- package/lib/Signer.js +318 -97
- package/lib/Signer.js.map +1 -1
- package/lib/browser/Contract.d.ts +66 -18
- package/lib/browser/Contract.js +103 -40
- package/lib/browser/Contract.js.map +1 -1
- package/lib/browser/Provider.d.ts +22 -7
- package/lib/browser/Provider.js +60 -21
- package/lib/browser/Provider.js.map +1 -1
- package/lib/browser/Serializer.d.ts +9 -3
- package/lib/browser/Serializer.js +111 -85
- package/lib/browser/Serializer.js.map +1 -1
- package/lib/browser/Signer.d.ts +58 -38
- package/lib/browser/Signer.js +318 -97
- package/lib/browser/Signer.js.map +1 -1
- package/lib/browser/index.d.ts +1 -1
- package/lib/browser/index.js +1 -1
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/indexUtils.d.ts +2 -0
- package/lib/browser/indexUtils.js +15 -0
- package/lib/browser/indexUtils.js.map +1 -0
- package/lib/browser/interface.d.ts +242 -46
- package/lib/browser/jsonDescriptors/chain-proto.json +676 -0
- package/lib/browser/jsonDescriptors/{krc20-proto.json → token-proto.json} +47 -4
- package/lib/browser/protoModules/protocol-proto.d.ts +2 -0
- package/lib/browser/protoModules/protocol-proto.js +6336 -0
- package/lib/browser/protoModules/protocol-proto.js.map +1 -0
- package/lib/browser/utils.d.ts +19 -255
- package/lib/browser/utils.js +170 -15
- package/lib/browser/utils.js.map +1 -1
- package/lib/browser/utilsNode.d.ts +1021 -0
- package/lib/browser/utilsNode.js +346 -0
- package/lib/browser/utilsNode.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/indexUtils.d.ts +2 -0
- package/lib/indexUtils.js +15 -0
- package/lib/indexUtils.js.map +1 -0
- package/lib/interface.d.ts +242 -46
- package/lib/jsonDescriptors/chain-proto.json +676 -0
- package/lib/jsonDescriptors/{krc20-proto.json → token-proto.json} +47 -4
- package/lib/protoModules/protocol-proto.d.ts +2 -0
- package/lib/protoModules/protocol-proto.js +6336 -0
- package/lib/protoModules/protocol-proto.js.map +1 -0
- package/lib/utils.d.ts +19 -255
- package/lib/utils.js +170 -15
- package/lib/utils.js.map +1 -1
- package/lib/utilsNode.d.ts +1021 -0
- package/lib/utilsNode.js +346 -0
- package/lib/utilsNode.js.map +1 -0
- package/package.json +1 -1
- package/lib/browser/jsonDescriptors/protocol-proto.json +0 -246
- package/lib/jsonDescriptors/protocol-proto.json +0 -246
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
|
});
|
|
@@ -77,6 +77,10 @@ There are 4 principal classes:
|
|
|
77
77
|
- **Serializer**: Class with the protocol buffers definitions to
|
|
78
78
|
serialize/deserialize data types.
|
|
79
79
|
|
|
80
|
+
### Examples
|
|
81
|
+
|
|
82
|
+
#### Send tokens, get balance
|
|
83
|
+
|
|
80
84
|
The following code shows how to sign a transaction, broadcast
|
|
81
85
|
a transaction, and read contracts.
|
|
82
86
|
|
|
@@ -88,7 +92,7 @@ a transaction, and read contracts.
|
|
|
88
92
|
signer.provider = provider;
|
|
89
93
|
const koinContract = new Contract({
|
|
90
94
|
id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
91
|
-
abi: utils.
|
|
95
|
+
abi: utils.tokenAbi,
|
|
92
96
|
provider,
|
|
93
97
|
signer,
|
|
94
98
|
});
|
|
@@ -105,11 +109,16 @@ a transaction, and read contracts.
|
|
|
105
109
|
});
|
|
106
110
|
|
|
107
111
|
// Transfer
|
|
108
|
-
const { transaction } = await koin.transfer({
|
|
112
|
+
const { transaction, receipt } = await koin.transfer({
|
|
109
113
|
to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
|
|
110
114
|
value: "10.0001",
|
|
111
115
|
});
|
|
112
|
-
console.log(`Transaction id ${transaction.id} submitted
|
|
116
|
+
console.log(`Transaction id ${transaction.id} submitted. Receipt:`);
|
|
117
|
+
console.log(receipt);
|
|
118
|
+
|
|
119
|
+
if (receipt.logs) {
|
|
120
|
+
console.log(`Transfer failed. Logs: ${receipt.logs.join(",")}`);
|
|
121
|
+
}
|
|
113
122
|
|
|
114
123
|
// wait to be mined
|
|
115
124
|
const blockNumber = await transaction.wait();
|
|
@@ -117,11 +126,13 @@ a transaction, and read contracts.
|
|
|
117
126
|
|
|
118
127
|
// read the balance
|
|
119
128
|
const { result } = await koin.balanceOf(signer.getAddress());
|
|
120
|
-
console.log(
|
|
129
|
+
console.log(result);
|
|
121
130
|
})();
|
|
122
131
|
```
|
|
123
132
|
|
|
124
|
-
|
|
133
|
+
#### Upload contract
|
|
134
|
+
|
|
135
|
+
It's also possible to upload contracts. First, follow the instructions in [koinos-sdk](https://github.com/koinos/koinos-sdk-cpp) (for C++ developers) or [koinos-as-sdk-examples](https://github.com/roaminroe/koinos-as-sdk-examples) (for TypeScript developers) to compile the contracts as wasm files. Then you can use koilib to deploy them.
|
|
125
136
|
|
|
126
137
|
```typescript
|
|
127
138
|
(async () => {
|
|
@@ -133,13 +144,58 @@ It's also possible to upload contracts. First, follow the instructions in [koino
|
|
|
133
144
|
|
|
134
145
|
// create contract and deploy
|
|
135
146
|
const contract = new Contract({ signer, provider, bytecode });
|
|
136
|
-
const { transaction } = await contract.deploy();
|
|
147
|
+
const { transaction, receipt } = await contract.deploy();
|
|
148
|
+
console.log("Transaction submitted. Receipt:");
|
|
149
|
+
console.log(receipt);
|
|
137
150
|
// wait to be mined
|
|
138
151
|
const blockNumber = await transaction.wait();
|
|
139
152
|
console.log(`Contract uploaded in block number ${blockNumber}`);
|
|
140
153
|
})();
|
|
141
154
|
```
|
|
142
155
|
|
|
156
|
+
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.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
(async () => {
|
|
160
|
+
// define signer, provider and bytecode
|
|
161
|
+
const provider = new Provider(["http://api.koinos.io:8080"]);
|
|
162
|
+
const accountWithFunds = Signer.fromSeed("this account has funds");
|
|
163
|
+
const newAccount = Signer.fromSeed("new account without funds");
|
|
164
|
+
accountWithFunds.provider = provider;
|
|
165
|
+
newAccount.provider = provider;
|
|
166
|
+
|
|
167
|
+
const bytecode = fs.readFileSync("my_contract.wasm");
|
|
168
|
+
|
|
169
|
+
// create contract. Set newAccount as signer
|
|
170
|
+
const contract = new Contract({
|
|
171
|
+
signer: newAccount.address,
|
|
172
|
+
provider,
|
|
173
|
+
bytecode,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// call deploy but do not broadcast the transaction.
|
|
177
|
+
// Also set the payer
|
|
178
|
+
const { transaction } = await contract.deploy({
|
|
179
|
+
payer: accountWithFunds.address,
|
|
180
|
+
sendTransaction: false,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// sign the transaction with the payer
|
|
184
|
+
await accountWithFunds.signTransaction(transaction);
|
|
185
|
+
|
|
186
|
+
// at this point the transaction will have 2 signatures:
|
|
187
|
+
// - signature of newAccount
|
|
188
|
+
// - signature of accountWithFunds
|
|
189
|
+
|
|
190
|
+
// now broadcast the transaction to deploy
|
|
191
|
+
const { receipt } = await newAccount.sendTransaction(transaction);
|
|
192
|
+
console.log("Transaction submitted. Receipt: ");
|
|
193
|
+
console.log(receipt);
|
|
194
|
+
const blockNumber = await transaction.wait();
|
|
195
|
+
console.log(`Contract uploaded in block number ${blockNumber}`);
|
|
196
|
+
})();
|
|
197
|
+
```
|
|
198
|
+
|
|
143
199
|
### Create ABIs
|
|
144
200
|
|
|
145
201
|
ABIs are composed of 2 elements: methods and types.
|
|
@@ -166,19 +222,19 @@ const tokenJson = require("./token-proto.json");
|
|
|
166
222
|
const abiToken = {
|
|
167
223
|
methods: {
|
|
168
224
|
balanceOf: {
|
|
169
|
-
entryPoint:
|
|
225
|
+
entryPoint: 0x5c721497,
|
|
170
226
|
inputs: "balance_of_arguments",
|
|
171
227
|
outputs: "balance_of_result",
|
|
172
228
|
readOnly: true,
|
|
173
229
|
defaultOutput: { value: "0" },
|
|
174
230
|
},
|
|
175
231
|
transfer: {
|
|
176
|
-
entryPoint:
|
|
232
|
+
entryPoint: 0x27f576ca,
|
|
177
233
|
inputs: "transfer_arguments",
|
|
178
234
|
outputs: "transfer_result",
|
|
179
235
|
},
|
|
180
236
|
mint: {
|
|
181
|
-
entryPoint:
|
|
237
|
+
entryPoint: 0xdc6f17bb,
|
|
182
238
|
inputs: "mint_argumnets",
|
|
183
239
|
outputs: "mint_result",
|
|
184
240
|
},
|
|
@@ -197,8 +253,9 @@ such cases.
|
|
|
197
253
|
|
|
198
254
|
1. Can this library be used to create smart contracts?
|
|
199
255
|
|
|
200
|
-
No. You need to install [koinos-
|
|
201
|
-
|
|
256
|
+
No. You need to install [koinos-sdk](https://github.com/koinos/koinos-sdk-cpp)
|
|
257
|
+
(for C++ developers) or [koinos-as-sdk-examples](https://github.com/roaminroe/koinos-as-sdk-examples)
|
|
258
|
+
(for TypeScript developers) for this purpose.
|
|
202
259
|
|
|
203
260
|
2. Can this library be used to deploy smart contracts?
|
|
204
261
|
|
|
@@ -223,6 +280,12 @@ such cases.
|
|
|
223
280
|
|
|
224
281
|
The complete documentation can be found at https://joticajulian.github.io/koilib/
|
|
225
282
|
|
|
283
|
+
## Acknowledgments
|
|
284
|
+
|
|
285
|
+
Many thanks to the sponsors of this library: @levineam, @Amikob, @motoeng, @isaacdozier, @imjwalker, and the private sponsors.
|
|
286
|
+
|
|
287
|
+
If you would like to contribute to the development of this library consider becoming a sponsor in https://github.com/sponsors/joticajulian.
|
|
288
|
+
|
|
226
289
|
## License
|
|
227
290
|
|
|
228
291
|
MIT License
|