Comparing version 1.3.3 to 1.3.4
@@ -1,2 +0,2 @@ | ||
export declare const supportedChains: readonly ["137", "17000"]; | ||
export declare const supportedChains: readonly ["1", "137", "17000"]; | ||
export type SupportedChain = typeof supportedChains[number]; | ||
@@ -3,0 +3,0 @@ export declare const zkETHContractItem: readonly ["zkETH", "zkETHRelayer"]; |
@@ -9,2 +9,3 @@ "use strict"; | ||
exports.supportedChains = [ | ||
'1', // ethereum | ||
'137', // polygon | ||
@@ -16,2 +17,8 @@ '17000' // holesky | ||
const tokenLists = { | ||
'1': { | ||
usdt: "0xdAC17F958D2ee523a2206206994597C13D831ec7", | ||
usdc: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", | ||
link: "0x514910771af9ca656af840dff83e8264ecf986ca", | ||
wsteth: "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0", | ||
}, | ||
'137': { | ||
@@ -50,2 +57,6 @@ usdt: "0xc2132d05d31c914a87c6611c10748aeb04b58e8f", | ||
const contracts = { | ||
1: { | ||
zkETH: "0xB30a12919579128147bA11F99Ed4Bd31f7e535e4", | ||
zkETHRelayer: "", | ||
}, | ||
137: { | ||
@@ -52,0 +63,0 @@ zkETH: "0x0e96e410e5B40c4BEF8f8dA0E053BFb8855D5A84", |
import { ethers } from "ethers"; | ||
import { SupportedChain, TokenName } from "../config/utils.js"; | ||
import { SupportedChain, TokenMetadataType, TokenName } from "../config/utils.js"; | ||
import Authentication from "../authentication/auth.js"; | ||
@@ -17,2 +17,3 @@ /** | ||
getTokenAddress: (token: TokenName) => string; | ||
getTokenListsWithMetadata: () => TokenMetadataType[]; | ||
getTokenContract: (token: TokenName) => Promise<ethers.Contract>; | ||
@@ -19,0 +20,0 @@ depositNative: (amountInWei: bigint, onBehalfOf: string, queryId?: number) => Promise<any>; |
@@ -32,2 +32,5 @@ "use strict"; | ||
}; | ||
this.getTokenListsWithMetadata = () => { | ||
return this.tokenListsWithMetadata; | ||
}; | ||
this.getTokenContract = (token) => __awaiter(this, void 0, void 0, function* () { | ||
@@ -34,0 +37,0 @@ const tokenAddress = this.getTokenAddress(token); |
{ | ||
"name": "zkt-sdk", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"description": "zkToken | JS SDK", | ||
@@ -12,3 +12,3 @@ "main": "lib/index.js", | ||
"build-web": "rimraf dist/web && webpack --mode production", | ||
"build-node": "rimraf lib && tsc && copy-assets ", | ||
"build-node": "rimraf lib && tsc && npm run copy-assets ", | ||
"pub": "npm version patch --force && npm publish" | ||
@@ -15,0 +15,0 @@ }, |
193
README.md
@@ -5,13 +5,46 @@ # zkt-sdk | ||
library designed to interact with zkETH contracts on Ethereum and other supported blockchains. It provides methods to deposit native tokens and ERC-20 tokens, manage token approvals, and handle authentication. | ||
## Installation and Running | ||
To install ZkETH, use npm or yarn: | ||
```sh | ||
npm install zketh | ||
``` | ||
or | ||
```sh | ||
yarn add zketh | ||
``` | ||
### As a package for typescript project | ||
Initiate zketh instance: | ||
```js | ||
import { ZkEth } from "zkt-sdk"; | ||
import { ZkEth, ethers } from "zkt-sdk"; | ||
const zkEth = new ZkEth("<ETHERJS_BROWSER_PROVIDER>"); | ||
const auth = zkEth.authentication("<SXT_ENDPOINT>", "<SECRETS_PROXY_ENDPOINT>"); | ||
console.log(zkEth); | ||
const main = async () => { | ||
const provider = new ethers.JsonRpcProvider('https://ethereum-holesky.publicnode.com'); | ||
const signer = new ethers.Wallet(privateKey, provider); | ||
// Define the chain ID (e.g., 17000 for holesky) | ||
const zkEth = new ZkEth(signer, '17000'); // holesky | ||
try { | ||
const tx = await zkEth.depositNative(20n, '0x3077Bf667dBD81d3c718684Da4DE4Dc8448220E1', 0); // 20 wei | ||
const txReceipt = await tx.wait(); | ||
} catch (e) { | ||
console.log("error:", e); | ||
} | ||
console.log('venu!'); | ||
}; | ||
main(); | ||
``` | ||
@@ -21,2 +54,6 @@ | ||
Here's an example of how to use the zkt-lib library with ethers v5 lib: | ||
using Ethers v6: | ||
```js | ||
@@ -34,4 +71,30 @@ import { ZkEth } from "zkt-sdk"; | ||
### As a bundled js file for the web | ||
zkt-sdk also export ethers v6 instance: | ||
```js | ||
import { ZkEth, SupportedChain ,ethers} from "zketh"; | ||
const provider = new ethers.JsonRpcProvider("YOUR_RPC_URL"); | ||
const signer = provider.getSigner(); | ||
// Define the chain ID (1 for Ethereum mainnet) | ||
const chainId: SupportedChain = 1; | ||
// Instantiate the ZkEth class | ||
const zkEth = new ZkEth(signer, chainId); | ||
// Use the ZkEth instance to interact with zkETH contracts | ||
async function main() { | ||
const tokenContract = await zkEth.getTokenContract("usdt"); | ||
console.log("Token contract address:", tokenContract.address); | ||
const depositTx = await zkEth.depositNative(BigInt("1000000000000000000"), "0xRecipientAddress"); | ||
console.log("Deposit transaction:", depositTx); | ||
} | ||
main().catch(console.error); | ||
``` | ||
### As a package file for the nodejs | ||
1. Install all dependencies | ||
@@ -43,48 +106,114 @@ | ||
2. Build the bundled js file | ||
2. Generate a node js package | ||
```sh | ||
yarn run build-web | ||
yarn run build | ||
``` | ||
The build files should be available in `./dist/web` folder | ||
Node js version of the files will be generated to `lib` | ||
3. Test | ||
```sh | ||
yarn run test-web | ||
## Methods | ||
- getZkETHContract | ||
```ts | ||
async getZkETHContract(): Promise<ethers.Contract> | ||
``` | ||
A new `index.html` with sample usage code should be available in the `./dist` folder. In your browser open http://localhost:9000 and check the console logs. It watches any changes to the html file | ||
Returns an instance of the zkETH contract. | ||
#### Usage | ||
- getTokenAddress | ||
```html | ||
<!DOCTYPE html> | ||
<head> | ||
<script src="./bundle.js"></script> | ||
<script> | ||
// Using the auth | ||
const zkEth = new ZkEth("<ETHERJS_BROWSER_PROVIDER>"); | ||
const auth = zkEth.authentication("<SXT_ENDPOINT>", "<SECRETS_PROXY_ENDPOINT>"); | ||
console.log(auth) | ||
</script> | ||
</head> | ||
</html> | ||
```ts | ||
getTokenAddress(token: TokenName): string | ||
``` | ||
### As a package file for the nodejs | ||
Returns the address of a specified token. | ||
1. Install all dependencies | ||
token: The name of the token. Valid names are "usdt", "usdc", "link", "wsteth". | ||
```sh | ||
yarn | ||
- getTokenListsWithMetadata | ||
```ts | ||
getTokenListsWithMetadata(): TokenMetadataType[] | ||
``` | ||
2. Generate a node js package | ||
Returns a list of tokens with their metadata. | ||
- getTokenContract | ||
```ts | ||
async getTokenContract(token: TokenName): Promise<ethers.Contract> | ||
``` | ||
Returns an instance of the specified token's contract. | ||
token: The name of the token. | ||
- depositNative | ||
```ts | ||
async depositNative( | ||
amountInWei: bigint, | ||
onBehalfOf: string, | ||
queryId?: number | ||
): Promise<any> | ||
``` | ||
Deposits native tokens (ETH/MATIC) into the zkETH contract. | ||
amountInWei: The amount to deposit, in wei. | ||
onBehalfOf: The address on whose behalf the deposit is made. | ||
queryId: (Optional) A query ID for tracking purposes. | ||
- approve | ||
```ts | ||
async approve(token: TokenName, amount: bigint): Promise<any> | ||
Approves the zkETH contract to spend a specified amount of a token. | ||
``` | ||
token: The name of the token. | ||
amount: The amount to approve. | ||
- revokeApprove | ||
```ts | ||
async revokeApprove(token: TokenName): Promise<any> | ||
Revokes the approval for the zkETH contract to spend a specified token. | ||
``` | ||
token: The name of the token. | ||
- depositTokens | ||
```ts | ||
async depositTokens( | ||
token: TokenName, | ||
amount: bigint, | ||
onBehalfOf: string, | ||
queryId?: number | ||
): Promise<any> | ||
``` | ||
Deposits ERC-20 tokens into the zkETH contract. | ||
token: The name of the token. | ||
amount: The amount to deposit. | ||
onBehalfOf: The address on whose behalf the deposit is made. | ||
queryId: (Optional) A query ID for tracking purposes. | ||
# Development | ||
To contribute to the development of ZkETH, clone the repository and install the dependencies: | ||
```sh | ||
yarn run build-node | ||
git clone https://github.com/spaceandtimelabs/zkt-sdk-js.git | ||
cd zketh | ||
npm install | ||
``` | ||
Node js version of the files will be generated to `dist/node` | ||
# Contributing | ||
We welcome contributions to zkt-sdk. Please open an issue or submit a pull request on GitHub. | ||
# License | ||
ZkETH is released under the MIT License. See the LICENSE file for more details. |
74659
1766
215