Using current User for ethers js signer

Rather than executing cloud code for contract functions. Is it possible for me to set the current user from Moralis.User.Current as an ethers js signer.

If this is possible it would be super helpful since Iโ€™m already very familiar with executing contract code through the ethers js library.

I tried using the user directly as a signer and was getting an error.

Moralis exposes a provider which is meant to be a normal ethers.js provider; try creating a signer (getSigner) using that.

Web3 Provider - Moralis

2 Likes

Thanks Iโ€™ll try this out

That doesnโ€™t work, and I tried to manually assign the address by setting signer._address = to the authenticated eth address. Still no luck

const ethAddress = currentUser.get("ethAddress");
let signer = provider.getSigner(ethAddress);

This is the solution for anyone who was wondering

1 Like

Thanks - that is surprising since itโ€™s meant to be a normal provider. Moralis must take over the provider even for this.

1 Like