koilib 2.8.0 → 3.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 +61 -7
- package/dist/koinos.js +8404 -200
- package/dist/koinos.min.js +1 -1
- package/lib/Contract.d.ts +46 -7
- package/lib/Contract.js +89 -21
- package/lib/Contract.js.map +1 -1
- package/lib/Provider.d.ts +16 -3
- package/lib/Provider.js +36 -6
- package/lib/Provider.js.map +1 -1
- package/lib/Serializer.d.ts +2 -1
- package/lib/Serializer.js +50 -37
- package/lib/Serializer.js.map +1 -1
- package/lib/Signer.d.ts +42 -42
- package/lib/Signer.js +294 -112
- package/lib/Signer.js.map +1 -1
- package/lib/browser/Contract.d.ts +46 -7
- package/lib/browser/Contract.js +89 -21
- package/lib/browser/Contract.js.map +1 -1
- package/lib/browser/Provider.d.ts +16 -3
- package/lib/browser/Provider.js +36 -6
- package/lib/browser/Provider.js.map +1 -1
- package/lib/browser/Serializer.d.ts +2 -1
- package/lib/browser/Serializer.js +50 -37
- package/lib/browser/Serializer.js.map +1 -1
- package/lib/browser/Signer.d.ts +42 -42
- package/lib/browser/Signer.js +294 -112
- 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 +221 -45
- package/lib/browser/jsonDescriptors/chain-proto.json +676 -0
- package/lib/browser/jsonDescriptors/krc20-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 +18 -254
- package/lib/browser/utils.js +140 -12
- 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 +221 -45
- package/lib/jsonDescriptors/chain-proto.json +676 -0
- package/lib/jsonDescriptors/krc20-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 +18 -254
- package/lib/utils.js +140 -12
- 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
|
@@ -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
|
|
|
@@ -117,11 +121,13 @@ a transaction, and read contracts.
|
|
|
117
121
|
|
|
118
122
|
// read the balance
|
|
119
123
|
const { result } = await koin.balanceOf(signer.getAddress());
|
|
120
|
-
console.log(
|
|
124
|
+
console.log(result);
|
|
121
125
|
})();
|
|
122
126
|
```
|
|
123
127
|
|
|
124
|
-
|
|
128
|
+
#### Upload contract
|
|
129
|
+
|
|
130
|
+
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
131
|
|
|
126
132
|
```typescript
|
|
127
133
|
(async () => {
|
|
@@ -140,6 +146,47 @@ It's also possible to upload contracts. First, follow the instructions in [koino
|
|
|
140
146
|
})();
|
|
141
147
|
```
|
|
142
148
|
|
|
149
|
+
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.
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
(async () => {
|
|
153
|
+
// define signer, provider and bytecode
|
|
154
|
+
const provider = new Provider(["http://api.koinos.io:8080"]);
|
|
155
|
+
const accountWithFunds = Signer.fromSeed("this account has funds");
|
|
156
|
+
const newAccount = Signer.fromSeed("new account without funds");
|
|
157
|
+
accountWithFunds.provider = provider;
|
|
158
|
+
newAccount.provider = provider;
|
|
159
|
+
|
|
160
|
+
const bytecode = fs.readFileSync("my_contract.wasm");
|
|
161
|
+
|
|
162
|
+
// create contract. Set newAccount as signer
|
|
163
|
+
const contract = new Contract({
|
|
164
|
+
signer: newAccount.address,
|
|
165
|
+
provider,
|
|
166
|
+
bytecode,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// call deploy but do not broadcast the transaction.
|
|
170
|
+
// Also set the payer
|
|
171
|
+
const { transaction } = await contract.deploy({
|
|
172
|
+
payer: accountWithFunds.address,
|
|
173
|
+
sendTransaction: false,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// sign the transaction with the payer
|
|
177
|
+
await accountWithFunds.signTransaction(transaction);
|
|
178
|
+
|
|
179
|
+
// at this point the transaction will have 2 signatures:
|
|
180
|
+
// - signature of newAccount
|
|
181
|
+
// - signature of accountWithFunds
|
|
182
|
+
|
|
183
|
+
// now broadcast the transaction to deploy
|
|
184
|
+
transaction = await newAccount.sendTransaction(transaction);
|
|
185
|
+
const blockNumber = await transaction.wait();
|
|
186
|
+
console.log(`Contract uploaded in block number ${blockNumber}`);
|
|
187
|
+
})();
|
|
188
|
+
```
|
|
189
|
+
|
|
143
190
|
### Create ABIs
|
|
144
191
|
|
|
145
192
|
ABIs are composed of 2 elements: methods and types.
|
|
@@ -166,19 +213,19 @@ const tokenJson = require("./token-proto.json");
|
|
|
166
213
|
const abiToken = {
|
|
167
214
|
methods: {
|
|
168
215
|
balanceOf: {
|
|
169
|
-
entryPoint:
|
|
216
|
+
entryPoint: 0x5c721497,
|
|
170
217
|
inputs: "balance_of_arguments",
|
|
171
218
|
outputs: "balance_of_result",
|
|
172
219
|
readOnly: true,
|
|
173
220
|
defaultOutput: { value: "0" },
|
|
174
221
|
},
|
|
175
222
|
transfer: {
|
|
176
|
-
entryPoint:
|
|
223
|
+
entryPoint: 0x27f576ca,
|
|
177
224
|
inputs: "transfer_arguments",
|
|
178
225
|
outputs: "transfer_result",
|
|
179
226
|
},
|
|
180
227
|
mint: {
|
|
181
|
-
entryPoint:
|
|
228
|
+
entryPoint: 0xdc6f17bb,
|
|
182
229
|
inputs: "mint_argumnets",
|
|
183
230
|
outputs: "mint_result",
|
|
184
231
|
},
|
|
@@ -197,8 +244,9 @@ such cases.
|
|
|
197
244
|
|
|
198
245
|
1. Can this library be used to create smart contracts?
|
|
199
246
|
|
|
200
|
-
No. You need to install [koinos-
|
|
201
|
-
|
|
247
|
+
No. You need to install [koinos-sdk](https://github.com/koinos/koinos-sdk-cpp)
|
|
248
|
+
(for C++ developers) or [koinos-as-sdk-examples](https://github.com/roaminroe/koinos-as-sdk-examples)
|
|
249
|
+
(for TypeScript developers) for this purpose.
|
|
202
250
|
|
|
203
251
|
2. Can this library be used to deploy smart contracts?
|
|
204
252
|
|
|
@@ -223,6 +271,12 @@ such cases.
|
|
|
223
271
|
|
|
224
272
|
The complete documentation can be found at https://joticajulian.github.io/koilib/
|
|
225
273
|
|
|
274
|
+
## Acknowledgments
|
|
275
|
+
|
|
276
|
+
Many thanks to the sponsors of this library: @levineam, @Amikob, @motoeng, @isaacdozier, @imjwalker, and the private sponsors.
|
|
277
|
+
|
|
278
|
+
If you would like to contribute to the development of this library consider becoming a sponsor in https://github.com/sponsors/joticajulian.
|
|
279
|
+
|
|
226
280
|
## License
|
|
227
281
|
|
|
228
282
|
MIT License
|