LoginSignup
3
0

More than 1 year has passed since last update.

前書き

3年ほど前にRustでweb3を触りつつ、ENS(Ethereum Name Service)を紹介し、RustでENSを扱えるcrateを作ったのでした。

そして時は経ち、つい最近rust-ensのGitHubにこんなissueがあがりました。

要約すると、rust-web3の方にENS関連の機能を組み込んじゃうよ!?という内容でした。
私はrust-web3の方で使える方が良いのでやっちゃってください!!と返しました。

そして1週間程前に無事にpull-requestが取り込まれたようでした。
https://github.com/tomusdrw/rust-web3/pull/562

というわけでrust-web3でENSを触ってみます。

環境

Rust 1.56.1 stable
MacOSX 11.6 (Intel Mac)
rust-web3 https://github.com/tomusdrw/rust-web3/commit/1f807bb7c288a1d2668c691839381786065b2eac

使ってみる

$ cargo new rustens
$ cd rustens

まだENS扱える機能はcrate.ioには登録されていないので、gitのrev指定で使います。

Cargo.toml
[package]
name = "rustens"
version = "0.1.0"
edition = "2021"

[dependencies]
web3 = { git = "https://github.com/tomusdrw/rust-web3.git", rev = "1f807bb7c288a1d2668c691839381786065b2eac" }
tokio = "1.14.0"

ENS名 vitalik.eth のEthereumアドレスを表示してみることにします。

src/main.rs
use web3::contract::ens::Ens;
use web3::api::Namespace;

#[tokio::main]
async fn main() -> web3::Result<()> {
    let transport = web3::transports::Http::new("http://localhost:8545").unwrap();

    let ens_name = "vitalik.eth";

    let ens = Ens::new(transport);
    let addr = ens.eth_address(ens_name).await;
    println!("{:?}", addr);

    Ok(())
}
$ cargo run
Ok(0xd8da6bf26964af9d7eed9e03e53415d37aa96045)

無事 vitalik.eth のアドレスを得ることができました 👍

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0