⚡️ ENS Dart

一个包装以太坊名称服务 (ENS) 的 Dart 库。

以太坊名称服务 (ENS) 类似于域名服务 (DNS)。它允许用户和开发人员使用人类可读的名称来代替易出错的十六进制地址、内容哈希等。

  • web3dart 包进行互操作
  • 从 ETH 地址获取 ENS 名称
  • 从 ENS 名称获取地址
  • 获取 contentHash
  • 获取 textRecord
  • 调用 ENS 智能合约的函数并监听合约事件

用法

获取 ENS 名称和地址

ENS Dart 提供了一个接口,用于查找给定名称对应的地址,反之亦然,以及更多功能。

Future<void> main() async {
  env.load('../.env');
  final infuraKey = env.env['INFURA_KEY'];

  final rpcUrl = 'https://mainnet.infura.io/v3/$infuraKey';
  final wsUrl = 'wss://mainnet.infura.io/ws/v3/$infuraKey';

  final client = Web3Client(rpcUrl, Client(), socketConnector: () {
    return IOWebSocketChannel.connect(wsUrl).cast<String>();
  });

  /// ENS client
  final ens = Ens(client: client);

  /// Get name from address
  final name = await ens
      .withAddress('0x1a5cdcFBA600e0c669795e0B65c344D5A37a4d5A')
      .getName();

  /// Get address from name
  final addr = await ens.withName('brantly.eth').getAddress();

  /// Get text record
  final textRecord = await ens.getTextRecord();

  print('name: $name'); // addr: 0x324f9307b6d26881822c7c8692eeac39791a9756
  print('addr: $addr'); // name: sea.eth
  print(
      'textRecord: $textRecord');  /* EnsTextRecord {
      email: [email protected],
      url: http://brantly.xyz/,
      avatar: eip155:1/erc721:0xb7F7F6C52F2e2fdb1963Eab30438024864c313F6/2430,
      description: "If anyone would come after me, let him deny himself and take up his cross daily and follow me. For whoever would save his life will lose it, but whoever loses his life for my sake will save it. For what does it profit a man if he gains the whole world and loses or forfeits himself?" - Jesus, Luke 9.23-25,
      notice: Not for sale,
      keywords: ,
      com.discord: brantly.eth#9803,
      com.github: brantlymillegan,
      com.reddit: brantlymillegan,
      com.twitter: brantlymillegan,
      org.telegram: brantlymillegan,
      eth.ens.delegate: https://discuss.ens.domains/t/ens-dao-delegate-applications/815/697?u=brantlymillegan
    } 
}

GitHub

查看 Github