Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
filoozom committed Apr 27, 2022
0 parents commit 90bf3ec
Show file tree
Hide file tree
Showing 7 changed files with 1,432 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
wallet.json
23 changes: 23 additions & 0 deletions add-token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { getDefaultProvider } = require("ethers");
const { Wallet, Provider } = require("zksync-web3");

// Lib
const { getWallet } = require("./get-wallet");

// Config
const token = "0x6842745bCDBa872C64CeE14C5036EF7AECD587ab";

// Get wallet and contract
const zkSyncProvider = new Provider("https://zksync2-testnet.zksync.dev");
const ethereumProvider = getDefaultProvider("goerli");
const wallet = new Wallet(
getWallet().privateKey,
zkSyncProvider,
ethereumProvider
);

// Deposit tokens
(async () => {
const tx = await wallet.addToken({ token });
console.log(await tx.wait());
})();
10 changes: 10 additions & 0 deletions create-wallet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { writeFileSync, existsSync } = require("fs");
const { Wallet } = require("ethers");

if (existsSync("wallet.json")) {
console.log("Wallet already exists");
process.exit(-1);
}

const wallet = Wallet.createRandom();
writeFileSync("wallet.json", JSON.stringify(wallet.mnemonic));
27 changes: 27 additions & 0 deletions deposit-token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { getDefaultProvider } = require("ethers");
const { Wallet, Provider } = require("zksync-web3");

// Lib
const { getWallet } = require("./get-wallet");

// Config
const token = "0x6842745bCDBa872C64CeE14C5036EF7AECD587ab";

// Get wallet and contract
const zkSyncProvider = new Provider("https://zksync2-testnet.zksync.dev");
const ethereumProvider = getDefaultProvider("goerli");
const wallet = new Wallet(
getWallet().privateKey,
zkSyncProvider,
ethereumProvider
);

// Deposit tokens
(async () => {
const tx = await wallet.deposit({
token,
amount: 100n * 10n ** 18n,
approveERC20: true,
});
console.log(await tx.wait());
})();
17 changes: 17 additions & 0 deletions get-wallet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { readFileSync } = require("fs");
const { Wallet } = require("ethers");

const getWallet = () => {
const json = JSON.parse(readFileSync("wallet.json"));
return Wallet.fromMnemonic(json.phrase, json.path, json.locale);
};

module.exports = {
getWallet,
};

if (require.main === module) {
const wallet = getWallet();
console.log("Address:", wallet.address);
console.log("Private key:", wallet.privateKey);
}
Loading

0 comments on commit 90bf3ec

Please sign in to comment.