Wallet Connect integration for web3 dapps built in python with anvil

Since 2022 I have been building smart contracts in Solidity and the supporting user interfaces in Anvil. Over $100M of business has been conducted in these products.

Here is the WalletConnect.com component that I use for allowing users to connect their wallets to the sites and broadcast transactions to the blockchain. I followed the instructions for a vanilla javascript wallet connect integration and used the anvil.js package to drive it fully in python. true magic! . My integration is bare bones and basic, but see the documentation to expand the functionality or customize the theme: Usage | WalletConnect Docs

Example Site:

Clone Links (sample site and Wallet Connect Hub) :

Integration Instructions:

  1. Import the WalletConnect Hub app as a dependency and add ethers library to your Native Libraries.
  2. Add the “wallet_chains” datatable from the WalletConnect Hub app into your new app. Add any EVM chain you want. For production applications, you want to get your own RPC endpoints from services such as Alchemy or Infura.
  3. Sign up for a Wallet Connect account to get your project ID. Do not be surprised if the project ID used in this sample is suddenly turned off.
  4. Define the wallet connect component in the “define_wc()” function to include the project_id, chain_ids for the chains you will be enabling, project name, description, and icon.
  5. Add the wc component to your page, i like putting it on the navbar links section but it is your choice.
  6. add optional logic to the “connect” event handler which is triggered when any change to the wallet connect modal occurs (connect, disconnect)
  7. You can reference the provider object, signer object, or connected address with self.wc.provider, self.wc.signer, self.wc.address. Provider can be used for “read only” functions, signer is used for state changing functions.
    for example to send all tokens:
balance = ethers.Contract(token_address, token_abi, self.wc.provider).balanceOf(self.wc.address)
a = anvil.js.await_promise(ethers.Contract(token_address, token_abi, self.wc.signer).transfer(recipient_address, balance)
a.wait()
Notification("tokens sent!").show()

If you need help with any crypto related product, please reach out to me at maximusdipcatcher@gmail.com

Important Safety warning: This site is obviously safe to click on since you can read the source code in the clone, but do not just go around clicking links trying to get you to connect your wallet. You shouldnt have any meaningful amount of funds or important private keys on devices that you are also using to read forums. always be careful and dont get scammed.

1 Like