【BSC】使用Python玩转PancakeSwap(入门篇)

这篇具有很好参考价值的文章主要介绍了【BSC】使用Python玩转PancakeSwap(入门篇)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

需求

最近我们需要在BSC上实现代币的自动化兑换,比如自动把BNB兑换成USDT,自动把USDT兑换成CAKE等其它代币,同时也要监视价格,在价格合适的时候再兑换代币。而PancakeSwap正是BSC上最大的去中心化平台,我们已经学会了手动在PancakeSwap上进行代币兑换,那么如何使用Python对这个操作进行自动化呢?

快速学习法

本文从新手的角度,讲解如何在面对一个从来没接触过的新事物时,快速上手做出东西来。
我们在学习一些新知识,新编程语言,新框架的时候,往往会陷入一个误区,就是总想一来就要把东西从头到尾的啃透,在网上找了一大堆资料、书籍、视频,然后正襟危坐的从第一页开始学起,过不了多久,就会越来越枯燥,越来越疲惫,从而半途而费。

多年来我总结出了一种快速学习法,就是先借助搜索引擎看个大概,对目标事物有个基本了解,然后就直接动手开始操练,刚开始肯定是写的磕磕绊绊,但是不要紧,边写边查边改,慢慢摸索,很快就能写出个勉强能用的东西,接下来再慢慢改进,不断优化,最终改成一份能放入产品的代码,此时基本用法已经学到个七七八八了,再越到类似需求则可以融会贯通,快速做出东西。

调用合约

要实现在PancakeSwap上的自动化需求,首先我们了解到,PancakeSwap的底层是一套智能合约。那么第一步我们的目标就是学会使用Python调用智能合约。

通过一番搜索我们找到了一个名为【web3.py】的库,正是做这个事情的。

初略阅读一下【web3.py】的文档,我们直接看调用合约的部分:
https://web3py.readthedocs.io/en/v5/contracts.html#contractcaller
文档中有大量的示例可以参考:
https://web3py.readthedocs.io/en/v5/examples.html

接下来马上动手操练,写一个调用合约的代码,比如调用BUSD的合约,查询我们的BUSD余额。

我们在BSC浏览器上找到BUSD的合约地址:
https://bscscan.com/address/0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56#readContract

pancake getamountsout,区块链,python,区块链,Web3,web3.py

在下方的【Contract】选项卡,我们可以看到该合约的方法,其中【Read Contract】是只读方法,用于查询一些数据,不需要签名即可调用,【Write Contract】是写入方法,需要签名授权才可以调用,我们可以直接在这边页面手动测试,比如上图中,在【balanceOf】方法中输入我们的钱包地址,点击【Query】按钮就可以查出我们的余额,由于USDT有18位小数精度,所以这个数值需要除以 10^18,就可以得到人类可读的余额约为 35.026 BUSD。其实这是一个标准的ERC20代币合约,在BSC上也称为【BEP20 Token】 标准,有着统一的ABI接口,但先不用了解那么多,我们直接上手,使用Python的【web3.py】库,调用这个合约的【balanceOf】方法:

import web3
from decimal import Decimal
import json

client = web3.Web3(web3.HTTPProvider("https://bsc-dataseed1.binance.org"))

address_busd = "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56"

abi_busd = json.loads(r'[{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"constant":true,"inputs":[],"name":"_decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]')


def main():
    contract = client.eth.contract(address = address_busd, abi = abi_busd)
    balance = contract.caller.balanceOf("0xeaC7d998684F50b7A492EA68F27633a117Be201d")
    balance = Decimal(balance) / (10 ** 18)
    print(balance)


if __name__ == '__main__':
    main()

执行结果:
pancake getamountsout,区块链,python,区块链,Web3,web3.py
果然成功调用合约拿到了余额数字

合约ABI

代码其中有个参数是abi_busd,即BUSD这个合约的ABI,这个ABI从哪里来呢,依然是在BSC浏览器里面查询合约地址就可以找到:
https://bscscan.com/address/0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56#code

