Created
July 16, 2022 09:50
-
-
Save rjcrystal/6e4004ab48f78a87fb554fd8fa6c3c16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"github.com/ethereum/go-ethereum/ethclient" | |
"github.com/gin-gonic/gin" | |
"github.com/wealdtech/go-ens/v3" | |
) | |
func main() { | |
r := gin.Default() | |
r.GET("/ping", func(c *gin.Context) { | |
// Replace SECRET with your own access token for this example to work. | |
client, err := ethclient.Dial("https://mainnet.infura.io/v3/e568c670bd77478094e99fa343df8fd8") | |
if err != nil { | |
panic(err) | |
} | |
// Resolve a name to an address. | |
domain := "prnth.eth" | |
address, err := ens.Resolve(client, domain) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("Address of %s is %s\n", domain, address.Hex()) | |
ens.NewResolver(client, domain) | |
// Reverse resolve an address to a name. | |
resolver, err := ens.NewResolver(client, domain) | |
if err != nil { | |
panic(err) | |
} | |
hash, err := resolver.Contenthash() | |
if err != nil { | |
fmt.Printf("%s has no reverse lookup\n", address.Hex()) | |
} else { | |
fmt.Printf("Name of %v is %v\n", address.Hex(), hash) | |
} | |
c.JSON(http.StatusOK, gin.H{ | |
"message": "pong", | |
}) | |
}) | |
r.Run() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment