forked from matter-labs/zksync
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2526ccc
commit 4da64a5
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |