Skip to content

Commit

Permalink
chore(js): lint the project
Browse files Browse the repository at this point in the history
  • Loading branch information
danijelTxFusion committed Dec 22, 2023
1 parent 2952040 commit 3420520
Show file tree
Hide file tree
Showing 25 changed files with 243 additions and 203 deletions.
60 changes: 30 additions & 30 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{
"name": "zksync2-js-examples",
"version": "0.1.0",
"license": "MIT",
"devDependencies": {
"@types/chai": "^4.3.9",
"@types/mocha": "^10.0.1",
"@types/node": "^20.5.2",
"c8": "^8.0.1",
"chai": "^4.3.10",
"ethers": "^6.7.1",
"mocha": "^10.2.0",
"prettier": "3.0.3",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
},
"peerDependencies": {
"ethers": "^6.9.0"
},
"dependencies": {
"zksync-ethers": "^6.0.0"
},
"scripts": {
"test:prepare": "cd tests/setup/ && ./setup.sh && cd ../..",
"test:wait": "ts-node tests/wait.ts",
"test": "mocha -r ts-node/register tests/*.test.ts",
"lint": "prettier . --write",
"lint:check": "prettier . --check",
"watch": "tsc --watch"
}
}
"name": "zksync2-js-examples",
"version": "0.1.0",
"license": "MIT",
"devDependencies": {
"@types/chai": "^4.3.9",
"@types/mocha": "^10.0.1",
"@types/node": "^20.5.2",
"c8": "^8.0.1",
"chai": "^4.3.10",
"ethers": "^6.7.1",
"mocha": "^10.2.0",
"prettier": "3.0.3",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
},
"peerDependencies": {
"ethers": "^6.9.0"
},
"dependencies": {
"zksync-ethers": "^6.0.0"
},
"scripts": {
"test:prepare": "cd tests/setup/ && ./setup.sh && cd ../..",
"test:wait": "ts-node tests/wait.ts",
"test": "mocha -r ts-node/register tests/*.test.ts",
"lint": "prettier . --write",
"lint:check": "prettier . --check",
"watch": "tsc --watch"
}
}
17 changes: 9 additions & 8 deletions js/src/01_deposit.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {Provider, types, utils, Wallet} from "zksync-ethers";
import {ethers} from "ethers";
import { Provider, types, utils, Wallet } from "zksync-ethers";
import { ethers } from "ethers";

const provider = Provider.getDefaultProvider(types.Network.Sepolia);
const ethProvider = ethers.getDefaultProvider("sepolia");
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);


async function main() {
console.log(`L2 balance before deposit: ${await wallet.getBalance()}`);
console.log(`L1 balance before deposit: ${await wallet.getBalanceL1()}`);
Expand All @@ -15,15 +14,17 @@ async function main() {
token: utils.ETH_ADDRESS,
to: await wallet.getAddress(),
amount: ethers.parseEther("0.00020"),
refundRecipient: await wallet.getAddress()
refundRecipient: await wallet.getAddress(),
});
const receipt = await tx.wait();
const receipt = await tx.wait();
console.log(`Tx: ${receipt.hash}`);

console.log(`L2 balance after deposit: ${await wallet.getBalance()}`);
console.log(`L1 balance after deposit: ${await wallet.getBalanceL1()}`);
}

main().then().catch(error => {
console.log(`Error: ${error}`);
})
main()
.then()
.catch((error) => {
console.log(`Error: ${error}`);
});
15 changes: 8 additions & 7 deletions js/src/02_transfer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {Provider, types, Wallet} from "zksync-ethers";
import {ethers} from "ethers";
import { Provider, types, Wallet } from "zksync-ethers";
import { ethers } from "ethers";

const provider = Provider.getDefaultProvider(types.Network.Sepolia);
const ethProvider = ethers.getDefaultProvider("sepolia");
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);


async function main() {
const receiver = "0x81E9D85b65E9CC8618D85A1110e4b1DF63fA30d9";

Expand All @@ -17,13 +16,15 @@ async function main() {
to: receiver,
amount: ethers.parseEther("0.01"),
});
const receipt = await tx.wait();
const receipt = await tx.wait();
console.log(`Tx: ${receipt.hash}`);

console.log(`Account1 balance after transfer: ${await wallet.getBalance()}`);
console.log(`Account2 balance after transfer: ${await provider.getBalance(receiver)}`);
}

