Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joticajulian/kondor-js
library to interact with kondor extension
https://github.com/joticajulian/kondor-js
Last synced: 3 months ago
JSON representation
library to interact with kondor extension
- Host: GitHub
- URL: https://github.com/joticajulian/kondor-js
- Owner: joticajulian
- License: mit
- Created: 2022-05-07T21:05:32.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-25T16:14:15.000Z (9 months ago)
- Last Synced: 2024-10-18T07:24:06.289Z (3 months ago)
- Language: TypeScript
- Size: 1.25 MB
- Stars: 2
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Kondor JS
Library to interact with Kondor, the browser extension for Koinos blockchain.
## Table of Contents
1. [Install](#install)
2. [Usage](#usage)
3. [Documentation](#documentation)
4. [License](#license)## Install
Install the package from NPM
```sh
npm install kondor-js
```You can also load it directly to the browser by downloading the bunble file located at `dist/kondor.min.js`, or its non-minified version `dist/kondor.js` (useful for debugging).
## Usage
### Vanilla JS
```html
My App
(async () => {
const accounts = await kondor.getAccounts();
const userAddress = accounts[0].address;const koinContract = new Contract({
id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
abi: utils.tokenAbi,
provider: kondor.getProvider("harbinger"),
signer: kondor.getSigner(userAddress),
});
const koin = koinContract.functions;// Get balance
const { result } = await koin.balanceOf({
owner: userAddress,
});
console.log(balance.result);
})();
```
NOTE: For koilib check https://github.com/joticajulian/koilib
### Using a framework
```ts
import * as kondor from "kondor-js";
import { Contract, utils } from "koilib";(async () => {
const accounts = await kondor.getAccounts();
const userAddress = accounts[0].address;const koinContract = new Contract({
id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
abi: utils.tokenAbi,
provider: kondor.getProvider("harbinger"),
signer: kondor.getSigner(userAddress),
});
const koin = koinContract.functions;// Get balance
const { result } = await koin.balanceOf({
owner: userAddress,
});
console.log(balance.result);
})();
```### Known issues
In some cases Kondor triggers 2 popups. In particular when transaction options like `chainId`, `rcLimit`, and `nonce` are defined beforehand and then Kondor doesn't have to calculate them.
If this happens to you then define the signer in this way:
```
const provider = new Provider(["https://api.koinos.io"]);
const userAddress = "1K6oESWG87m3cB3M2WVkzxdTr38po8WToN";
const signer = kondor.getSigner(userAddress, {
providerPrepareTransaction: provider,
});
```With this definition, kondor will use `providerPrepareTransaction` in the preparation of the transaction instead of calling the kondor extension. This solves the race condition with double popups.
Take into account that if you use this code but the `chainId`, `rcLimit`, or `nonce` are not defined, then it's normal to see a delay between the click and the popup (because they are called using the provider before triggering the popup). In conclusion, define the 3 values when using `providerPrepareTransaction` to not experiment delays.
Note: This is a temporary solution while the race condition with double popups is fixed.
## Test
Run `yarn serve` and open in the browser `http://localhost:8081/test.html`. This page contains a basic example to get accounts and make a transfer using Kondor.
## Acknowledgments
Many thanks to the sponsors of this library: @levineam, @Amikob, @motoeng, @isaacdozier, @imjwalker, and the private sponsors.
If you would like to contribute to the development of this library consider becoming a sponsor in https://github.com/sponsors/joticajulian.
## License
MIT License
Copyright (c) 2021 Julián González
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.