pancake getamountsout,区块链,python,区块链,Web3,web3.py
在【Contract】的【Code】里可以找到它的ABI,是一个JSON,复制出来即可。

ABI我们可以理解为对该合约所有公开方法的描述,它声明了函数名,函数参数个数、类型,返回值,这样在调用该合约的时候才能正确的序列化参数以及获取返回值,不难理解为什么要有这么个东西,想想在Windows上的C++开发中,很多第三方闭源库都是提供一个DLL文件和一个 .h头文件和一个 .lib 导入库,.h里的函数定义就如同这些JSON ABI,描述每个函数的函数名和参数,我们才能正确调用,至于C# 的DLL为什么可以直接调用而不需要接口描述文件,那是因为它的接口描述信息已经写到了DLL中,可以直接从DLL文件读取。

那么这个合约的ABI文件,除了从BSC浏览器中手动复制,有没有办法从网络上获取呢?当然是有的,【bscscan】提供了很多API其中就包括获取合约ABI的API,文档在此:
https://docs.bscscan.com/api-endpoints/contracts

import web3
from web3.middleware import geth_poa_middleware
from decimal import Decimal
import requests

client = web3.Web3(web3.HTTPProvider("https://bsc-dataseed1.binance.org"))

# 连接公共节点需要注入此中间件
client.middleware_onion.inject(geth_poa_middleware, layer=0)

# 我们的钱包地址
address_wallet = "0xeaC7d998684F50b7A492EA68F27633a117Be201d"
# 私钥从环境变量获取
private_key = os.getenv("key")

# BUSD合约地址
address_busd = "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56"

# pancakeswap合约地址
address_pancakeswap = "0x10ED43C718714eb63d5aA57B78B54704E256024E"

# 获取合约ABI
def fetch_abi(address):
    url = "https://api.bscscan.com/api"
    params = {
        "module": "contract",
        "action": "getabi",
        "address": address,
        "apikey": "6HQZV977GIY8FNT36XN1JJSE12IP2IYVTQ",
    }
    resp = requests.get(url, params = params).json()
    return resp["result"]

# 获取账户ERC20代币余额
def erc20_balance(address_erc20: str, wallet: str) -> Decimal:
    abi_busd = fetch_abi(address_erc20)
    contract = client.eth.contract(address=address_erc20, abi=abi_busd)
    # 先获取该代币精度
    decimals = contract.functions.decimals().call()
    # 获取代币余额
    balance = contract.functions.balanceOf(wallet).call()
    balance = Decimal(balance) / (10 ** decimals)
    return balance

def main():
    balance = erc20_balance(address_busd, address_wallet)
    print(balance)

if __name__ == '__main__':
    main()

于是我们写了一个Python函数用于从网上获取ABI,这样在调用不同合约的时候,就不用一一手动复制ABI了。

注意上面的 apikey 是 bscscan.com 的 apikey ,我们可以在这里注册账号免费申请:https://bscscan.com/apis

免费版的 apikey 一天可以调用10万次 bscscan API,足够使用了。

不过这种从网上获取ABI的方式,在项目实践中最好获取一次然后缓存到本地,可以存到数据库也可以存到文本文件,总之每调用一次合约函数,就要发送HTTP请求获取一次ABI,是不太明智的选择,当然我们现在是学习阶段,这样简单写一写也无妨。

授权