main().then().catch(error => {
console.log(`Error: ${error}`);
})
main()
.then()
.catch((error) => {
console.log(`Error: ${error}`);
});
15 changes: 8 additions & 7 deletions js/src/03_withdraw.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {Provider, types, utils, Wallet} from "zksync-ethers";
import {ethers} from "ethers";
import { Provider, types, utils, Wallet } from "zksync-ethers";
import { ethers } from "ethers";

const provider = Provider.getDefaultProvider(types.Network.Sepolia);
const ethProvider = ethers.getDefaultProvider("sepolia");
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);


async function main() {
console.log(`L2 balance before withdraw: ${await wallet.getBalance()}`);
console.log(`L1 balance before withdraw: ${await wallet.getBalanceL1()}`);
Expand All @@ -16,7 +15,7 @@ async function main() {
to: await wallet.getAddress(),
amount: ethers.parseEther("0.00020"),
});
const receipt = await tx.wait();
const receipt = await tx.wait();
console.log(`Tx: ${receipt.hash}`);

// The duration for submitting a withdrawal transaction to L1 can last up to 24 hours. For additional information,
Expand All @@ -25,6 +24,8 @@ async function main() {
// To learn more about how to achieve this, please take a look at the 04_finalize_withdraw.ts script.
}

main().then().catch(error => {
console.log(`Error: ${error}`);
})
main()
.then()
.catch((error) => {
console.log(`Error: ${error}`);
});
15 changes: 8 additions & 7 deletions js/src/04_finalize_withdraw.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Provider, types, Wallet} from "zksync-ethers";
import {ethers} from "ethers";
import { Provider, types, Wallet } from "zksync-ethers";
import { ethers } from "ethers";

const provider = Provider.getDefaultProvider(types.Network.Sepolia);
const ethProvider = ethers.getDefaultProvider("sepolia");
Expand All @@ -9,12 +9,11 @@ const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);
const WITHDRAW_TX = process.env.WITHDRAW_TX;

async function main() {

// Perform the finalize withdrawal if it has not been already finalized.
// On the testnet, withdrawals are automatically finalized. For additional information, please refer
// to the documentation: https://era.zksync.io/docs/reference/concepts/bridging-asset.html#withdrawals-to-l1.
// There is no need to execute FinalizeWithdraw, otherwise, an error with code `jj` would occur.
if (! (await wallet.isWithdrawalFinalized(WITHDRAW_TX))) {
if (!(await wallet.isWithdrawalFinalized(WITHDRAW_TX))) {
const finalizeWithdrawTx = await wallet.finalizeWithdrawal(WITHDRAW_TX);
const receipt = await finalizeWithdrawTx.wait();
console.log(`Tx: ${receipt.hash}`);
Expand All @@ -24,6 +23,8 @@ async function main() {
}
}

main().then().catch(error => {
console.log(`Error: ${error}`);
})
main()
.then()
.catch((error) => {
console.log(`Error: ${error}`);
});
19 changes: 9 additions & 10 deletions js/src/05_deposit_token.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {Provider, types, Wallet} from "zksync-ethers";
import {ethers} from "ethers";
import { Provider, types, Wallet } from "zksync-ethers";
import { ethers } from "ethers";

const provider = Provider.getDefaultProvider(types.Network.Sepolia);
const ethProvider = ethers.getDefaultProvider("sepolia");
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);



async function main() {
// Crown token which can be mint for free
const tokenL1 = "0x56E69Fa1BB0d1402c89E3A4E3417882DeA6B14Be";
Expand All @@ -21,16 +19,17 @@ async function main() {
to: await wallet.getAddress(),
amount: 5,
approveERC20: true,
refundRecipient: await wallet.getAddress()
refundRecipient: await wallet.getAddress(),
});
const receipt = await tx.wait();
const receipt = await tx.wait();
console.log(`Tx: ${receipt.hash}`);

console.log(`L2 balance after deposit: ${await wallet.getBalance(tokenL2)}`);
console.log(`L1 balance after deposit: ${await wallet.getBalanceL1(tokenL1)}`);

}

main().then().catch(error => {
console.log(`Error: ${error}`);
})
main()
.then()
.catch((error) => {
console.log(`Error: ${error}`);
});
23 changes: 14 additions & 9 deletions js/src/06_transfer_token.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
import {Provider, types, Wallet} from "zksync-ethers";
import {ethers} from "ethers";
import { Provider, types, Wallet } from "zksync-ethers";
import { ethers } from "ethers";

