-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeposit.js
29 lines (23 loc) · 898 Bytes
/
deposit.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
const Web3 = require('web3');
const { abi } = require('./abi.json');
const dotenv = require('dotenv');
dotenv.config();
const web3 = new Web3(new Web3.providers.HttpProvider(process.env.NODE_URL));
const contractAddress = '0xA51894664A773981C6C112C43ce576f315d5b1B6';
const contract = new web3.eth.Contract(abi, contractAddress);
const deposit = async (amount, gwei) => {
const accounts = await web3.eth.getAccounts();
const data = contract.methods.wrap(amount).encodeABI();
const tx = {
from: accounts[0],
to: contractAddress,
gas: 2000000,
gasPrice: web3.utils.toWei(gwei.toString(), 'gwei'),
data: data,
};
const signedTx = await web3.eth.accounts.signTransaction(tx, process.env.PRIVATE_KEY);
return web3.eth.sendSignedTransaction(signedTx.rawTransaction)
.on('receipt', console.log)
.on('error', console.error);
};
module.exports = { deposit };