0

I'm trying to build a web3.py program to take in a given user's address, and return the amount of ETH traded since they added liquidity to a Uniswap exchange. Uniswap is a smart contract on the Ethereum platform.

The Uniswap contract has a method 'AddLiquidity' that allows users to add funds, and I want to find when a given user did this.

I looked through the documentation for how to do this. I'm accessing the blockchain via an infura node, and the docs seemed to say that on infura you can't use a filter.

On the contract documentation, it seemed like I could do this via the events object, but couldnt't get this to work. Think the eventslog may be important but as I say have struggled to get any of it to do what I was hoping.

Please let me know if you need any further info to help me and thanks!

0

Smart Contract

pragma solidity 0.5.1;


contract Uniswap {

   event Triggered(address indexed user);

   function addLiquidity() external {
       emit Triggered(msg.sender);
   }

}

Javascript Event Filtering

var sha3HashOfTheEvent = web3.sha3("event Triggered(address)");
var filterOptions = {
    fromBlock: 0,
    toBlock: 'latest',
    topics:[sha3HashOfTheEvent]
}
filter.watch(function(error, result){
    if(!error){
       console.log("The event has been triggered.......")
       filter.stopWatching();
    }
});

Hope it will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.