Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

359
Vistas
How to save wallet address to user model in Django?

I have run into a bit of a hiccup here.

I have a script which gets the user's Metamask wallet address which works fine. The problem arises when I need to save that wallet address to the user model in this field:

ethereum_address = models.CharField(max_length=42, blank=True, null=True)

I have a Javascript that fetches the wallet when the Connect button is pressed:

function connect() {
        ethereum
            .request({ method: 'eth_requestAccounts' })
            .then((account)=> saveAccount(account))
            .catch((error) => {
            if (error.code === 4001) {
                // EIP-1193 userRejectedRequest error
                console.log('Please connect to MetaMask.');
            } else {
                console.error(error);
            }
            });
        }
        
        function saveAccount(account) {
            console.log(account);
            $.ajax({
                url: '/connect-metamask/',
                type: 'POST',
                data: {
                    'account': account,
                    'csrfmiddlewaretoken': '{{ csrf_token }}'
                },
            });
        }

In the views.py I have this when I have a POST request:

def connect_metamask(request):
user = request.user

if request.method == "POST":
    user.ethereum_address = request.POST.get("account")
    user.save()
.........

But when I look at the database the ethereum_address is Null .

How do I make this work?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda