-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathnewbot.js
64 lines (50 loc) · 1.96 KB
/
newbot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const ethers = require('ethers');
//This contains an Endpoint URL, and a wallet private key!!!
const secrets = require('./secrets.json');
//THIS WORK ON BSC TESTNET!!!!!
//All Values are for the testnet!!!!!!!!
const WBNB = "0xae13d989dac2f0debff460ac112a837c89baa7cd";
const BUSD = "0x78867BbEeF44f2326bF8DDd1941a4439382EF2A7";
const router = "0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3";
const provider = new ethers.providers.JsonRpcProvider(secrets.provider);
const wallet = new ethers.Wallet(secrets.privatekey);
const signer = wallet.connect(provider);
const routerContract = new ethers.Contract(
router,
[
'function getAmountsOut(uint amountIn, address[] memory path) public view returns(uint[] memory amounts)',
'function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)'
],
signer
);
const busdContract = new ethers.Contract(
BUSD,
[
'function approve(address spender, uint256 amount) external returns (bool)'
],
signer
)
async function main() {
const BUSDamountIn = ethers.utils.parseUnits('100', 18);
let amounts = await routerContract.getAmountsOut(BUSDamountIn, [BUSD, WBNB]);
const WBNBamountOutMin = amounts[1].sub(amounts[1].div(10));
console.log(ethers.utils.formatEther(BUSDamountIn));
console.log(ethers.utils.formatEther(WBNBamountOutMin));
const approveTx = await busdContract.approve(
router,
BUSDamountIn
);
let reciept = await approveTx.wait();
console.log(reciept);
const swapTx = await routerContract.swapExactTokensForTokens(
BUSDamountIn,
WBNBamountOutMin,
[BUSD, WBNB],
wallet.address,
Date.now() + 1000 * 60 * 10,
{gasLimit: 250000}
)
receipt = await swapTx.wait();
console.log(receipt);
}
main().then().finally(() => {});