接下来,我们需要调用 PancakeSwap 合约,实现代币的兑换,以BUSD兑换CAKE为例,最简单快速的方法,就是直接去 PancakeSwap 网页上手动发起一笔交易,待交易成功后,到BSC浏览器里查看链上的交易记录,看它调用了哪个合约的哪个方法,传递了什么参数,然后使用Python写代码,照葫芦画瓢即可。
pancake getamountsout,区块链,python,区块链,Web3,web3.py
首先,在 PancakeSwap 第一次交易某种代币时,需要授权,这个授权实际上是调用 BUSD 合约的【approve】方法,将我们账户的BUSD授权给 PancakeSwap 的合约进行支配,这样在接下来的兑换交易中,PancakeSwap 的合约才有权从我们账户中提取我们的BUSD代币,然后缓存CAKE代币转给我们。这个授权该如何用Python去实现呢?最简单的方法是直接提交交易,然后到BSC浏览器查询这笔交易:
https://bscscan.com/tx/0x6bdb716c91b4446dc9f66305578569241eb6b3ee058d943730a9ff3645f7994f#eventlog
pancake getamountsout,区块链,python,区块链,Web3,web3.py
在 Logs 这里我们可以看到这笔授权交易调用了
0xe9e7cea3dedca5984780bafc599bd69add087d56 合约(BUSD合约)的 Approval 方法
pancake getamountsout,区块链,python,区块链,Web3,web3.py
在【Overview】中我们可以看到传递的两个参数值是什么

再到BSC浏览器中查看BUSD的合约方法:
pancake getamountsout,区块链,python,区块链,Web3,web3.py
确实有【approve】这个方法,我们也可以直接在这里输入一样的参数进行手动测试,以验证结果。网上搜索资料,我们可以了解到这两个参数的意思,【spender】就是授权给谁,这里是授权给PancakeSwap的合约地址,【amount】是授权金额,图片里的这个值就是uint256的最大值,最终结果就等同于【无限制】。

接下来我们用Python代码实现这个授权操作:

import web3
from web3.middleware import geth_poa_middleware
from decimal import Decimal
import requests

client = web3.Web3(web3.HTTPProvider("https://bsc-dataseed1.binance.org"))

# 连接公共节点需要注入此中间件
client.middleware_onion.inject(geth_poa_middleware, layer=0)

# 我们的钱包地址
address_wallet = "0xeaC7d998684F50b7A492EA68F27633a117Be201d"
# 私钥从环境变量获取
private_key = os.getenv("key")

# BUSD合约地址
address_busd = "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56"

# pancakeswap合约地址
address_pancakeswap = "0x10ED43C718714eb63d5aA57B78B54704E256024E"

# 获取合约ABI
def fetch_abi(address):
    url = "https://api.bscscan.com/api"
    params = {
        "module": "contract",
        "action": "getabi",
        "address": address,
        "apikey": "6HQZV977GIY8FNT36XN1JJSE12IP2IYVTQ",
    }
    resp = requests.get(url, params = params).json()
    return resp["result"]

# 授权pancakeswap合约使用我们账户的BUSD代币
def approve_busd_to_pancakeswap(wallet: str):
    abi_busd = fetch_abi(address_busd)
    contract = client.eth.contract(address=address_busd, abi=abi_busd)
    txn = contract.functions.approve(address_pancakeswap, 2 ** 256 - 1).build_transaction({
        "chainId": client.eth.chain_id,
        "from": wallet,
        "nonce": client.eth.get_transaction_count(wallet),
        "gasPrice": client.eth.gas_price
    })
    signed_txn = client.eth.account.sign_transaction(txn, private_key)
    txn_hash = client.eth.send_raw_transaction(signed_txn.rawTransaction)
    txn_hash = client.toHex(txn_hash)
    return txn_hash

def main():
    txn_hash = approve_busd_to_pancakeswap(address_wallet)
    print(txn_hash)

if __name__ == '__main__':
    main()

查询价格

授权完成后,在进行兑换交易之前,我们需要先查询兑换价格,这样才能确定多少代币可以兑换多少另一种代币,我们以BUSD购买CAKE为例,先查询一个BUSD可以买多少个CAKE。

