Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update readme #44

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 91 additions & 41 deletions ethers-ext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,69 +10,119 @@ Ethers.js Extension for Klaytn offers:

## Note for ethers v6

`@kaiachain/ethers-ext` was developed based on ethers v5. As a result, ethers v6 classes are incompatible with ethers-ext classes. If you are using ethers v6 in your codebase, do not mix ethers v6 classes and ethers-ext classes. e.g. ethers v6 JsonRpcProvider cannot be supplied to ethers-ext Wallet.

- **Don't**: mix ethers v6 and ethers-ext
```js
const ethers = require("ethers");
const { Wallet } = require("@kaiachain/ethers-ext");

const provider = new ethers.JsonRpcProvider("https://public-en-kairos.node.kaia.io");
const wallet = new Wallet("<private key>", provider);
```
- **Do**: mix ethers v5 and ethers-ext
```js
const ethers = require("ethers");
const { Wallet } = require("@kaiachain/ethers-ext");

const provider = new ethers.providers.JsonRpcProvider("https://public-en-kairos.node.kaia.io");
const wallet = new Wallet("<private key>", provider);
```
- **Do**: ethers-ext only
```js
const { Wallet, JsonRpcProvider } = require("@kaiachain/ethers-ext");

const provider = new JsonRpcProvider("https://public-en-kairos.node.kaia.io");
const wallet = new Wallet("<private key>", provider);
```
`@kaiachain/ethers-ext` supports both ethers v5 and v6. However, you need to use the right packages which are specified for each `ethers` version. So ethers v5 must be used with packages from `@kaiachain/ethers-ext/v5` and ethers v6 is only compatible with `@kaiachain/ethers-ext/v6`.

> **_NOTE:_**
> If the import path has no version sub-path (`@kaiachain/ethers-ext`), ethers v5 will be used by default.

- **Don't**: Mixing ethers v6 and ethers-ext for ethers v5

```js
const ethers = require("ethers"); // ethers v6
const { Wallet } = require("@kaiachain/ethers-ext/v5");

const provider = new ethers.JsonRpcProvider(
"https://public-en-kairos.node.kaia.io"
);
const wallet = new Wallet("<private key>", provider);
```

- **Do**: Using with ethers v5

```js
const ethers = require("ethers"); // ethers v5
const { Wallet } = require("@klaytn/ethers-ext/v5");

const provider = new ethers.providers.JsonRpcProvider(
"https://public-en-kairos.node.kaia.io"
);
const wallet = new Wallet("<private key>", provider);
```

- **Do**: Using with ethers v6

```js
const ethers = require("ethers"); // ethers v6
const { Wallet } = require("@klaytn/ethers-ext/v6");

const provider = new ethers.JsonRpcProvider(
"https://public-en-kairos.node.kaia.io"
);
const wallet = new Wallet("<private key>", provider);
```

- **Do**: Using ethers-ext only

```js
const { Wallet, JsonRpcProvider } = require("@kaiachain/ethers-ext/v5");
// or
const { Wallet, JsonRpcProvider } = require("@kaiachain/ethers-ext/v6");

const provider = new JsonRpcProvider("https://public-en-kairos.node.kaia.io");
const wallet = new Wallet("<private key>", provider);
```

## Install

### Node.js

- Install
```sh
npm install --save @kaiachain/ethers-ext ethers@5
```
```sh
npm install --save @kaiachain/ethers-ext ethers@5 # or ethers@6
```
- ESM or TypeScript
```ts
import { Wallet, JsonRpcProvider } from "@kaiachain/ethers-ext";
const provider = new JsonRpcProvider("https://public-en-kairos.node.kaia.io");
const wallet = new Wallet("<private key>", provider);
```

```ts
import { Wallet, JsonRpcProvider } from "@klaytn/ethers-ext";

// esm
// v5
import { v5 } from "@klaytn/ethers-ext";
const { Wallet, JsonRpcProvider } = v5;
// v6
import { v6 } from "@klaytn/ethers-ext";
const { Wallet, JsonRpcProvider } = v6;

// esm subpath import. If using typescript, add "moduleResolution": "nodenext" to tsconfig.json
// v5
import { Wallet, JsonRpcProvider } from "@klaytn/ethers-ext/v5";
// v6
import { Wallet, JsonRpcProvider } from "@klaytn/ethers-ext/v6";

const provider = new JsonRpcProvider("https://public-en-kairos.node.kaia.io");
const wallet = new Wallet("<private key>", provider);
```

- CommonJS
```js
const { Wallet, JsonRpcProvider } = require("@kaiachain/ethers-ext");
const provider = new JsonRpcProvider("https://public-en-kairos.node.kaia.io");
const wallet = new Wallet("<private key>", provider);
```

```js
// v5
const { Wallet, JsonRpcProvider } = require("@klaytn/ethers-ext");
const { Wallet, JsonRpcProvider } = require("@klaytn/ethers-ext").v5;
const { Wallet, JsonRpcProvider } = require("@klaytn/ethers-ext/v5");
// v6
const { Wallet, JsonRpcProvider } = require("@klaytn/ethers-ext").v6;
const { Wallet, JsonRpcProvider } = require("@klaytn/ethers-ext/v6");

const provider = new JsonRpcProvider("https://public-en-kairos.node.kaia.io");
const wallet = new Wallet("<private key>", provider);
```

### Browser

It is not recommended to use CDNs in production, But you can use below for quick prototyping.
It is not recommended to use CDNs in production, But you can use below for quick prototyping. using `ethers-ext.buldle.js` for ethers v5 and `ethers-ext.v6.bundle.js` for ethers v6

```html
<script src="https://cdn.jsdelivr.net/npm/@kaiachain/ethers-ext@latest/dist/ethers-ext.bundle.js"></script>
<script>
const provider = new ethers_ext.providers.Web3Provider(window.klaytn);
const provider = new ethers_ext.providers.Web3Provider(window.klaytn);
</script>
```

## Usage

See [example](./example) and [test](./test).


## Class extension design

```mermaid
Expand Down
Loading