Transfer NFT To User Returns Error With Signer

Hi, I’m having trouble transferring an NFT to a user in my website, which is weird because I’m not having trouble with getting their NFT or giving them MATIC. The function is below. I am getting an error saying:

Error: Contract with a Signer cannot override from (operation="overrides.from", code=UNSUPPORTED_OPERATION, version=contracts/5.6.0)

My Function:

async function giveNFTtoUser(address, token) {
  let userWallet = await getAddress();
  let web3 = await Moralis.enableWeb3({
        chainId: 0x13881,
          "{private key for my account}"
  console.log('in get nft')
  const options = {
      type: "erc721",
  receiver: userWallet,
  contractAddress: address,
    tokenId: token
  let transaction = await Moralis.transfer(options);
  let result = await transaction.wait();
  return result;

How was Moralis.start initialized?

You can use ethers or web3 directly in case that it doesn’t work.

I also got into some problems on polygon with the gas price using this syntax to transfer an erc20 token.

My Moralis.start code is as follows:

/* Moralis init code */
const serverUrl = "";
const appId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
Moralis.start({ serverUrl, appId });

How would you transfer an NFT with a private key used for a signer on ethers or web3?

you have to use Moralis.start({moralisSecret}) for that syntax with private key to work, and you should run in only in nodejs

you transfer NFTs by calling a contract function (probably transfer) like doing any other web3 contract function call to a writable function, you will need the abi

you can also take a look in the source code for Moralis SDK to see how it works

That’s weird, because then how would I link up my server url and appid? Also, the same syntax (but with slight changes to options was working for transferring MATIC to a user)

you run that code in nodejs server side or in the browser?

I don’t expect it to work without using moralisSecret in nodejs server side

I’m doing it in the browser (with the SDK)

ok, in the browser it works without private key, it uses metamask or other web3 provider that was enabled

Yes, but I am trying to get a different account which is not logged in to sign and give away an NFT. So, I don’t want to ask a user to give an NFT, I am having my other account sign and give it by using the private key

I don’t think that it is a good idea to hardcode/use a private key in browser, anyone could use that private key

I am using an express server and have the private key passed in to the page, but either way that wouldn’t explain why the transfer doesn’t work

I don’t expect it to work that way, maybe when it worked it worked because it used metamask?

Like I said before, the privatekey thing worked for transferring native tokens. However, do you think it might work if I set up an API endpoint that uses nodejs that I can call whenever I need to give the user an NFT?

I think that it is a better idea to use an API endpoint, that way the private key is not exposed directly