我们先在BSC浏览器中找到 PancakeSwap 的合约地址:
https://bscscan.com/address/0x10ed43c718714eb63d5aa57b78b54704e256024e#readContract
pancake getamountsout,区块链,python,区块链,Web3,web3.py
同理,我们在下方的【Contract】【Read Contract】中可以测试该合约的所有可读方法,其中【getAmountsOut】方法就是用于查询多少A代币可以兑换多少B代币的函数,我们可以直接在这里手动测试,其中【amountIn】参数就是输入多少A代币,【path】参数就是兑换路径,这是一个数组,这里我们填入BUSD的合约地址和CAKE的合约地址即可,表示直接从BUSD兑换成CAKE,因为这两个代币之间有一个很大的流动性池子,可以直接兑换。有的时候,要兑换的两种代币之间没有池子,则需要将A先换成B再换成C,这个时候【path】就有三个元素,分别是A/B/C代币的合约地址。
pancake getamountsout,区块链,python,区块链,Web3,web3.py
比如要把HIGH兑换成CAKE,由于HIGH和CAKE之间没有池子,所以需要先讲HIGH换成BUSD再换成CAKE,那么【path】就需要三个元素,分别是HIGH/BUSD/CAKE的合约地址。

弄清楚大致原理后,我们就可以着手写Python代码如下:

import web3
from web3.middleware import geth_poa_middleware
from decimal import Decimal
import requests

client = web3.Web3(web3.HTTPProvider("https://bsc-dataseed1.binance.org"))

# 连接公共节点需要注入此中间件
client.middleware_onion.inject(geth_poa_middleware, layer=0)

# 我们的钱包地址
address_wallet = "0xeaC7d998684F50b7A492EA68F27633a117Be201d"

# BUSD合约地址
address_busd = "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56"

# CAKE合约地址
address_cake = "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82"

# pancakeswap合约地址
address_pancakeswap = "0x10ED43C718714eb63d5aA57B78B54704E256024E"

# 获取合约ABI
def fetch_abi(address):
    url = "https://api.bscscan.com/api"
    params = {
        "module": "contract",
        "action": "getabi",
        "address": address,
        "apikey": "6HQZV977GIY8FNT36XN1JJSE12IP2IYVTQ",
    }
    resp = requests.get(url, params = params).json()
    return resp["result"]

# 查询CAKE与BUSD兑换价格
def query_cake_price() -> Decimal:
    abi_pancakeswap = fetch_abi(address_pancakeswap)
    contract = client.eth.contract(address=address_pancakeswap, abi=abi_pancakeswap)
    price = contract.functions.getAmountsOut(1 * 10 ** 18, [address_busd, address_cake]).call()
    return Decimal(price[1]) / (10 ** 18)

def main():
    price = query_cake_price()
    print(price)

if __name__ == '__main__':
    main()

执行结果:
pancake getamountsout,区块链,python,区块链,Web3,web3.py
可以看到,执行结果为,1个BUSD可以换约0.2535个CAKE
需要注意的是,函数中的 10 ** 18,因为我们知道 BUSD 和 CAKE 的精度都是18位小数,所以我们在这里直接写死了,在实际项目中需要根据你的情况更改。

兑换交易

接下来最后一步就是进行兑换交易了,我们可以先手动兑换一笔,然后查看交易记录:
https://bscscan.com/tx/0x71f5d27d08803ca834b685c86b7f8a2b72039b468fc6600256a18e8ba0c7a173
pancake getamountsout,区块链,python,区块链,Web3,web3.py
我们可以看到它调用了 PancakeSwap 合约的 【swapExactTokensForTokens】方法,【Decode Input Data】后可以看到传递的参数是什么:
pancake getamountsout,区块链,python,区块链,Web3,web3.py
有同学就要问了,你怎么知道 PancakeSwap 合约的这些方法和参数是什么含义呢?包括上面的【getAmountsOut】方法,答案就在PancakeSwap的文档中,解释得很清楚了:
https://docs.pancakeswap.finance/code/smart-contracts/pancakeswap-exchange/v2/router-v2

接下来我们用 Python 代码实现兑换操作:

import web3
from web3.middleware import geth_poa_middleware
from decimal import Decimal
import requests
from datetime import datetime, timedelta

