[SOLVED] Use Moralis.link() with self hosted

Hello all

I want to use Moralis.link on my self hosted server. But Metamask has an empty signing message. I think i need to get “message” from my server to pass it to link function (like auth with self hosting), but i dont know how to do it.

Can someone help me please ?

thanks!

I am not sure if link functionality was implemented in the self hosted server

you can look at the link function from the sdk and try to write a similar code, but the server also has to know how to handle linked accounts

You can use Moralis.link() if you use the same type of authentication in this tutorial.

For example with the React client:

async function link() {
  await enableWeb3();

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',
    });

    await Moralis.link(accountstringyouwanttolinkhere, {
      signingMessage: message,
    }).catch((err) => {
      console.log('err', err);
    });
}
2 Likes

Thank’s very much!

I ever try to do like that, but i use TypeScript and LinkOptions had no signingMessage props. So I retried after to have edit LinkOptions type, and it’s working!
I added that code :
type LinkOptions = Object.SaveOptions & { signingMessage?: string };