diff --git a/cli.js b/cli.js index a72a0e8..666da53 100755 --- a/cli.js +++ b/cli.js @@ -71,7 +71,11 @@ async function generateTransaction(to, encodedData, value = 0) { const bumped = Math.floor(fetchedGas * 1.3) gasLimit = web3.utils.toHex(bumped) } - await estimateGas(); + if (encodedData) { + await estimateGas(); + } else { + gasLimit = web3.utils.toHex(21000); + } async function txoptions() { // Generate EIP-1559 transaction @@ -348,6 +352,53 @@ async function withdraw({ deposit, currency, amount, recipient, relayerURL, torP console.log('Done withdrawal from Tornado Cash') } +/** + * Do an ETH / ERC20 send + * @param address Recepient address + * @param amount Amount to send + * @param tokenAddress ERC20 token address + */ +async function send({ address, amount, tokenAddress }) { + // using private key + assert(senderAccount != null, 'Error! PRIVATE_KEY not found. Please provide PRIVATE_KEY in .env file if you send') + if (tokenAddress) { + const erc20ContractJson = require('./build/contracts/ERC20Mock.json') + erc20 = new web3.eth.Contract(erc20ContractJson.abi, tokenAddress) + const balance = await erc20.methods.balanceOf(senderAccount).call() + const decimals = await erc20.methods.decimals().call() + const toSend = amount * Math.pow(10, decimals) + if (balance < toSend) { + console.error("You have",toDecimals(balance, decimals, (balance.length + decimals)).toString().replace(/\B(? { async function getRelayerStatus() { @@ -984,6 +1035,13 @@ async function main() { await printERC20Balance({ address, name: 'Account', tokenAddress }) } }) + program + .command('send
[amount] [token_address]') + .description('Send ETH or ERC to address') + .action(async (address, amount, tokenAddress) => { + await init({ rpc: program.rpc, torPort: program.tor, balanceCheck: true }) + await send({ address, amount, tokenAddress }) + }) program .command('compliance