client = web3.Web3(web3.HTTPProvider("https://bsc-dataseed1.binance.org"))

# 连接公共节点需要注入此中间件
client.middleware_onion.inject(geth_poa_middleware, layer=0)

# 我们的钱包地址
address_wallet = "0xeaC7d998684F50b7A492EA68F27633a117Be201d"
# 私钥从环境变量获取
private_key = os.getenv("key")

# BUSD合约地址
address_busd = "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56"

# CAKE合约地址
address_cake = "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82"

# pancakeswap合约地址
address_pancakeswap = "0x10ED43C718714eb63d5aA57B78B54704E256024E"

# 获取合约ABI
def fetch_abi(address):
    url = "https://api.bscscan.com/api"
    params = {
        "module": "contract",
        "action": "getabi",
        "address": address,
        "apikey": "6HQZV977GIY8FNT36XN1JJSE12IP2IYVTQ",
    }
    resp = requests.get(url, params = params).json()
    return resp["result"]

# 将BUSD兑换为CAKE
def swap_busd_to_cake(wallet: str, amount_busd: Decimal):
    abi_pancakeswap = fetch_abi(address_pancakeswap)
    contract = client.eth.contract(address=address_pancakeswap, abi=abi_pancakeswap)
    price_cake = contract.functions.getAmountsOut(1 * 10 ** 18, [address_busd, address_cake]).call()
    price_cake = Decimal(price_cake[1]) / (10 ** 18)
    # 滑点0.5% 交易手续费 0.25% ,则最小换得的cake数量为理论换得的cake数量 乘 99.25 %
    amount_cake_min = int(price_cake * amount_busd * Decimal("0.9925") * 10 ** 18)
    amount_busd = int(amount_busd * 10 ** 18)
    # deadline为交易必须在此时间前确认,否则交易失败,我们在pancakeswap网页上手动操作的时候默认是20分钟,所以照着它来
    deadline = datetime.now() + timedelta(minutes = 20)
    txn = contract.functions.swapExactTokensForTokens(amount_busd, amount_cake_min, [address_busd, address_cake], wallet, int(deadline.timestamp())).build_transaction({
        "chainId": client.eth.chain_id,
        "from": wallet,
        "nonce": client.eth.get_transaction_count(wallet),
        "gasPrice": client.eth.gas_price
    })
    signed_txn = client.eth.account.sign_transaction(txn, private_key)
    txn_hash = client.eth.send_raw_transaction(signed_txn.rawTransaction)
    txn_hash = client.toHex(txn_hash)
    return txn_hash

def main():
    txn_hash = swap_busd_to_cake(address_wallet, Decimal("1.0"))
    print(txn_hash)

if __name__ == '__main__':
    main()

执行以后,交易成功,perfect !
https://bscscan.com/tx/0xbb7de1e37f332bd8114ba8d58cf3a13226d76194dc8cc08f3e7dac9ba00df4a0
pancake getamountsout,区块链,python,区块链,Web3,web3.py

完整示例代码

【python_pancakeswap】https://github.com/encoderlee/python_pancakeswap文章来源地址https://www.toymoban.com/news/detail-776944.html

