惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
量子位
腾讯CDC
月光博客
月光博客
博客园 - 【当耐特】
博客园 - 聂微东
罗磊的独立博客
aimingoo的专栏
aimingoo的专栏
D
DataBreaches.Net
Apple Machine Learning Research
Apple Machine Learning Research
F
Fortinet All Blogs
博客园 - Franky
爱范儿
爱范儿
L
LangChain Blog
云风的 BLOG
云风的 BLOG
TaoSecurity Blog
TaoSecurity Blog
N
News and Events Feed by Topic
Security Archives - TechRepublic
Security Archives - TechRepublic
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
Simon Willison's Weblog
Simon Willison's Weblog
Google DeepMind News
Google DeepMind News
S
Schneier on Security
H
Help Net Security
H
Heimdal Security Blog
The GitHub Blog
The GitHub Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Y
Y Combinator Blog
N
Netflix TechBlog - Medium
Microsoft Azure Blog
Microsoft Azure Blog
Cyberwarzone
Cyberwarzone
Cloudbric
Cloudbric
Recorded Future
Recorded Future
Hacker News: Ask HN
Hacker News: Ask HN
S
Security @ Cisco Blogs
Project Zero
Project Zero
AWS News Blog
AWS News Blog
Spread Privacy
Spread Privacy
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Securelist
Recent Announcements
Recent Announcements
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CERT Recently Published Vulnerability Notes
M
MIT News - Artificial intelligence
IT之家
IT之家
Google Online Security Blog
Google Online Security Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com

博客园 - daviyoung

Windows 11 22H2 安装 .NET Framework 3.5 完整教程 System.Threading.Timer 详细讲解 Agent 开发入门(一):从零构建你的第一个智能体 用 C# 开发一个解释器语言——基于《Crafting Interpreters》的实战系列(五)表达式求值 python使用plotly绘制图表 手把手搭建OPC UA服务器 图像处理库Pillow的使用:批量裁剪图片 python-docx库的使用:图片插入到word文档里 modbus(二)用NModbus4库实现Modbus tcp从站 Jenkins 容器化实践:Docker 部署与 CI/CD 流水线配置 Streamlit实战 用pycdc批量反编译pyc文件 虚拟环境下安装包后,vs code仍然有下滑波浪线及显示找不到包(运行是正常的)的解决办法 Merkle Tree 用 C# 开发一个解释器语言——基于《Crafting Interpreters》的实战系列(四)可视化 语法树 Solidity开发ERC20智能合约claim token的功能 Solidity开发ERC20智能合约demo及部署到测试网 用 C# 开发一个解释器语言——基于《Crafting Interpreters》的实战系列(三)表达式的抽象语法树设计(Expr) 用 C# 开发一个解释器语言——基于《Crafting Interpreters》的实战系列(二)词法分析器
以ENS 的 BaseRegistrarImplementation 合约为例,用web3.py调用合约
daviyoung · 2025-08-14 · via 博客园 - daviyoung
import time
from web3 import Web3
import json
from dotenv import load_dotenv
import os

# 读取环境变量
load_dotenv()
INFURA_KEY = os.getenv("INFURA_KEY")
BASE_REGISTRAR_ADDRESS = os.getenv("BASE_REGISTRAR_ADDRESS")

# 连接到以太坊主网
w3 = Web3(Web3.HTTPProvider(f'https://mainnet.infura.io/v3/{INFURA_KEY}'))

# 加载 BaseRegistrarImplementation 合约 ABI
with open('base_registrar_abi.json', 'r') as f:
    base_registrar_abi = json.load(f)

# 创建合约实例
base_registrar = w3.eth.contract(address=BASE_REGISTRAR_ADDRESS, abi=base_registrar_abi)

# 查询 ENS 域名的到期时间
label = "testensdomain"  # 域名前缀
label_hash = w3.keccak(text=label)                # 得到 bytes
token_id = int.from_bytes(label_hash, 'big')      # 转为 uint256

try:
    expiry_timestamp = base_registrar.functions.nameExpires(token_id).call()
    if expiry_timestamp == 0:
        print(f"{label}.eth 尚未注册")
    else:
        expiry_date = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(expiry_timestamp))
        print(f"{label}.eth 过期时间:{expiry_date} (UTC)")
except Exception as e:
    print(f"查询失败: {e}")

posted @ 2025-08-14 09:04  daviyoung  阅读(22)  评论()    收藏  举报