2

I was just trying to create something which will listen to buy(pancakeswap) events of a specific token like SafeMoon & notify me when someone buys it on pancakeswap.

My progress so far. The Way I Am Doing Now Is Finding Pancakeswap Pair Address Of A Token And Listen For Its Swap Events

pair_address = '0xBc9d0929c5a1D21BbAaB8826c0a6a78e096702A4' #Pair Address Of ORAKLER/WBNB On Pancakeswap

contract = web3.eth.contract(address=web3.toChecksumAddress(pair_address), abi=helper.getTokenAbi(pair_address))

def handle_event(event):
    result = Web3.toJSON(event)
    main_base = json.loads(result)
    txn_hash = main_base['transactionHash']
    print(result)
    

async def log_loop(event_filter, poll_interval):
    while True:
        for PairCreated in event_filter.get_new_entries():
            handle_event(PairCreated)
        await asyncio.sleep(poll_interval)

def main():
    event_filter = contract.events.Swap.createFilter(fromBlock='latest')

    loop = asyncio.get_event_loop()
    try:
        loop.run_until_complete(
            asyncio.gather(
                log_loop(event_filter, 2)))
    finally:
        loop.close()


if __name__ == "__main__":
    main()

In the above code, I am listing for Swap Event Of A Smart Contract And The Output I Am Getting Is

{"args": {"sender": "0x10ED43C718714eb63d5aA57B78B54704E256024E", "to": "0x4C7369b0615125481E2D6Fcd39e4d8c70DB2e830", "amount0In": 0, "amount1In": 4957805606627501, "amount0Out": 200000000000000000, "amount1Out": 0}, "event": "Swap", "logIndex": 339, "transactionIndex": 102, "transactionHash": "0x694f61f705d2fa49d6b16f9d56902f6e4b50c88e9d3adb4ab6fbea6632b0eb1b", "address": "0xBc9d0929c5a1D21BbAaB8826c0a6a78e096702A4", "blockHash": "0x6aedadf8d3618a1d21a48890d7bcfd9968df575a1a56323830f5dd242c79cdd3", "blockNumber": 14269884}

It contains Swap Event Parameter And They Look Like That

Swap (
  index_topic_1 address sender,
  uint256 amount0In,
  uint256 amount1In,
  uint256 amount0Out,
  uint256 amount1Out,
  index_topic_2 address to
)

I am just confused about how to determine if it's a sold ORAKLER or Just bought & if he did buy how much money In BNB did he spend.

If anyone knows any other solution to do it or anything wrong I am doing here please tell me

Mr. AdityaYT
  • 51
  • 1
  • 6

1 Answers1

0

I have figured out what I was doing wrong.

First I was using pancake factory address instead of my token lp address. Second I have to use Swap not PairCreated In The code

Mr. AdityaYT
  • 51
  • 1
  • 6