到了这里,关于【BSC】使用Python玩转PancakeSwap(入门篇)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 100天玩转python——day67 使用Selenium抓取网页动态内容

    根据权威机构发布的全球互联网可访问性审计报告,全球约有四分之三的网站其内容或部分内容是通过JavaScript动态生成的,这就意味着在浏览器窗口中“查看网页源代码”时无法在HTML代码中找到这些内容,也就是说我们之前用的抓取数据的方式无法正常运转了。解决这样的

    2024年02月09日
    浏览(56)
  • XR2 Pancake VR下的Unity Launcher优化

    表现优化 纹理优化 在游戏中,纹理是占用大量内存和显存的重要资源。为了优化性能,我们可以考虑以下措施: 压缩纹理:使用适当的纹理压缩格式,如ETC、ASTC或BC等,以减少纹理占用的内存和显存。 减小纹理尺寸:根据实际需求,将纹理的分辨率调整到合适的大小,避免

    2024年01月20日
    浏览(38)
  • PICO 4评测:Pancake光学新标杆,VR娱乐VR健身就选它

    最近一年多时间里,国内消费级VR环境发生了不小的变化,各个品牌纷纷发布VR一体机,给了国内玩家不同于PC VR的新选择,而这一切则源自于PICO Neo3的发布。Neo3可以说是打开了国内双6DoF VR一体机市场,在自研光学追踪算法和内容引进上加大投入,实现了用户规模的大幅增长

    2023年04月09日
    浏览(39)
  • pancakeswap批量抢跑机器

    这个机器人主要是用来在pancakeswap开盘时抢先购买token。 界面图 完整代码是用vue写的,现在先来个学习版的方便小白理解 这个学习版只有单个抢先的功能,完整版在GitHub 核心代码讲解: 调用swapExactTokensForTokens和swapExactETHForTokens进行转账操作 原vue写的网页完整版在这里:ht

    2024年02月12日
    浏览(35)
  • 区块链-PancakeSwap抢跑机器人

    监听txpool,直到检测匹配符合我们的条件时购买 提高gas费实现插队 ethers或web3,本文采用ethers erc20 1、通过ehters提供的监听方法,监听链上的pending事件 2、通过 swapETHForExactTokens 实现bnb交换对应的代币,如果非bnb交易池,例如是busd交易池,则需要用swapExactTokensForTokens,交换对

    2024年02月15日
    浏览(36)
  • 玩转数据可视化,从入门到精通 Echarts

    如今,数据已成为企业和个人不可或缺的资源。然而,无论数据的来源、体量和种类如何,作为人类的我们有时会感到“数据山海苍茫,看不清真假蒙蔽双眼”。而数据可视化正是帮助我们解决这一问题的利器之一。其中, Echarts 作为当前最为流行的前端可视化库之一,其简

    2024年02月05日
    浏览(102)
  • pancakeswap 开盘抢跑机器人 (附代码)

    这个机器人主要就是抢跑用的:机器人一次只能狙击一个令牌。 WBNB_CONTRACT=0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c 购买代币的 WBNB 合约 FACTORY=0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73 Pancake Factory 合约获得购买功能 ROUTER=0x10ED43C718714eb63d5aA57B78B54704E256024E Pancake Factory 合约处理购买功能 YOUR_AD

    2024年02月02日
    浏览(34)
  • 深入解析Pancakeswap Prediction|博饼预测玩法

    领取奖金有时间限制吗? 没有时间限制,可以在任何时间来领取。 利息是如何计算的? 上行池的支付比率=两个池的总价值÷上行池的价值 下行池的支付比率=两个池的总价值÷下行池的价值 例如,如果一轮的下线有15BNB,而总奖金池为150BNB,下线支付比率将为(150/15)=10x。

    2024年02月13日
    浏览(35)
  • 入门级教程 仅需四步帮你玩转无线网络

    你是一位资深的网虫吗?你家里的客厅、卧室、书房、厕所等等都能上网吗?你漂亮温馨的小天地里,没有那煞风景的网线吧?!如果前三个问题,你的回答都是YES!那好了,我接下来的这篇文章一定会对你大有帮助!如若能实现我上面所说的诸多事情,那么朋友们的家中肯定少不了

    2024年02月05日
    浏览(36)
  • 如何防止uniswap和pancakeswap夹子机器人

    被机器人夹是通俗说法 实际就是 front running(抢先提前交易) 具体就是机器人在链上嗅探到你有买入行为的时候,他立刻买,gas给的比你高,快你一步确认,这样你成交价就高了,因为交易所有滑点,所以你依旧会以高一点的价格成交并且再将价格推高一点,这时他再卖出,

    2024年01月16日
    浏览(34)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包