- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开始使用 Ethereum 和 Web3py,我希望在 specific address 上发生交易时发生交易。为了做到这一点,我注册了 infura 并获得了我的项目 ID。所以这是我尝试过的:
from web3 import Web3
import asyncio
import websockets
ABI = {"inputs":[{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"_WETH","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"WETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"},{"internalType":"uint256","name":"amountADesired","type":"uint256"},{"internalType":"uint256","name":"amountBDesired","type":"uint256"},{"internalType":"uint256","name":"amountAMin","type":"uint256"},{"internalType":"uint256","name":"amountBMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"addLiquidity","outputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"amountB","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountTokenDesired","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"addLiquidityETH","outputs":[{"internalType":"uint256","name":"amountToken","type":"uint256"},{"internalType":"uint256","name":"amountETH","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"reserveIn","type":"uint256"},{"internalType":"uint256","name":"reserveOut","type":"uint256"}],"name":"getAmountIn","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"reserveIn","type":"uint256"},{"internalType":"uint256","name":"reserveOut","type":"uint256"}],"name":"getAmountOut","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"}],"name":"getAmountsIn","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"}],"name":"getAmountsOut","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"reserveA","type":"uint256"},{"internalType":"uint256","name":"reserveB","type":"uint256"}],"name":"quote","outputs":[{"internalType":"uint256","name":"amountB","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountAMin","type":"uint256"},{"internalType":"uint256","name":"amountBMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"removeLiquidity","outputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"amountB","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"removeLiquidityETH","outputs":[{"internalType":"uint256","name":"amountToken","type":"uint256"},{"internalType":"uint256","name":"amountETH","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"removeLiquidityETHSupportingFeeOnTransferTokens","outputs":[{"internalType":"uint256","name":"amountETH","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bool","name":"approveMax","type":"bool"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"removeLiquidityETHWithPermit","outputs":[{"internalType":"uint256","name":"amountToken","type":"uint256"},{"internalType":"uint256","name":"amountETH","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bool","name":"approveMax","type":"bool"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"removeLiquidityETHWithPermitSupportingFeeOnTransferTokens","outputs":[{"internalType":"uint256","name":"amountETH","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountAMin","type":"uint256"},{"internalType":"uint256","name":"amountBMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bool","name":"approveMax","type":"bool"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"removeLiquidityWithPermit","outputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"amountB","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapETHForExactTokens","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactETHForTokens","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactETHForTokensSupportingFeeOnTransferTokens","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactTokensForETH","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactTokensForETHSupportingFeeOnTransferTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactTokensForTokens","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactTokensForTokensSupportingFeeOnTransferTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"amountInMax","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapTokensForExactETH","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"amountInMax","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapTokensForExactTokens","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}
def handle_event(event):
# Define data from the event
print(event)
async def log_loop(event_filter, poll_interval):
while True:
for event in event_filter:
handle_event(event)
await asyncio.sleep(poll_interval)
def main():
w3 = Web3(Web3.WebsocketProvider(f'wss://mainnet.infura.io/ws/v3/<MY-PRIJECT>'))
uniswap = w3.eth.contract('0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D', abi=ABI)
block_filter = uniswap.events.getLogs.createFilter(fromBlock = 'latest').get_all_entries()
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(asyncio.gather(log_loop(block_filter, 2)))
finally:
loop.close()
if __name__ == '__main__':
main()
响应是这样的:
("The event 'getLogs' was not found in this contract's abi. ", 'Are you sure you provided the correct contract abi?')
我也尝试使用 Infura 做到这一点:
import asyncio
import websockets
async def connect():
uri = "wss://mainnet.infura.io/ws/v3/<MY-PROJECT>"
async with websockets.connect(uri) as ws:
await ws.send('{"jsonrpc":"2.0", "id": 1, "method": "eth_subscribe", "params": ["logs", {"address": "0x7a250d5630b4cf539739df2c5dacb4c659f2488d"}]}')
while True:
msg = await ws.recv()
message = json.loads(msg)
print(message)
asyncio.get_event_loop().run_until_complete(connect())
但这没有给我任何东西。
最佳答案
正如 this answer 中所述,使用像 Etherscan API 这样的集中式工具来完成这样的任务更简单/更快。
假设此解决方案适合您,那么获得您要查找的内容非常简单:
import json
import time
import requests
# Place your own Etherscan API key here
ETHERSCAN_API_KEY =
ADDRESS = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"
def get_last_block():
return int(json.loads(requests.get(
f"https://api.etherscan.io/api?module=block&action=getblocknobytime×tamp={round(time.time())}&closest=before&apikey={ETHERSCAN_API_KEY}"
).text)["result"])
def get_last_txs(since=2):
return json.loads(requests.get(
f"https://api.etherscan.io/api?module=account&action=txlist&address={ADDRESS}&startblock={get_last_block() - since}&sort=asc&apikey={ETHERSCAN_API_KEY}"
).text)["result"]
txs = get_last_txs()
在 shell 中,您将获得以下行为:
>>> type(txs)
<class 'list'>
>>> len(txs)
60
>>> txs[0]
{'blockNumber': '11887758', 'timeStamp': '1613743087', 'hash': '0xacb6ba33c7fc4d8db7ad8ba4b09263ed0e6c2050842d189ba09b8a06b81ebc32', 'nonce': '25', 'blockHash': '0xebf1b16b9bccfb2dab43a304dfe2fb3d6c80d714669fd7bb651af98d497ddbea', 'transactionIndex': '56', 'from': '0xd8f19c1fd2916e10f0460976e57251d5a42e394f', 'to': '0x7a250d5630b4cf539739df2c5dacb4c659f2488d', 'value': '0', 'gas': '198839', 'gasPrice': '191000000000', 'isError': '0', 'txreceipt_status': '1', 'input': '0x18cbafe500000000000000000000000000000000000000000000000000000010245204950000000000000000000000000000000000000000000000000f58f2fc4900d7e700000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000d8f19c1fd2916e10f0460976e57251d5a42e394f00000000000000000000000000000000000000000000000000000000602fc89e000000000000000000000000000000000000000000000000000000000000000200000000000000000000000068a0a1fef18dfcc422db8be6f0f486dea1999edc000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', 'contractAddress': '', 'cumulativeGasUsed': '3396885', 'gasUsed': '155481', 'confirmations': '3'}
>>> txs[-1]
{'blockNumber': '11887760', 'timeStamp': '1613743113', 'hash': '0x6228f262db37a2eeaba16869e45cb0e632bb1a2f301bda57fd9c7c54a2abe26b', 'nonce': '763', 'blockHash': '0x3352a2613fd38d1a4e90d8cac7f89df6f0fdfe3b9b7f20557b7d60b2e3fd643e', 'transactionIndex': '214', 'from': '0xe4fb9ca52e39b83be69e74e7fac8f807a9c16ef9', 'to': '0x7a250d5630b4cf539739df2c5dacb4c659f2488d', 'value': '0', 'gas': '174926', 'gasPrice': '148832420000', 'isError': '1', 'txreceipt_status': '0', 'input': '0x18cbafe5000000000000000000000000000000000000000000000001158e460913d0000000000000000000000000000000000000000000000000000009c18457fae1609800000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000e4fb9ca52e39b83be69e74e7fac8f807a9c16ef900000000000000000000000000000000000000000000000000000000602fc3080000000000000000000000000000000000000000000000000000000000000002000000000000000000000000260e63d91fccc499606bae3fe945c4ed1cf56a56000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', 'contractAddress': '', 'cumulativeGasUsed': '11747610', 'gasUsed': '23683', 'confirmations': '1'}
然后,您可以自由地对这些交易做任何您想做的事情。当然,您可以查找 Etherscan API 以获取您想要获取的任何其他信息。不过要小心,因为您被限制为 5 个请求/秒。这就是
since
参数显示有用的原因:您可以每 10 秒发出 1 个请求,但考虑到最后 2 或 3 个块,您肯定不会错过任何交易。您还必须考虑 API 最多返回 10000 笔交易的事实,因此如果您想要此合约的完整交易历史记录,您必须以 10000 x 10000 的比例获得它们。
关于Python - 如何获得以太坊交易?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66186408/
我听过很多次公司喜欢HBase的强一致性。我阅读了 HBase 并喜欢它。然后我想到了mongodb write和那时候的区别。查了一下MongoDB似乎也有很强的一致性。但它是一致的吗?看起来 HB
区块链入门 ③ - 交易 交易 概述 比特币交易本质上包含交易参与者价值转移的相关信息数据结构。比特币区块链是一本全球复式记账总账簿,每笔交易都是在比特币区块链上的一个公开记录.
我有以下情况: 我正在迭代我的Affiliate 实体,对于每个实体,我需要在一个唯一的事务中保存和更新数据。因此,我有一个服务,其方法用 Spring @Transactional 注释(其中创建和
我无法理解 DaoManager 的默认行为。 DaoManager.createDao(connectionSource, theClass); 这需要一个 connectionSource - 而
我是 Spring 新手,有一个关于事务的问题。 我知道对于每个 http 请求都有一个 servlet 线程,它有自己的堆栈。据我所知,所有局部变量和方法都驻留在堆栈上。因此,如果我有一个方法 pu
我想设计一个简单的应用程序(没有 j2ee 和 jms),可以处理大量消息(比如在交易系统中) 我创建了一个服务,可以接收消息并将它们放入队列中,这样系统就不会在过载时卡住。 然后我创建了一个包装队列
如果使用 PDO 事务,是否需要锁定表? 如果用户 a 有 50 笔钱,将 50 笔转给用户 b,PDO 交易是否会确保它们都无误地执行? 另外,如果说我有一个 if 语句, if ($user['m
我正在实现一个方法,它会做类似的事情: ... try { myPojo.setProperty("foo"); myService.execute(myPojo); } catch (E
我正在尝试使用 ActiveRecord::Base.transaction。我认为使用 Rails 1.2.6 和 mysql 5.0 默认情况下回滚不起作用。多玩一点我发现 autocommit
我在我的网站上使用嵌入式支付,支付交易直接从买家到卖家发起,服务充当 API 调用方。商品价格由卖家以美元设定,以简化国际贸易。 当发件人和收件人都是俄罗斯居民时,发件人会收到错误消息: The pa
如果我删除我的应用程序中的数据,然后重新购买一些我知道该帐户已经拥有的托管 IAP,iOS 会给我原生的“您确定要重新购买该项目吗?您不会被收取费用”对话框。这符合预期。 当购买返回到我的应用程序时,
我一直在阅读 transactions & jooq但我很难看到如何在实践中实现它。 假设我为 JOOQ 提供了一个自定义 ConnectionProvider,它恰好使用了一个自动提交设置为 fal
我们正在使用 Entity Framework 并在事务范围内运行单元测试。我们最初在标题中遇到错误。 我已经设法将问题隔离开来。 using (TransactionScope scope1 = n
我有一个注册页面,基本上我需要将数据插入到 4 个表中。我是 PDO 的新手,对某些事情感到困惑。 基本上,如果任何插入失败,我不想向数据库中添加任何内容,这看起来很简单。 我的困惑是,我需要首先在我
我使用枢轴点进行交易。我在屏幕指示器上使用以下指标“CM_Pivots_Filtered”、“Pivots”、“CD_PivotR”和“CM_Gaps_Intra-Day_V2.1”。这些枢轴工作得很
我正在努力解决 Sonar 问题: squid:S2229 "Methods should not call same-class methods with incompatible "@Transa
在我的 Controller 中,我有一些类似的代码... ... if user.save something = Something.where("thing = ?", thing)
我使用 StoreKit 进行应用内购买。我发现当用户按下“取消”按钮时,API 的行为很奇怪。 例如,如果我在“确认您的应用内购买”屏幕上按“取消”,我会收到一个带有 error.code == S
AppStore 在自动续订自动续订订阅时是否会发出交易?如果是这样,如果应用程序将自己设置为观察者,那么下次应用程序加载时是否可以可靠地检测到它: [[SKPaymentQueue defaultQ
我正在研究 EMV 技术,并寻找终端和发行者之间的通信(请求/响应)以进行授权/在线 PIN 检查。 我知道离线数据验证仅在终端上进行检查,然后终端将数据发送给发行者。我想知道授权过程需要发送哪些数据
我是一名优秀的程序员,十分优秀!