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

推荐订阅源

博客园_首页
Blog — PlanetScale
Blog — PlanetScale
腾讯CDC
aimingoo的专栏
aimingoo的专栏
Microsoft Azure Blog
Microsoft Azure Blog
A
About on SuperTechFans
J
Java Code Geeks
G
Google Developers Blog
N
Netflix TechBlog - Medium
Vercel News
Vercel News
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
罗磊的独立博客
GbyAI
GbyAI
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 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)  评论()    收藏  举报