Add user to server database

Hi there,

I want to add user eth address into server whenever they click connect wallet using auth method. Is there any documentation to read? Thank you

cheers,
edd

Hi @edi.msi,

Yes absolutely, you can check out the docs here.

https://docs.moralis.io/moralis-server/users/crypto-login

1 Like

Hi Malik,

Thank you. I am going thru the doc, but havent finished it yet.

The connect wallet went flawlessly in Chrome, but got problem during connecting wallet in Firefox.

Any insight? Thank you!

Do you get any other errors in Firefox? From that print screen it looks like an error in the local JavaScript file.

No, mate. All error I have is on screenshot.

On what JavaScript line is that error generated? Can you share your code?

hi @cryptokid here’s the code. Error in Firefox comes from multiple lines as shown in screenshot above

//Mainnet
Moralis.initialize(""); // Application id from moralis.io
Moralis.serverURL = “”; //Server url from moralis.io

const chainutama = “bsc testnet”

//dApp frontend logic
async function login(){

Moralis.Web3.authenticate({signingMessage:“hello there!”}).then(function (user) {
user.save();
getBalances();
})
}

async function getBalances(){

const web3 = await Moralis.Web3.enable();
const chainIdDec = await web3.eth.getChainId();

if (chainIdDec == 97 ) {
chain = “BSC Testnet”;
chain2 = “bsc testnet”;
} else if (chainIdDec == 56 ) {
chain = “BSC Mainnet”;
chain2 = “bsc”;
} else if (chainIdDec == 1 ) {
chain = “ETH Mainnet”;
chain2 = “eth”;
} else if (chainIdDec == 3 ) {
chain = “Ropsten Testnet”;
chain2 = “ropsten”;
} else if (chainIdDec == 4 ) {
chain = “Rinkeby Testnet”;
chain2 = “rinkeby”;
} else if (chainIdDec == 5 ) {
chain = “Goerli Testnet”;
chain2 = “goerli”;
} else if (chainIdDec == 42 ) {
chain = “Kovan Testnet”;
chain2 = “kovan”;
}
console.log(chain);
document.querySelector("#network").textContent = chain;

const tier = await Moralis.Web3.getAllERC20( { chain: chainutama }).then(getTier);
const balances = await Moralis.Web3.getAllERC20( { chain: chain2 }).then(allBalance);

}

function getTier(data){
const tokadd = “0xae13d989dac2f0debff460ac112a837c89baa7cd”;
for (var i = 0; i < data.length; i++){

  	if (data[i].tokenAddress == tokadd) {
  	tokbal = data[i].balance/10**18;			
  } 

}

if (tokbal >= 0 && tokbal <= 1) {
result = “Tier 0”;
} else if (tokbal > 1 && tokbal <= 3) {
result = “Tier 1”;
} else if (tokbal > 3 && tokbal <= 5) {
result = “Tier 2”;
} else {
result = “Tier 3”;
}

console.log(result);
document.querySelector("#tier").textContent = result;

if (result != “Tier 0”) {
document.getElementById(‘btSubmit’).disabled = true;
}
else {
document.getElementById(‘btSubmit’).disabled = false;
}
}

function allBalance(data){

var simbol = [];
var saldo = [];
displaydata = [];

for (var i = 0; i < data.length; i++){

  simbol.push(data[i].symbol);
  desimal = data[i].decimals;
  saldo.push(data[i].balance/10**desimal);

}

console.log(saldo,simbol);

obj = {};

for (var i = 0; i < data.length; i++) {

 obj[saldo[i]] = simbol[i];

}

console.log(obj);

}

It looks like this function didn’t execute, in order to set that tokbal variable.
Or it did execute but it didn’t have data.

hi @cryptokid, after multiple check it did execute but didn’t have data. thank you!