Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ENS_ETHNewYork_Workshop_May_2019.pdf

 ENS_ETHNewYork_Workshop_May_2019.pdf

Makoto Inoue

May 17, 2019
Tweet

More Decks by Makoto Inoue

Other Decks in Technology

Transcript

  1. Agenda - 1. What can you do with ENS? -

    2. ENS contracts and API overview - 3. Pro tips
  2. Contract MyResolver { address me; function MyResolver() { me =

    msg.sender; } function addr(bytes32 node) constant returns (address) { return me; } } ENS by example: Resolvers
  3. Reverse resolution const addr = ‘0x112234455...’ const name = await

    ens.reverse(‘0x112234455...’).name() //for security const forward = await ens.resolver(name) if(addr === forward){ …. }
  4. Signup flow example Make sure - User is on the

    right network - Metamask is unlocked
  5. Getting ENS subdomain Check if the ENS subdomain already exists

    - If yes, then check if it is owned by the address currently on metamask - If yes then its a sign in, make them sign a message to prove they actually hold the acount they are signing up for. If it doesnt exist then they can have it!
  6. Verify account Signing a message to verify they hold the

    account A nounce to prevent replay attacks
  7. Account Users are logged in regardless of the status of

    transactions. (UX comment) Since Zinc sends the transactions and the messages are verified on chain, they are also verified off chain to prevent sending transactions which are guaranteed to fail.
  8. Contract MyAweSomeApp { function register(bytes32 label) public { bytes32 node

    = getNode(label); require(ens.owner(node) == address(0)) ens.setSubnodeOwner(rootNode, label, this); ens.setResolver(node, resolver); resolver.setAddr(node, msg.sender); ens.setOwner(node, msg.sender); } } The code
  9. Contract MyAweSomeApp { function register(bytes32 label) public { bytes32 node

    = getNode(label); require(ens.owner(node) == address(0)) ens.setSubnodeOwner(rootNode, label, this); ens.setResolver(node, resolver); resolver.setAddr(node, msg.sender); ens.setOwner(node, msg.sender); } } The code web3.utils.sha3(“makoto”)
  10. Contract MyAweSomeApp { function register(bytes32 label) public { bytes32 node

    = getNode(label); require(ens.owner(node) == address(0)) ens.setSubnodeOwner(rootNode, label, this); ens.setResolver(node, resolver); resolver.setAddr(node, msg.sender); ens.setOwner(node, msg.sender); } } The code keccak256(abi.encodePacked(“yourdomain.eth”, label))
  11. Contract MyAweSomeApp { function register(bytes32 label) public { bytes32 node

    = getNode(label); require(ens.owner(node) == address(0)) ens.setSubnodeOwner(rootNode, label, this); ens.setResolver(node, resolver); resolver.setAddr(node, msg.sender); ens.setOwner(node, msg.sender); } } The code web3.utils.sha3(“makoto.yourdomain.eth”)
  12. Contract MyAweSomeApp { function register(bytes32 label) public { bytes32 node

    = getNode(label); require(ens.owner(node) == address(0)) ens.setSubnodeOwner(rootNode, label, this); ens.setResolver(node, resolver); resolver.setAddr(node, msg.sender); ens.setOwner(node, msg.sender); } } The code Check the name is not taken yet
  13. Contract MyAweSomeApp { function register(bytes32 label) public { bytes32 node

    = getNode(label); require(ens.owner(node) == address(0)) ens.setSubnodeOwner(rootNode, label, this); ens.setResolver(node, resolver); resolver.setAddr(node, msg.sender); ens.setOwner(node, msg.sender); } } The code Set the contract to own “makoto.yourdomain.eth”
  14. Contract MyAweSomeApp { function register(bytes32 label) public { bytes32 node

    = getNode(label); require(ens.owner(node) == address(0)) ens.setSubnodeOwner(rootNode, label, this); ens.setResolver(node, resolver); resolver.setAddr(node, msg.sender); ens.setOwner(node, msg.sender); } } The code Set the default resolver to “makoto.yourdomain.eth”
  15. Contract MyAweSomeApp { function register(bytes32 label) public { bytes32 node

    = getNode(label); require(ens.owner(node) == address(0)) ens.setSubnodeOwner(rootNode, label, this); ens.setResolver(node, resolver); resolver.setAddr(node, msg.sender); ens.setOwner(node, msg.sender); } } The code Set the sender address to “makoto.yourdomain.eth”
  16. Contract MyAweSomeApp { function register(bytes32 label) public { bytes32 node

    = getNode(label); require(ens.owner(node) == address(0)) ens.setSubnodeOwner(rootNode, label, this); ens.setResolver(node, resolver); resolver.setAddr(node, msg.sender); ens.setOwner(node, msg.sender); } } The code Give the ownership of the node to the sender
  17. Pro tips - 1. Creating your test ENS name -

    2. Deploying ENS locally - 3. ENS is just a smart contract