easy solution RIGHT HERE;
Import your required libraries
from web3 import Web3, HTTPProvider
Intialize your infura node in a variable
w3 = Web3(Web3.HTTPProvider("https://rinkeby.infura.io/v3/YOUR_INFURA_KEY"))
aand.. the most SIMPLE part, which TOOK OVER THREE WEEKS to figure out because the documentation is absolutely horrenous ;
inject the damn middle-ware in the variable holding your infura node;
w3.middleware_stack.inject(geth_poa_middleware, layer=0)
just remember that you have to sign all transactions LOCALLY, as infura does not handle any keys from your wallet
transaction = contract.functions.function_Name(params)
signed_tx = w3.eth.account.signTransaction(transaction, private_key)
and then send;
txn_hash = w3.eth.sendRawTransaction(signed.rawTransaction)
txn_receipt = w3.eth.waitForTransactionReceipt(txn_hash)
there you go, an all in one solution !
P.S : use print(txn_receipt) to get transaction id to view in etherscan
Factory.createPair()
will effectively deploy your pair contract, while when using UniswapLibrary.pairFor(), you will get the theoretical address of any potential pair, based on the uniswapV2Pair bytecode keccak256 hash (the "INIT_CODE" in get_pair()). If this hash differs than the one based on your actual deployment (ie an "old" value stayed hard-coded), createPair and pairFor will return different values.
See https://ethereum.stackexchange.com/a/112709/68134 for similar concept in V3
Best Answer
By definition of EIP-214 any state change within a static call will cause an error. So if you define your function as
view
orpure
this will not be possible, as this indicates the calling contract that they should usestaticcall
.BUT if you want to write a method and don't care about the
view
orpure
you can do a little trick.You create a method that will perform the call, encode the response (success, data) into a
bytes
and then revert via assembly with thesebytes
, therefore reverting the state changes. You can now call this function from another function, catch this error and process the results.Gnosis has written utils for this: https://github.com/gnosis/util-contracts/blob/main/contracts/storage/StorageAccessible.sol
Hopefully this can be simplified once Solidity allows catching custom errors. As of now you require assembly to do this without wasting too much gas.