CryptoFly.us | CRYPTOCURRENCY BITCOIN SHIRTS CLOTHING APPAREL HATS

CRYPTO NEWS

Event Listener using web3py (for stateless node providers)

I am trying to make an event listener, I came across this code and it works fine for infura nodes, however, when I use another type of node, specifically from ankr, it gives the the error ValueError: {‘code’: -32000, ‘message’: ‘filter not found’}.

# import the following dependencies import json from web3 import Web3 import asyncio  # add your blockchain connection information infura_url = 'ADDYOURINFURAURL' web3 = Web3(Web3.HTTPProvider(infura_url))  # uniswap address and abi uniswap_router = '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D' uniswap_factory = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f' uniswap_factory_abi = json.loads('[{"inputs":[{"internalType":"address","name":"_feeToSetter","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token0","type":"address"},{"indexed":true,"internalType":"address","name":"token1","type":"address"},{"indexed":false,"internalType":"address","name":"pair","type":"address"},{"indexed":false,"internalType":"uint256","name":"","type":"uint256"}],"name":"PairCreated","type":"event"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"allPairs","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"allPairsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"}],"name":"createPair","outputs":[{"internalType":"address","name":"pair","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"feeTo","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"feeToSetter","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"getPair","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_feeTo","type":"address"}],"name":"setFeeTo","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_feeToSetter","type":"address"}],"name":"setFeeToSetter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]')  contract = web3.eth.contract(address=uniswap_factory, abi=uniswap_factory_abi)   # define function to handle events and print to the console def handle_event(event):     print(Web3.toJSON(event))     # and whatever   # asynchronous defined function to loop # this loop sets up an event filter and is looking for new entires for the "PairCreated" event # this loop runs on a poll interval 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)   # when main is called # create a filter for the latest block and look for the "PairCreated" event for the uniswap factory contract # run an async loop # try to run the log_loop function above every 2 seconds def main():     event_filter = contract.events.PairCreated.createFilter(fromBlock='latest')     #block_filter = web3.eth.filter('latest')     # tx_filter = web3.eth.filter('pending')     loop = asyncio.get_event_loop()     try:         loop.run_until_complete(             asyncio.gather(                 log_loop(event_filter, 2)))                 # log_loop(block_filter, 2),                 # log_loop(tx_filter, 2)))     finally:         # close loop to free up system resources         loop.close()   if __name__ == "__main__":     main() 

Is it possible to achieve receive eth and mint nft in the same contract?

recently I’m build some ERC721 nft contract. I know that smart contract can receive ETH, so my question is that is it possible to write a payable function, and upon receive some ETH from someone, the contract will mint an NFT right away and send to the msg sender? If not, what will be the::Listen

recently I’m build some ERC721 nft contract.

I know that smart contract can receive ETH, so my question is that is it possible to write a payable function, and upon receive some ETH from someone, the contract will mint an NFT right away and send to the msg sender?

If not, what will be the recommended way to buy an NFT with ETH instead of going through some third party platform like OpenSea? Thanks!

Event Listener using web3py (for stateless node providers)

Shopping cart
There are no products in the cart!
Continue shopping
0