Skip to content

Commit

Permalink
init commt
Browse files Browse the repository at this point in the history
  • Loading branch information
Zfinix committed Dec 31, 2021
0 parents commit 6eeb85e
Show file tree
Hide file tree
Showing 26 changed files with 3,274 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
**/.env
.env

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.packages
build/
10 changes: 10 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 262b70ece1aebf84f132c51ec4cf90be605ce61b
channel: beta

project_type: package
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## 1.0.0
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2022 Chiziaruhoma Ogbonda

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# ⚡️ ENS Dart

A dart library that wraps the Ethereum Name Service.

The Ethereum Name Service is analogous to the Domain Name Service. It enables users and developers to use human-friendly names in place of error-prone hexadecimal addresses, content hashes, and more.

- Interop with `web3dart` package
- Get ENS name from ETH address
- Get address from ENS name
- Get contentHash
- Get textRecord
- Call functions on ENS smart contracts and listen for contract events

## Usage

### Get ENS name and address

ENS Dart provides an interface to look up an address from a name, the reverse, and more.

```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
}
}
```
4 changes: 4 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
48 changes: 48 additions & 0 deletions example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:ens_dart/ens_dart.dart';
import 'package:dotenv/dotenv.dart' as env;

import 'package:http/http.dart';
import 'package:web3dart/web3dart.dart';
import 'package:web_socket_channel/io.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>();
});

final ens = Ens(client: client);

// ENS supports reverse resolution to allow applications to display
// ENS names in place of hexadecimal addresses.
final name = await ens
.withAddress('0x1a5cdcFBA600e0c669795e0B65c344D5A37a4d5A')
.getName();

final addr = await ens.withName('brantly.eth').getAddress();
final content = await ens.getTextRecord();

print('name: $name'); // addr: 0x324f9307b6d26881822c7c8692eeac39791a9756
print('addr: $addr'); // name: sea.eth

print(
'content: $content'); /* 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
} */
}
1 change: 1 addition & 0 deletions lib/ens_dart.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'src/ens_dart.dart';
14 changes: 14 additions & 0 deletions lib/src/const/const.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// ignore_for_file: non_constant_identifier_names

import 'package:web3dart/web3dart.dart';

final ENS =
EthereumAddress.fromHex('0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72');
final ENS_FALLBACK_REGISTRY =
EthereumAddress.fromHex('0x00000000000c2e074ec69a0dfb2997ba6c7d2e1e');
final ENS_RESOLVER =
EthereumAddress.fromHex('0x4976fb03c32e5b8cfe2b6ccb31c09ba78ebaba41');
final ENS_REVERSE_RESOLVER =
EthereumAddress.fromHex('0xa2c122be93b0074270ebee7f6b7292c7deb45047');
final ENS_REVERSE_REGISTRAR =
EthereumAddress.fromHex('0x084b1c3c81545d370f3634392de611caabff8148');
9 changes: 9 additions & 0 deletions lib/src/contracts/contracts.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export 'ens.g.dart';
export 'ens_root.g.dart';
export 'ens_token.g.dart' hide Transfer;
export 'ens_service.g.dart' hide Transfer, NewTTL, NewResolver, NewOwner;
export 'ens_resolver.g.dart';
export 'ens_reverse_registrar.g.dart';
export 'ens_reverse_resolver.g.dart';
export 'ens_registry_fallback.g.dart'
hide ApprovalForAll, NewTTL, Transfer, NewResolver, NewOwner;
Loading

0 comments on commit 6eeb85e

Please sign in to comment.