我正在使用 web3 和 python 构建一个工具,需要通过 PancakeSwap 快速准确地获取币安智能链上的代币价格。
该工具收集有关 BSC 代币、价格、流动性等信息,以便我可以进一步分析 rugpulls。
在下面的代码中,它提供了一个合约地址,并且需要提供 BNB 中每个代币的当前价格。然而,它出现了很多故障,并且没有给我正确的价格,我不知道出了什么问题。代码如下。
from web3 import Web3
web3 = Web3(Web3.WebsocketProvider('wss://speedy-nodes-nyc.moralis.io/b51e035eb24e1e81cc144788/bsc/mainnet/ws'))
tokenPriceABI = 'Token Price ABI'
def getTokenPrice(tokenAddress):
BNBTokenAddress = Web3.toChecksumAddress("0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c") # BNB
amountOut = None#
#tokenAddress = Web3.toChecksumAddress(tokenAddress)
tokenRouter = web3_sell.eth.contract(address=tokenAddress, abi=tokenPriceABI)
router = web3_sell.eth.contract(address=Web3.toChecksumAddress("0x10ed43c718714eb63d5aa57b78b54704e256024e"), abi=pancakeABI)
amountIn = web3_sell.toWei(1, 'ether')
amountOut = router.functions.getAmountsOut(amountIn, [tokenAddress, BNBTokenAddress]).call()
amountOut = web3_sell.fromWei(amountOut[1], 'ether')
return amountOut
tokenAddress = input("Enter token address: ")
tokenAddress = Web3.toChecksumAddress(tokenAddress)
priceInBnb = getTokenPrice(tokenAddress)
print(priceInBnb)
Run Code Online (Sandbox Code Playgroud)
有人能帮忙吗?谢谢。
经过几个小时的搜索,我设法运行了这段代码,但不幸的是,这并没有产生我想要的输出,即获取(TOKEN/BNB LP)中的 LP 池地址。
给定令牌地址:0xe56842ed550ff2794f010738554db45e60730371
我想获取 BIN/BNB 池地址:0xe432afB7283A08Be24E9038C30CA6336A7cC8218。
有什么想法可能是什么问题吗?
from web3 import Web3
from eth_abi.packed import encode_abi_packed
from eth_abi import encode_abi
import eth_abi
"""
Contract: 0xe56842ed550ff2794f010738554db45e60730371
BIN/BNB Address: 0xe432afB7283A08Be24E9038C30CA6336A7cC8218
BIN/BNB LP URL: https://bscscan.com/token/0xe432afB7283A08Be24E9038C30CA6336A7cC8218#balances
"""
CONTRACTS = {"CONTRACT": "0xe56842ed550ff2794f010738554db45e60730371",}
PANCAKE_SWAP_FACTORY = "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73"
PANCAKE_SWAP_ROUTER = "0x10ED43C718714eb63d5aA57B78B54704E256024E"
WBNB_ADDRESS = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"
hexadem_= '0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f'
factory = PANCAKE_SWAP_FACTORY
abiEncoded_1 = encode_abi_packed(['address', 'address'], (CONTRACTS['CONTRACT'], WBNB_ADDRESS))
salt_ = Web3.solidityKeccak(['bytes'], ['0x' +abiEncoded_1.hex()])
abiEncoded_2 = encode_abi_packed([ 'address', 'bytes32'], ( factory, salt_))
resPair = Web3.solidityKeccak(['bytes','bytes'], ['0xff' + abiEncoded_2.hex(), …Run Code Online (Sandbox Code Playgroud) 我有一个 erc20 代币,在另一个合约中我想创建一个代币交换功能。所以很容易,发送一个 usdc 代币并以 1:1 的比例交换我的 erc20 代币。问题是如何批准使用我的 erc20 代币。我尝试了几次但找不到方法。
interface IERC20 {...}
contract AnotherContract {
function approve(address _spender, uint256 _amount) public returns(bool) {
return IERC20(MyToken).approve(_spender, _amount);
}
Run Code Online (Sandbox Code Playgroud)
我部署了另一个合同,当我从中调用批准功能时。所以当我将“_spender”设置为这个合约地址时。结果很奇怪。所以这个合约既是所有者又是消费者。我认为用户应该是所有者,而这个合约应该是消费者。但是函数是从链上调用的。msg.sender 将是该合约地址本身。
我不明白并且很困惑。有人知道或者有一些资源吗?谢谢。
blockchain ethereum solidity smartcontracts binance-smart-chain
我正在基于 BEP20Token 模板(https://github.com/binance-chain/bsc-genesis-contract/blob/master/contracts/bep20_template/BEP20Token.template )创建智能合约(BEP20 代币)。公共构造函数被修改以添加一些令牌详细信息。然而,所有标准函数都会出现编译时问题,例如缺少覆盖函数。
**这是源代码**
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.2;
interface IBEP20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the token decimals.
*/
function decimals() external view returns (uint8);
/**
* @dev Returns the token symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the token name.
*/
function name() external view returns (string memory);
/**
* @dev …Run Code Online (Sandbox Code Playgroud) 我正在创建一个代币,想要解决拉高和转储的大鲸鱼问题,或者只是转储问题。因此,我考虑限制一个地址每笔交易或每 24 小时可以出售的数量。
这在 Bep20 智能合约中可能吗?我的编码员告诉我事实并非如此。如果是,这是否也会自动影响一个人可以购买的数量?
这种限制会带来未知的负面后果吗?
你会购买这种类型的代币吗?
最后,目前是否有任何 BEP20(或其他区块链)代币正在实现这一点?
感谢您的任何建议。
solidity smartcontracts cryptocurrency binance binance-smart-chain
我试图使用 web3.py 获取各种加密货币的价格。
tokenAddres = '0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82' #Cake
tokenAddres = Web3.toChecksumAddress(tokenAddres)
bnbPrice = calcBNBPrice()
print(f'current BNB price: {bnbPrice}')
priceInBnb = calcSell(1, tokenAddres)
print(f'SHIT_TOKEN VALUE IN BNB : {priceInBnb} | Just convert it to USD ')
print(f'SHIT_TOKEN VALUE IN USD: {priceInBnb * bnbPrice}')
Run Code Online (Sandbox Code Playgroud)
calcsell 函数应该是返回 BNB 中代币值的函数
def calcSell(tokenToSell, tokenAddress):
BNBTokenAddress = Web3.toChecksumAddress("0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c") # BNB
amountOut = None
tokenRouter = web3.eth.contract(address=Web3.toChecksumAddress(tokenAddress), abi=tokenAbi)
tokenDecimals = tokenRouter.functions.decimals().call()
tokenToSell = setDecimals(tokenToSell, tokenDecimals) # Set token a correct number of 0s
router = web3.eth.contract(address=Web3.toChecksumAddress(pancakeSwapContract), abi=pancakeSwapAbi)
amountIn …Run Code Online (Sandbox Code Playgroud) 如何即时追踪BSC网络中钱包的交易情况?(我正在考虑使用 web3 js。)
我不想使用 BSCscan 上的 api 来执行此操作。据我所知,它不会立即显示出来。
solidity ×4
python ×3
web3py ×3
binance ×2
ethereum ×2
blockchain ×1
node.js ×1
pancakeswap ×1
web3js ×1