const provider = Provider.getDefaultProvider(types.Network.Sepolia);
const ethProvider = ethers.getDefaultProvider("sepolia");
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);


async function main() {
const token = "0x6a4Fb925583F7D4dF82de62d98107468aE846FD1";
const receiver = "0x81E9D85b65E9CC8618D85A1110e4b1DF63fA30d9";

console.log(`Account1 balance before transfer: ${await wallet.getBalance(token)}`);
console.log(`Account2 balance before transfer: ${await provider.getBalance(receiver, 'latest', token)}`);
console.log(
`Account2 balance before transfer: ${await provider.getBalance(receiver, "latest", token)}`,
);

const tx = await wallet.transfer({
token: token,
to: receiver,
amount: 5,
});
const receipt = await tx.wait();
const receipt = await tx.wait();
console.log(`Tx: ${receipt.hash}`);

console.log(`Account1 balance after transfer: ${await wallet.getBalance(token)}`);
console.log(`Account2 balance after transfer: ${await provider.getBalance(receiver, 'latest', token)}`);
console.log(
`Account2 balance after transfer: ${await provider.getBalance(receiver, "latest", token)}`,
);
}

main().then().catch(error => {
console.log(`Error: ${error}`);
})
main()
.then()
.catch((error) => {
console.log(`Error: ${error}`);
});
15 changes: 8 additions & 7 deletions js/src/07_withdraw_token.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {Provider, types, Wallet} from "zksync-ethers";
import {ethers} from "ethers";
import { Provider, types, Wallet } from "zksync-ethers";
import { ethers } from "ethers";

const provider = Provider.getDefaultProvider(types.Network.Sepolia);
const ethProvider = ethers.getDefaultProvider("sepolia");
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);


async function main() {
const token = "0x6a4Fb925583F7D4dF82de62d98107468aE846FD1";

Expand All @@ -18,7 +17,7 @@ async function main() {
to: await wallet.getAddress(),
amount: 5,
});
const receipt = await tx.wait();
const receipt = await tx.wait();
console.log(`Tx: ${receipt.hash}`);

// The duration for submitting a withdrawal transaction to L1 can last up to 24 hours. For additional information,
Expand All @@ -27,6 +26,8 @@ async function main() {
// To learn more about how to achieve this, please take a look at the 04_finalize_withdraw.ts script.
}

main().then().catch(error => {
console.log(`Error: ${error}`);
})
main()
.then()
.catch((error) => {
console.log(`Error: ${error}`);
});
12 changes: 7 additions & 5 deletions js/src/08_get_confirmed_tokens.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Provider, types} from "zksync-ethers";
import { Provider, types } from "zksync-ethers";

const provider = Provider.getDefaultProvider(types.Network.Sepolia);

function toJSON(object: any): string {
return JSON.stringify(object, (key, value) => {
if (typeof value === 'bigint') {
if (typeof value === "bigint") {
return value.toString(); // Convert BigInt to string
}
return value;
Expand All @@ -15,6 +15,8 @@ async function main() {
console.log(`Confirmed tokens: ${toJSON(await provider.getConfirmedTokens())}`);
}

main().then().catch(error => {
console.log(`Error: ${error}`);
})
main()
.then()
.catch((error) => {
console.log(`Error: ${error}`);
});
14 changes: 8 additions & 6 deletions js/src/09_deploy_create.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Provider, types, Wallet, ContractFactory, Contract} from "zksync-ethers";
import {ethers, Typed} from "ethers";
import { Provider, types, Wallet, ContractFactory, Contract } from "zksync-ethers";
import { ethers, Typed } from "ethers";

const provider = Provider.getDefaultProvider(types.Network.Sepolia);
const PRIVATE_KEY = process.env.PRIVATE_KEY;
Expand All @@ -11,7 +11,7 @@ async function main() {
const bytecode: string = conf.contracts["Storage.sol:Storage"].bin;

const factory = new ContractFactory(abi, bytecode, wallet);
const storage = await factory.deploy() as Contract;
const storage = (await factory.deploy()) as Contract;
console.log(`Contract address: ${await storage.getAddress()}`);

console.log(`Value: ${await storage.get()}`);
Expand All @@ -22,6 +22,8 @@ async function main() {
console.log(`Value: ${await storage.get()}`);
}

main().then().catch(error => {
console.log(`Error: ${error}`);
})
main()
.then()
.catch((error) => {
console.log(`Error: ${error}`);
});
Loading

0 comments on commit 3420520

Please sign in to comment.