Created
November 7, 2023 05:36
-
-
Save jokereven/60de5b8f306ff0d1b140b94ccae5ce03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from uniswap import Uniswap | |
from web3 import Web3 | |
address = "" # or None if you're not going to make transactions | |
private_key = "" # or None if you're not going to make transactions | |
version = 2 # specify which version of Uniswap to use | |
provider = "" # can also be set through the environment variable `PROVIDER` | |
uniswap = Uniswap(address=address, private_key=private_key, version=version, provider=provider) | |
# Some token addresses we'll be using later in this guide | |
eth = "0x0000000000000000000000000000000000000000" | |
JOE = "0x76e222b07c53d28b89b0bac18602810fc22b49a8" | |
joe = Web3.to_checksum_address(JOE) | |
price = uniswap.get_price_input(eth, joe, 5 * 10**16) | |
price = Web3.from_wei(price, 'ether') | |
print(price, '== 0.05 ETH') | |
out_price = uniswap.get_price_output(eth, joe, 1_0000 * 10**18) | |
out_price = Web3.from_wei(out_price, 'ether') | |
print(out_price, '== 1_0000 JOE') | |
uniswap.make_trade_output(eth, joe, 5 * 10**16, slippage=30) # buy JOE for 0.05 ETH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment