-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathapproveTokens.js
52 lines (41 loc) · 1.74 KB
/
approveTokens.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
const {ethers} = require('ethers');
const {PANCAKE_ROUTER_ADDRESS,WEBSOCKET_PROVIDER_LINK, TOKEN_ADDRESSES, PRIVATE_KEY} = require('./constants.js');
const mnemonic = PRIVATE_KEY; //your memonic;
const provider = new ethers.providers.WebSocketProvider(WEBSOCKET_PROVIDER_LINK);
const wallet = new ethers.Wallet(mnemonic);
const account = wallet.connect(provider);
const recipient = account.getAddress();
const start = async() => {
const out_token_addresses = TOKEN_ADDRESSES;
for(var index = 0; index < out_token_addresses.length; index++) {
await approveIn(out_token_addresses[index]);
}
}
const approveIn = async (tokenIn) => {
const tokenApprove = new ethers.Contract(
tokenIn,
[
'function approve(address spender, uint256 amount) external returns (bool)',
'function allowance(address owner, address spender) external view returns (uint)'
],
account
);
const allowance = await tokenApprove.allowance(recipient,PANCAKE_ROUTER_ADDRESS);
if (allowance > 9999999){
console.log(('Current Allowance: '+ allowance));
}else{
console.log('Approving token...');
const approve = await tokenApprove.approve(
PANCAKE_ROUTER_ADDRESS, //pancake router
ethers.constants.MaxUint256, //max approve
{
'gasLimit': '300000',
'gasPrice': ethers.utils.parseUnits('10', 'gwei'), //INCREASE IN FUTURE ? FOR ETHEREUM
}
);
const approveReceipt = await approve.wait();
console.log(approveReceipt);
console.log(`txHash: ${approveReceipt.logs[0].transactionHash}`);
}
}
start();