So Im trying to use tihs code to copy traders in pancakeswap. But when the code achive the line (how i think) let decodedData = iface.parseTransaction({ data: txInfo.data })
code doesnt do bet like a trader. Code and errror is under.
const { ethers } = require('ethers')
const dotenv = require('dotenv').config();
const privateKey = process.env.privatekey
const provider = new ethers.providers.WebSocketProvider('wss://lingering-boldest-layer.bsc.discover.quiknode.pro/b3654a959a4ba0b782f4fe539b0f5f2c2b656f0f/')
const wallet = new ethers.Wallet(privateKey)
const signer = wallet.connect(provider)
//Prediction game Contract
const predictionAddress = '0x18B2A687610328590Bc8F2e5fEdDe3b582A49cdA'; // CAKE USD
const predictAbi = [{ "inputs": [{ "internalType": "contract IERC20", "name": "_token", "type": "address" }, { "internalType": "address", "name": "_oracleAddress", "type": "address" }, { "internalType": "address", "name": "_adminAddress", "type": "address" }, { "internalType": "address", "name": "_operatorAddress", "type": "address" }, { "internalType": "uint256", "name": "_intervalSeconds", "type": "uint256" }, { "internalType": "uint256", "name": "_bufferSeconds", "type": "uint256" }, { "internalType": "uint256", "name": "_minBetAmount", "type": "uint256" }, { "internalType": "uint256", "name": "_oracleUpdateAllowance", "type": "uint256" }, { "internalType": "uint256", "name": "_treasuryFee", "type": "uint256" }], "stateMutability": "nonpayable", "type": "constructor" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "sender", "type": "address" }, { "indexed": true, "internalType": "uint256", "name": "epoch", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "BetBear", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "sender", "type": "address" }, { "indexed": true, "internalType": "uint256", "name": "epoch", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "BetBull", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "sender", "type": "address" }, { "indexed": true, "internalType": "uint256", "name": "epoch", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "Claim", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "epoch", "type": "uint256" }, { "indexed": true, "internalType": "uint256", "name": "roundId", "type": "uint256" }, { "indexed": false, "internalType": "int256", "name": "price", "type": "int256" }], "name": "EndRound", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "epoch", "type": "uint256" }, { "indexed": true, "internalType": "uint256", "name": "roundId", "type": "uint256" }, { "indexed": false, "internalType": "int256", "name": "price", "type": "int256" }], "name": "LockRound", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "address", "name": "admin", "type": "address" }], "name": "NewAdminAddress", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "uint256", "name": "bufferSeconds", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "intervalSeconds", "type": "uint256" }], "name": "NewBufferAndIntervalSeconds", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "address", "name": "operator", "type": "address" }], "name": "NewKeeperAddress", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "epoch", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "minBetAmount", "type": "uint256" }], "name": "NewMinBetAmount", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "address", "name": "operator", "type": "address" }], "name": "NewOperatorAddress", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "address", "name": "oracle", "type": "address" }], "name": "NewOracle", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "uint256", "name": "oracleUpdateAllowance", "type": "uint256" }], "name": "NewOracleUpdateAllowance", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "epoch", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "treasuryFee", "type": "uint256" }], "name": "NewTreasuryFee", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" }], "name": "OwnershipTransferred", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "epoch", "type": "uint256" }], "name": "Pause", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "address", "name": "account", "type": "address" }], "name": "Paused", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "epoch", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "rewardBaseCalAmount", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "rewardAmount", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "treasuryAmount", "type": "uint256" }], "name": "RewardsCalculated", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "epoch", "type": "uint256" }], "name": "StartRound", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "token", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "TokenRecovery", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "TreasuryClaim", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "epoch", "type": "uint256" }], "name": "Unpause", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "address", "name": "account", "type": "address" }], "name": "Unpaused", "type": "event" }, { "inputs": [], "name": "MAX_TREASURY_FEE", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "adminAddress", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "epoch", "type": "uint256" }, { "internalType": "uint256", "name": "_amount", "type": "uint256" }], "name": "betBear", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "epoch", "type": "uint256" }, { "internalType": "uint256", "name": "_amount", "type": "uint256" }], "name": "betBull", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "bufferSeconds", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint256[]", "name": "epochs", "type": "uint256[]" }], "name": "claim", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "claimTreasury", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "epoch", "type": "uint256" }, { "internalType": "address", "name": "user", "type": "address" }], "name": "claimable", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "currentEpoch", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "executeRound", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "genesisLockOnce", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "genesisLockRound", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "genesisStartOnce", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "genesisStartRound", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "user", "type": "address" }, { "internalType": "uint256", "name": "cursor", "type": "uint256" }, { "internalType": "uint256", "name": "size", "type": "uint256" }], "name": "getUserRounds", "outputs": [{ "internalType": "uint256[]", "name": "", "type": "uint256[]" }, { "components": [{ "internalType": "enum PancakePredictionV3.Position", "name": "position", "type": "uint8" }, { "internalType": "uint256", "name": "amount", "type": "uint256" }, { "internalType": "bool", "name": "claimed", "type": "bool" }], "internalType": "struct PancakePredictionV3.BetInfo[]", "name": "", "type": "tuple[]" }, { "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "user", "type": "address" }], "name": "getUserRoundsLength", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "intervalSeconds", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "keeperAddress", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }, { "internalType": "address", "name": "", "type": "address" }], "name": "ledger", "outputs": [{ "internalType": "enum PancakePredictionV3.Position", "name": "position", "type": "uint8" }, { "internalType": "uint256", "name": "amount", "type": "uint256" }, { "internalType": "bool", "name": "claimed", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "minBetAmount", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "operatorAddress", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "oracle", "outputs": [{ "internalType": "contract AggregatorV3Interface", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "oracleLatestRoundId", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "oracleUpdateAllowance", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "owner", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "pause", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "paused", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_token", "type": "address" }, { "internalType": "uint256", "name": "_amount", "type": "uint256" }], "name": "recoverToken", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "epoch", "type": "uint256" }, { "internalType": "address", "name": "user", "type": "address" }], "name": "refundable", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "name": "rounds", "outputs": [{ "internalType": "uint256", "name": "epoch", "type": "uint256" }, { "internalType": "uint256", "name": "startTimestamp", "type": "uint256" }, { "internalType": "uint256", "name": "lockTimestamp", "type": "uint256" }, { "internalType": "uint256", "name": "closeTimestamp", "type": "uint256" }, { "internalType": "int256", "name": "lockPrice", "type": "int256" }, { "internalType": "int256", "name": "closePrice", "type": "int256" }, { "internalType": "uint256", "name": "lockOracleId", "type": "uint256" }, { "internalType": "uint256", "name": "closeOracleId", "type": "uint256" }, { "internalType": "uint256", "name": "totalAmount", "type": "uint256" }, { "internalType": "uint256", "name": "bullAmount", "type": "uint256" }, { "internalType": "uint256", "name": "bearAmount", "type": "uint256" }, { "internalType": "uint256", "name": "rewardBaseCalAmount", "type": "uint256" }, { "internalType": "uint256", "name": "rewardAmount", "type": "uint256" }, { "internalType": "bool", "name": "oracleCalled", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_adminAddress", "type": "address" }], "name": "setAdmin", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "_bufferSeconds", "type": "uint256" }, { "internalType": "uint256", "name": "_intervalSeconds", "type": "uint256" }], "name": "setBufferAndIntervalSeconds", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_keeperAddress", "type": "address" }], "name": "setKeeper", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "_minBetAmount", "type": "uint256" }], "name": "setMinBetAmount", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_operatorAddress", "type": "address" }], "name": "setOperator", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_oracle", "type": "address" }], "name": "setOracle", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "_oracleUpdateAllowance", "type": "uint256" }], "name": "setOracleUpdateAllowance", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "_treasuryFee", "type": "uint256" }], "name": "setTreasuryFee", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "token", "outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }], "name": "transferOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "treasuryAmount", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "treasuryFee", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "unpause", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "", "type": "address" }, { "internalType": "uint256", "name": "", "type": "uint256" }], "name": "userRounds", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }]
const contract = new ethers.Contract(predictionAddress, predictAbi, signer)
const addressToWatch = '0x101A4Fc1D52232616c245Fa85d5E4Ae370497662'
const betAmount = ethers.utils.parseEther('0.0001', 'ether') //Cake Token
const iface = new ethers.utils.Interface(predictAbi);
async function mempool() {
console.log("starting...")
provider.on("pending", async (tx) => {
const txInfo = await provider.getTransaction(tx);
try {
const to = txInfo['to'];
const from = txInfo['from']
if (to == predictionAddress && from == addressToWatch) {
console.log("Placing bet on prediction Game " + to)
console.log("1");
**\\I THINK CODE STOPS HERE**
let decodedData = iface.parseTransaction({ data: txInfo.data });
console.log("2");
console.log(decodedData);
console.log("3");
const epoch = await contract.currentEpoch()
console.log(decodedData['name'])
if (decodedData['name'].toString() == 'betBear') {
const betBearTx = contract.betBear(epoch, betAmount)
const receipt = provider.getTransactionReceipt()
console.log(receipt, betBearTx)
}
else if (decodedData['name'].toString() == 'betBull') {
const betBullTx = contract.betBull(epoch, betAmount)
const receipt = provider.getTransactionReceipt()
console.log(receipt, betBullTx)
}
}
}
catch (error) {
console.log("no data to show")
console.error(error);
}
})
}
mempool()
the error which I catch enter image description here
I expect that code will copy traders bet