Skip to content

ethersjs lib - examples : connect to the blockchain, read & write.

License

Notifications You must be signed in to change notification settings

sol-app/ethersjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ethersjs

ethersjs lib - examples : connect to the blockchain, read & write.

  • Connect web to blockchain (WEB3): here
  • Read from blockchain directly and/or from wallet: here
  • Listening smart contract from events: here

important:

ethersjs v6 have different method for detecting web3

example:

example wallet connect, without external libs. (run in webserver)

<!DOCTYPE html>
<html>
<head>
  <title>Web3 Wallet Connect Example</title>
  <link rel="stylesheet" href="https://bootswatch.com/4/darkly/bootstrap.min.css">
</head>
<body>
  <button id="connect-button" class="btn btn-primary m-5">Connect to Wallet</button>
  <script>
    const connectButton = document.getElementById('connect-button');
    const provider = window.ethereum;

    const connectToWallet = async () => {
      if (typeof provider !== 'undefined') {
        try {
          await provider.request({ method: 'eth_requestAccounts' });
          console.log('Connected to wallet:', provider.selectedAddress);
          // Do something with the connected wallet
        } catch (error) {
          console.error('Failed to connect to wallet:', error);
        }
      } else {
        console.error('No Web3 provider found');
      }
    };

    connectButton.addEventListener('click', connectToWallet);
  </script>
</body>
</html>

About

ethersjs lib - examples : connect to the blockchain, read & write.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published