Created
December 19, 2021 23:51
-
-
Save yuyasugano/a327c8ffad16b128e4b7e9ae18f3de95 to your computer and use it in GitHub Desktop.
MLC-FlashLoanDemo Example
This file contains hidden or 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
// test a flashloan in Multipler V1 | |
require('dotenv').config(); | |
const Web3 = require('web3'); | |
const BigNumber = require('bignumber.js'); | |
const abis = require('./abis'); | |
const instance = require('./build/contracts/Flashloan.json'); | |
const web3 = new Web3( | |
new Web3.providers.HttpProvider(process.env.BSC_HTTPS) | |
); | |
const { address: admin } = web3.eth.accounts.wallet.add(process.env.PRIVATE_KEY); | |
const amount = process.env.BNB_AMOUNT; | |
const flashloan = async() => { | |
const networkId = await web3.eth.net.getId(); | |
const contract = new web3.eth.Contract( | |
instance.abi, | |
instance.networks[networkId].address | |
); | |
const borrow = await new BigNumber(amount).shiftedBy(18); | |
const tx = await contract.methods.flashloanBnb(borrow); | |
// gas and gasPrice are manually set | |
const data = tx.encodeABI(); | |
const txData = { | |
from: admin, | |
to: contract.options.address, | |
data, | |
gas: 310000, | |
gasPrice: 5000000000, // 5Gwei | |
}; | |
const receipt = await web3.eth.sendTransaction(txData); | |
console.log(`Transaction hash: ${receipt.transactionHash}`); | |
} | |
flashloan(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment