Self-hosting your Moralis server

you can call it directly with a http request too, you can try with Moralis.Web3API prefix too

Could you be more specific please?

When I try to use Moralis.Web3API, it shows

Property ‘Web3API’ does not exist on type '{ Core: MoralisCore; Auth: MoralisAuth; Streams: MoralisStreams; EvmApi: MoralisEvmApi; SolApi: MoralisSolApi; start: (providedConfig?: Partial<…> | undefined) => Promise<…>; }

( "import Moralis from ‘moralis’)

this may work now, you can check the syntax for moralis v2

1 Like

I am getting this error while I am connecting my wallet to one of the Moralis app

http://localhost:1337/server/classes/MarketItems net::ERR_CONNECTION_REFUSED

Is your self hosted server running? You need to have two terminals open - one for your marketplace app and one for the self hosted server.

I have it open it’s saying this

You will need to adjust the authentication code when using a self hosted server - you can look at this page for an example.

I tried to incorporate it into the Account.jsx code but still cant get it to work. It does not throw an error in the browser but it is not doing what’s supposed to… here is the code

https://hastebin.com/egusazinec.js

Did you get any errors in your Parse Server terminal?

It does not throw an error in the browser but it is not doing what’s supposed to

What do you mean by this? Do you get the request to sign the message in MetaMask? Which part isn’t working as it should?

no error in the parse server terminal. Basically when I click on authenticate it does nothing…

Id you look in network tab in the browser what you see for that request that is made

no request that I see. am I supposed to see the function requestMessage in the parse server? i get some other function called
image

this is the network tab you are talking about?

If I replace isAuthenticated by isAuthenticating I get the Authenticate button to flicker if that helps…

What is the code that you use for that authentication button?

https://hastebin.com/egusazinec.js

Can you post it as code on forum? Only the code for that button specific to authentication

function Account() {
  const { authenticate, logout, enableWeb3 } = useMoralis();
  const { walletAddress, chainId } = useMoralisDapp();
  const [isModalVisible, setIsModalVisible] = useState(false);
  const [authError, setAuthError] = useState(null);
  const [isAuthenticating, setIsAuthenticating] = useState(false);
 
  const handleAuth = async (provider) => {
    try {
      setAuthError(null);
      setIsAuthenticating(true);
      // Enable web3 to get user address and chain
      await enableWeb3({ throwOnError: true, provider });
      const { account, chainId } = Moralis;
      if (!account) {
        throw new Error('Connecting to chain failed, as no connected account was found');
      }
      if (!chainId) {
        throw new Error('Connecting to chain failed, as no connected chain was found');
      }
      // Get message to sign from the auth api
      const { message } = await Moralis.Cloud.run('requestMessage', {
        address: account,
        chain: parseInt(chainId, 16),
        network: 'evm',
      });
      // Authenticate and login via parse
      await authenticate({
        signingMessage: message,
        throwOnError: true,
      });
    } catch (error) {
      setAuthError(error);
    } finally {
      setIsAuthenticating(false);
    }
  };


  if (!isAuthenticating) {
    return (
      <div
        style={styles.account}
        onClick={() => handleAuth("metamask")}>
        <p style={styles.text}>Authenticate</p>
      </div>
    );
  }

  return (
    <>
      <div style={styles.account} onClick={() => setIsModalVisible(true)}>
        <p style={{ marginRight: "5px", ...styles.text }}>
          {getEllipsisTxt(walletAddress, 6)}
        </p>
        <Blockie currentWallet scale={3} />
      </div>
      <Modal
        visible={isModalVisible}
        footer={null}
        onCancel={() => setIsModalVisible(false)}
        bodyStyle={{
          padding: "15px",
          fontSize: "17px",
          fontWeight: "500",
        }}
        style={{ fontSize: "16px", fontWeight: "500" }}
        width="400px"
      >
        Account
        <Card
          style={{
            marginTop: "10px",
            borderRadius: "1rem",
          }}
          bodyStyle={{ padding: "15px" }}
        >
          <Address
            avatar="left"
            size={6}
            copyable
            style={{ fontSize: "20px" }}
          />
          <div style={{ marginTop: "10px", padding: "0 10px" }}>
            <a
              href={`${getExplorer(chainId)}/address/${walletAddress}`}
              target="_blank"
              rel="noreferrer"
            >
              <SelectOutlined style={{ marginRight: "5px" }} />
              View on Explorer
            </a>
          </div>
        </Card>
        <Button
          size="large"
          type="primary"
          style={{
            width: "100%",
            marginTop: "10px",
            borderRadius: "0.5rem",
            fontSize: "16px",
            fontWeight: "500",
          }}
          onClick={() => {
            logout();
            setIsModalVisible(false);
          }}
        >
          Disconnect Wallet
        </Button>
      </Modal>
    </>
  );
}

export default Account;

Does it get to execute this line?

You can add some console.log lines to see if it gets there or not.

When that line executes you should see a request in the network tab to your self hosted server

this piece seems correct ?
image

I added logs into the handleAuth function its not going there…