Skip to content

Commit

Permalink
Merge branch 'dev' into stanislav-breadless-zks-183-linting-and-forma…
Browse files Browse the repository at this point in the history
…tting-architecture
  • Loading branch information
StanislavBreadless committed Dec 27, 2020
2 parents cf7a5e7 + 176362d commit 78888ba
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions infrastructure/eth_transfer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
22 changes: 22 additions & 0 deletions infrastructure/eth_transfer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "eth_transfer",
"version": "0.0.1",
"description": "CLI tool for transfering ETH",
"main": "build/index.js",
"bin": "build/index.js",
"repository": "https://github.com/matter-labs/zksync-dev.git",
"author": "The Matter Labs Team",
"license": "MIT",
"scripts": {
"build": "tsc",
"watch": "tsc --watch",
"start": "node build/index.js"
},
"devDependencies": {
"typescript": "^4.0.2"
},
"dependencies": {
"commander": "^6.0.0",
"ethers": "^5.0.18"
}
}
45 changes: 45 additions & 0 deletions infrastructure/eth_transfer/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Command } from 'commander';
import { ethers, Wallet } from 'ethers';

const program = new Command();
program.version('0.0.1');

program
.option('-pk, --private-key <private-key>', 'private key of the sender')
.option('-t, --target <target>', 'address of the target account')
.option('-n, --network <network>', 'eth network')
.option('-a, --amount <amount>', 'amount of the ETH to be sent');

program.parse(process.argv);

function getProvider(network: string) {
if (network === 'localhost') {
return new ethers.providers.JsonRpcProvider('http://localhost:8545');
}

return ethers.providers.getDefaultProvider(network);
}

async function main() {
const { privateKey, target, amount, network } = program;

const provider = getProvider(network || 'mainnet');
const wallet = new Wallet(privateKey).connect(provider);

let tx = {
to: target,
value: ethers.utils.parseEther(amount)
};

try {
const txResponse = await wallet.sendTransaction(tx);
console.log('Transaction was sent! Hash: ', txResponse.hash);
} catch (err) {
console.log('Failed to send tx. Reason: ', err.message || err);
}
}

main().catch((err: Error) => {
console.error('Error:', err.message || err);
process.exitCode = 1;
});
15 changes: 15 additions & 0 deletions infrastructure/eth_transfer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "es2019",
"module": "commonjs",
"outDir": "build",
"strict": true,
"esModuleInterop": true,
"noEmitOnError": true,
"skipLibCheck": true,
"declaration": true
},
"files": [
"src/index.ts"
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"infrastructure/zcli",
"infrastructure/explorer",
"infrastructure/zk",
"infrastructure/eth_transfer",
"core/tests/ts-tests"
],
"nohoist": [
Expand Down

0 comments on commit 78888ba

Please sign in to comment.