首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PancakeSwap执行恢复

PancakeSwap执行恢复
EN

Ethereum用户
提问于 2021-05-18 21:54:41
回答 1查看 3.1K关注 0票数 0

我一直在尝试编写在pancakeSwap上运行的机器人代码,由于某种原因,我尝试使用这个脚本的所有事务都会被恢复。

代码语言:javascript
复制
API_URL = 'https://data-seed-prebsc-1-s1.binance.org:8545/' #testnet
CONTRACT_ID = Web3.toChecksumAddress('0xc3f9c723ce06ee0fa420c8c88cee115fa0147748')

SENDER_ADDRESS = '00'
SENDER_PRIVATE_KEY = '00'

ROUTER_ADDRESS = '0xD99D1c33F9fC3444f8101754aBC46c52416550D1' #pancakeswap V2 router tesnet
Spend = Web3.toChecksumAddress('0xed24fc36d5ee211ea25a80239fb8c4cfd80f12ee') #spend binance 

Receive = CONTRACT_ID
max_approval_hex = f"0x{64 * 'f'}"
max_approval_int = int(max_approval_hex, 16)
w3 = Web3(Web3.HTTPProvider(API_URL))
contract = w3.eth.contract(address=ROUTER_ADDRESS, abi=ABI)

erc_20_contract = w3.eth.contract(address=Spend, abi=ERC20_ABI)
nonce = w3.eth.get_transaction_count(SENDER_ADDRESS)

#send coin to router
approve_txn = erc_20_contract.functions.transferFrom(SENDER_ADDRESS, ROUTER_ADDRESS, 1).buildTransaction({
    'from': SENDER_ADDRESS,
    'gas': w3.toWei('250000', 'wei'),
    'nonce':  nonce,
})
signed_txn = w3.eth.account.sign_transaction(approve_txn, private_key=SENDER_PRIVATE_KEY)
w3.eth.send_raw_transaction(signed_txn.rawTransaction)  

#approve the coin
approve_txn = erc_20_contract.functions.approve(ROUTER_ADDRESS, max_approval_int).buildTransaction({
    'from': SENDER_ADDRESS,
    'gas': w3.toWei('250000', 'wei'),
    'nonce': nonce + 1,
})
signed_txn = w3.eth.account.sign_transaction(approve_txn, private_key=SENDER_PRIVATE_KEY)
w3.eth.send_raw_transaction(signed_txn.rawTransaction)  

start = time.time()
pancakeswap_txn = contract.functions.swapExactTokensForTokens(
    100,
    10,
    [Spend, Receive],
    SENDER_ADDRESS,
    (int(time.time()) + 1000000)
).buildTransaction({
    'from': SENDER_ADDRESS,
    'gas': 100000,
    'gasPrice': w3.toWei('100', 'gwei'),
    'nonce':  nonce + 2,
})
signed_txn = w3.eth.account.sign_transaction(approve_txn, 
              private_key=SENDER_PRIVATE_KEY)
w3.eth.send_raw_transaction(signed_txn.rawTransaction)  

我试过批准和不批准,结果是一样的。我正在运行二进制TestNet,我的测试网钱包上有BNB。

EN

回答 1

Ethereum用户

回答已采纳

发布于 2021-05-19 03:48:16

嗯,我想出来了。原来我用的汽油太少了。

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/99231

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档