Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Buy/Sell Token Example#357

AL-THE-BOT-FATHER started this conversation inShow and tell
Nov 16, 2023· 5 comments· 1 reply
Discussion options

Thank you for this library. It works well!

I think some more examples would be helpful for users.

from uniswap import Uniswapfrom web3 import Web3import configdef create_uniswap_instance():    return Uniswap(address=config.WALLET, private_key=config.PRIV, provider=config.PROVIDER, version=2)def buy_token(token_address, eth_amount):    eth = "0x0000000000000000000000000000000000000000"    uniswap = create_uniswap_instance()        eth_balance_eth = Web3.from_wei(uniswap.get_eth_balance(), 'ether')    print(f"ETH Balance: {eth_balance_eth} ETH")        eth_amount_wei = Web3.to_wei(eth_amount, 'ether')        tx = uniswap.make_trade(eth, token_address, eth_amount_wei)    print(f"Transaction hash: {tx.hex()}")def sell_token(token_address):    eth = "0x0000000000000000000000000000000000000000"    uniswap = create_uniswap_instance()        token_balance_wei = uniswap.get_token_balance(token_address)    print(f"Token Balance: {token_balance_wei} ")        tx = uniswap.make_trade(token_address, eth, token_balance_wei)    print(f"Transaction hash: {tx.hex()}")
You must be logged in to vote

Replies: 5 comments 1 reply

Comment options

Thanks for that

You must be logged in to vote
0 replies
Comment options

Thank you for the information

You must be logged in to vote
0 replies
Comment options

very usefull

You must be logged in to vote
1 reply
@AL-THE-BOT-FATHER
Comment options

So the code doesn't include slippage, accounting for taxes or gas strategies...

I found the code fails often when the network is congested...

Comment options

Thanks for the useful information!

You must be logged in to vote
0 replies
Comment options

It is very important

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Labels
None yet
6 participants
@AL-THE-BOT-FATHER@altcoin31@dimonachi@Cobra2911@olvida@Avkubs

[8]ページ先頭

©2009-2025 Movatter.jp