How to perform eth contract transaction in Django using web3.py and Metamask

Trying to build a Dapp using Django, till now completed below steps.

  1. Deployed a simple lottery contract on test net, contract address is 0xD5d56C139848A0E55DC5C616D04a0CeD98D8BeA3 (can be seen at https://sepolia.etherscan.io/)
  2. Using web3.py I can connect to this contract and call the functions.
  3. I have created a simple webapp which ask user to connect to its Metamask wallet.
  4. I am using JS to load the Metamask wallet in the browser.
  5. When user click on connect wallet Metamask extension loads in the browser.
  6. Once user gets connected I can read the address of the connected user.

Next step is user will click on enter lottery button, after that Metamask should popup to sign the transaction.
The Problem is I want to use the web3.py in my Django view to call my contract function which will allow user to enter in to the lottery game, but how can I call Metamask from Django view to ask user to sign transaction as it is browser extension.

but how can I call Metamask from Django

You don't.

The whole point of the blockchain is that any call from the user goes directly to the blockchain, and there is no backend server that could block or censor what users are doing.

You need to implement logic in the frontend, using JavaScript, for the user interaction.

Back to Top