Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

How to include ens-ethereum via <script tag> not require? #53

Open
marsrobertson opened this issue Apr 24, 2020 · 3 comments
Open

How to include ens-ethereum via <script tag> not require? #53

marsrobertson opened this issue Apr 24, 2020 · 3 comments

Comments

@marsrobertson
Copy link

https://docs.ens.domains/dapp-developer-guide/working-with-ens

var accounts = ethereum.enable();
var web3 = new Web3(ethereum);
var ens = web3.eth.ens;

https://docs.ens.domains/dapp-developer-guide/managing-names
await ens.setSubnodeOwner('iam.alice.eth', '0x1234...', {from: ...});

The trouble: I'm not using (require) but a regular <script> tag

Uncaught TypeError: ens.setSubnodeOwner is not a function

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>ENS DOMAIN</title>
  </head>
  <body>
  	<h1>ENS DOMAIN</h1>
  
  </body>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> 
  <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>

  <script src="bundle.js"></script>


  <script type="text/javascript">

  	var accounts = ethereum.enable();
  	var web3 = new Web3(ethereum);
  	var ens = web3.eth.ens;


	  ens.setSubnodeOwner('testing.estoniadao.eth', '0x85A363699C6864248a6FfCA66e4a1A5cCf9f5567', {from: accounts[0]})
    
  </script>
</html>

I'd greatly appreciate dist or build version.

@marsrobertson
Copy link
Author

marsrobertson commented Apr 24, 2020

Example from: https://github.com/ethereum/web3.js#readme

One liner simplicity please 🙏

image

@marsrobertson
Copy link
Author

marsrobertson commented Apr 24, 2020

✅Tried with browserify: http://browserify.org/

main.js
ENS = require('ethereum-ens');

browserify main.js -o bundle.js

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>ENS DOMAIN</title>
  </head>
  <body>
  	<h1>ENS DOMAIN</h1>
  
  </body>

  <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.js"></script>

  <script src="bundle.js"></script>


  <script type="text/javascript">

    async function ethEnabled() {
      if (window.ethereum) {
        window.web3 = new Web3(window.ethereum);
        let result = await window.ethereum.enable();
        return result;
      }

      alert("Please ensure that you have MetaMask installed, we suggest Chrome or Brave");
      return false;
    }

    async function start() {
        let address = await ethEnabled();
        accounts = await web3.eth.getAccounts()
        var ens = new ENS(ethereum);

        ens.setSubnodeOwner('testing.estoniadao.eth', '0x85A363699C6864248a6FfCA66e4a1A5cCf9f5567', {from: accounts[0]})  
    }

    start()

  	

  </script>
</html>

DOWNSIDE: Bundle is 2.4 MB


🤷‍♀️ Tried with npx create-react-app

To take advantage of the module bundler...

Then replaced require with import

Then npm install web3

Then some random errors... Gave it a break, didn't follow that path.

@marsrobertson
Copy link
Author

For what I'm using currently, the web3.js is sufficient.

https://docs.ens.domains/dapp-developer-guide/ens-libraries

I simply assumed "no web.js it means operation not supported"

It is supported: https://web3js.readthedocs.io/en/v1.2.7/web3-eth-ens.html#setsubnodeowner

image

The issue remains open as easier to include library is better

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant