Can help me to execute this same code in ethers.js

I use moralis for an authentication by mail and ethers to transact in another way with another login to be able to sign the transactions. The question is if you are so kind to help me

I must pass the code to execute the function from morales to ethers to be able to sign, I share the code of what I have tried, there are more things that I have tried:

const sendOptions = {

        contractAddress: tokenAddress.toString().toLowerCase(),

        functionName: "createItem",

        abi: tokenErc721,

        params: {

          _req: [

          user.get("ethAddress"),

          user.get("ethAddress"),

          parseFloat(royal) * 2000,

          user.get("ethAddress"),

          metadataUrl,

          0,

          contracts.token,

          '0',

          '0',

          '0x0000000000000000000000000000000000000000000000000000000000000000'

        ],

        },

      };
        const tx: any = await Moralis.executeFunction(sendOptions)
        const result = await tx.wait(1);

need the same result but signing it with a custom signer i’m trying this way:


async function mintNFTEmail(metadataUrl: string, tokenAddress:  string) {

   

    const ethers = Moralis.web3Library;

    const mnemonic = userRender.attributes?.mnemonic ? userRender.attributes.mnemonic : "";

    const userAddress = userRender.attributes?.ethAddress.toString().toLowerCase() ? userRender.attributes.ethAddress : "";

    const ethAddress = userRender.attributes?.ethAddress ? userRender.attributes.ethAddress.toString().toLowerCase() : "";

    console.log("πŸš€ ~ file: MintState.tsx:655 ~ mintNFTEmail ~ ethAddress", ethAddress)

    const privateKey = userRender.attributes?.privateKey

    ? userRender.attributes.privateKey

    : "";

    const contractTokenKNRT = contracts.token;

    const contractERC721 = contracts.auction;

    const collectionAddress = tokenAddress.toLowerCase()

    const provider = new ethers.providers.WebSocketProvider("wss://polygon-mumbai.g.alchemy.com/v2/F1K_GUpFYDTcyNtye1IA7kPc_ant5-EH")

    // const provider = new ethers.providers.JsonRpcProvider(`${urlProvider}${apiAlchemy}`)

   

    console.log('providesAlchemy', `${urlProvider}${apiAlchemy}`)

    console.log("πŸš€ ~ file: MintState.tsx:663 ~ mintNFTEmail ~ provider", provider)

    // const signer = new ethers.Wallet(privateKey, provider);

       

    const wallet = ethers.Wallet.fromMnemonic(mnemonic);

    const signer = wallet.connect(provider);

    console.log("πŸš€ ~ file: MintState.tsx:665 ~ mintNFTEmail ~ signer", signer)

    let royal = 20 * 1000;

    if (userAddress) {

      const sendOptions = {

        contractAddress: tokenAddress.toString().toLowerCase(),

        functionName: "createItem",

        abi: tokenErc721,

        params: {

          _req: [

          ethAddress,

          ethAddress,

          royal,

          ethAddress,

          metadataUrl,

          0,

          contractTokenKNRT,

          '0',

          '0',

          '0x0000000000000000000000000000000000000000000000000000000000000000'

        ],

        },

        signer: signer

      };

      const _req =  [

            ethAddress,

            ethAddress,

            royal,

            ethAddress,

            metadataUrl,

            0,

            contractTokenKNRT,

            '0',

            '0',

            '0x0000000000000000000000000000000000000000000000000000000000000000'

          ]

      try {

        // const contract = new ethers.Contract(collectionAddress, tokenErc721, signer);

        // const contract = new ethers.Contract(collectionAddress, tokenErc721, signer);

        // console.log("πŸš€ ~ file: MintState.tsx:697 ~ mintNFTEmail ~ contract", contract)

        const hola = await wallet.signTransaction(sendOptions, privateKey)

        console.log("πŸš€ ~ file: MintState.tsx:725 ~ mintNFTEmail ~ hola", hola)

       

        // const tx = await contract.connect(signer).deploy(

        //   // sendOptions

        //   _req

        // ).wait(3);

       

        // const data = Promise.resolve(tx)

        // data.then(value => {

        //   console.log('dataPromise', value)

        // });

        // console.log("πŸš€ ~ file: MintState.tsx:722 ~ mintNFTEmail ~ data", data)

        // console.log("πŸš€ ~ file: MintState.tsx:698 ~ mintNFTEmail ~ tx", tx)

        // const tx: any = await Moralis.executeFunction(sendOptions)

        // const result = await tx.wait(1);

        console.log("resultMintNFT ", JSON.stringify(hola))

        console.log("resultMintNFTJSON", JSON.stringify(parseInt(hola.events[1].args[1]._hex, 16).toString()))

        return parseInt(hola.events[1].args[1]._hex, 16).toString()

      }catch (e: any) {

        console.log("ErrorMintNFT1", e)

        console.log("ErrorMintNFT2", e.message)

        return "-1";

      }

    }

  }

note: What is commented is what I have tried

and the same applies to this function, how can I take it to ethers:

async function _onBuy() {

    const user = await Moralis.User.current();

    if (user) {

      try {

        console.log(Moralis.Units.ETH(price));

        const sendOptions2 = {

          contractAddress: "0x11142365DDbc92C3547b8A074289409B5432CA8b",

          functionName: "approve",

          abi: abi.token,

          awaitReceipt: true, // should be switched to false

          params: {

            spender: "0xE76Bc6E52C2Db6054C4E63f2C9e72ADE240AC3DE",

            amount: Moralis.Units.ETH(price),

          },

        };

        let res = await Moralis.executeFunction(sendOptions2);

        await res.wait(2);

        const sendOptions = {

          contractAddress: "0xE76Bc6E52C2Db6054C4E63f2C9e72ADE240AC3DE",

          functionName: "makeBid",

          abi: abi.marketplace22,

          awaitReceipt: true,

          params: {

            _nftContractAddress: tokenAddress,

            _tokenId: tokenId,

            _erc20Token: "0x11142365DDbc92C3547b8A074289409B5432CA8b",

            _tokenAmount: price,

          },

        };

        const addItemToMarket = await Moralis.executeFunction(sendOptions);

        await addItemToMarket.wait(2);

      } catch (err: any) {

        console.log(err.message);

      }

    } else {

      return;

    }

  }

note: In the first one I need to sign and execute that function and in the other the same but also sign the payment

error example console.log:

ErrorMintNFT1 Error: invalid transaction key: 0 (argument="transaction", value=["0xf7fdd1a239a6fbca88ac8aaf97a174831d91bde3","0xf7fdd1a239a6fbca88ac8aaf97a174831d91bde3",20000,"0xf7fdd1a239a6fbca88ac8aaf…
code=INVALID_ARGUMENT, version=abstract-signer/5.7.0)

what line gives that error?

this is the error:

ErrorMintNFT1 Error: invalid object key - 0 (argument="transaction:0", value={"0":"0xf7fdd1a239a6fbca88ac8aaf97a174831d91bde3","1":"0xf7fdd1a239a6fbca88ac8aaf97a174831d91bde3","2":20000,"3":"0xf7fdd1a239a6fbca88ac8aaf97a174831d91bde3","4":"https://ipfs.moralis.io:2053/ipfs/QmP7HkQCV4WztF62nbXEyyp6VvFjmZpGLLZU2Qx1i9jZnk","5":0,"6":"0x11142365DDbc92C3547b8A074289409B5432CA8b","7":"0","8":"0","9":"0x0000000000000000000000000000000000000000000000000000000000000000"}, code=INVALID_ARGUMENT, version=properties/5.7.0)

this is function:

async function mintNFTEmail(metadataUrl: string, tokenAddress:  string) {

   

    const ethers = Moralis.web3Library;

    const mnemonic = userRender.attributes?.mnemonic ? userRender.attributes.mnemonic : "";

    const userAddress = userRender.attributes?.ethAddress.toString().toLowerCase() ? userRender.attributes.ethAddress : "";

    const ethAddress = userRender.attributes?.ethAddress ? userRender.attributes.ethAddress.toString().toLowerCase() : "";

    console.log("πŸš€ ~ file: MintState.tsx:655 ~ mintNFTEmail ~ ethAddress", ethAddress)

    const privateKey = userRender.attributes?.privateKey

    ? userRender.attributes.privateKey

    : "";

    const contractTokenKNRT = contracts.token;

    const collectionAddress = tokenAddress.toLowerCase()

    const provider = new ethers.providers.JsonRpcProvider(`${urlProvider}${apiAlchemy}`)

    const signer = new ethers.Wallet(privateKey, provider);

   

    let royal = 20 * 1000;

    if (userAddress) {

      // const sendOptions = {

      //   contractAddress: tokenAddress.toString().toLowerCase(),

      //   functionName: "createItem",

      //   abi: tokenErc721,

      //   params: {

      //     _req: [

      //       ethAddress,

      //       ethAddress,

      //       royal,

      //       ethAddress,

      //       metadataUrl,

      //       0,

      //       contractTokenKNRT,

      //       '0',

      //       '0',

      //       '0x0000000000000000000000000000000000000000000000000000000000000000'

      //   ],

      //   },

      // };

      const _req =  [

          ethAddress,

          ethAddress,

          royal,

          ethAddress,

          metadataUrl,

          0,

          contractTokenKNRT,

          '0',

          '0',

          '0x0000000000000000000000000000000000000000000000000000000000000000'

        ]

      try {

        const contract = new ethers.Contract(collectionAddress, tokenErc721, signer);

       

        const tx = await contract.signer.signTransaction(_req, signer)

       

        console.log("πŸš€ ~ file: MintState.tsx:725 ~ mintNFTEmail ~ tx", tx)

               

        return parseInt(tx.events[1].args[1]._hex, 16).toString()

      }catch (e: any) {

        console.log("ErrorMintNFT1", e)

        console.log("ErrorMintNFT2", e.message)

        return "-1";

      }

    }

  }

in this line give error :

const tx = await contract.signer.signTransaction(_req, signer)

and if i try in this way give me this error :

first function and last is error

async function mintNFTEmail(metadataUrl: string, tokenAddress:  string) {

   

    const ethers = Moralis.web3Library;

    const mnemonic = userRender.attributes?.mnemonic ? userRender.attributes.mnemonic : "";

    const userAddress = userRender.attributes?.ethAddress.toString().toLowerCase() ? userRender.attributes.ethAddress : "";

    const ethAddress = userRender.attributes?.ethAddress ? userRender.attributes.ethAddress.toString().toLowerCase() : "";

    console.log("πŸš€ ~ file: MintState.tsx:655 ~ mintNFTEmail ~ ethAddress", ethAddress)

    const privateKey = userRender.attributes?.privateKey

    ? userRender.attributes.privateKey

    : "";

    const contractTokenKNRT = contracts.token;

    const collectionAddress = tokenAddress.toLowerCase()

    const provider = new ethers.providers.JsonRpcProvider(`${urlProvider}${apiAlchemy}`)

    const signer = new ethers.Wallet(privateKey, provider);

   

    let royal = 20 * 1000;

    if (userAddress) {

      const sendOptions = {

        contractAddress: tokenAddress.toString().toLowerCase(),

        functionName: "createItem",

        abi: tokenErc721,

        params: {

          _req: [

            ethAddress,

            ethAddress,

            royal,

            ethAddress,

            metadataUrl,

            0,

            contractTokenKNRT,

            '0',

            '0',

            '0x0000000000000000000000000000000000000000000000000000000000000000'

        ],

        },

      };

      const _req =  [

          ethAddress,

          ethAddress,

          royal,

          ethAddress,

          metadataUrl,

          0,

          contractTokenKNRT,

          '0',

          '0',

          '0x0000000000000000000000000000000000000000000000000000000000000000'

        ]

      try {

        const contract = new ethers.Contract(collectionAddress, tokenErc721, signer);

       

        const tx = await contract.signer.sendTransaction(sendOptions) //sign , signer

       

        console.log("πŸš€ ~ file: MintState.tsx:725 ~ mintNFTEmail ~ tx", tx)

               

        return parseInt(tx.events[1].args[1]._hex, 16).toString()

      }catch (e: any) {

        console.log("ErrorMintNFT1", e)

        console.log("ErrorMintNFT2", e.message)

        return "-1";

      }

    }

  }

ErrorMintNFT1 Error: invalid transaction key: contractAddress (argument="transaction", value={"contractAddress":"0x1c7d04c4ddee4d13c31e800568039aceabdcc3c8","functionName":"createItem","abi":[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newRoyaltyRecipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"newRoyaltyBps","type":"uint256"}],"name":"DefaultRoyalty","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"prevOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"platformFeeRecipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"platformFeeBps","type":"uint256"}],"name":"PlatformFeeInfoUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"recipient","type":"address"}],"name":"PrimarySaleRecipientUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"royaltyRecipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"royaltyBps","type":"uint256"}],"name":"RoyaltyForToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"mintedTo","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenIdMinted","type":"uint256"},{"indexed":false,"internalType":"string","name":"uri","type":"string"}],"name":"TokensMinted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"signer","type":"address"},{"indexed":true,"internalType":"address","name":"mintedTo","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenIdMinted","type":"uint256"},{"components":[{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"royaltyRecipient","type":"address"},{"internalType":"uint256","name":"royaltyBps","type":"uint256"},{"internalType":"address","name":"primarySaleRecipient","type":"address"},{"internalType":"string","name":"uri","type":"string"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"address","name":"currency","type":"address"},{"internalType":"uint128","name":"validityStartTimestamp","type":"uint128"},{"internalType":"uint128","name":"validityEndTimestamp","type":"uint128"},{"internalType":"bytes32","name":"uid","type":"bytes32"}],"indexed":false,"internalType":"struct ITokenERC721.MintRequest","name":"mintRequest","type":"tuple"}],"name":"TokensMintedWithSignature","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"contractType","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"contractURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"contractVersion","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"royaltyRecipient","type":"address"},{"internalType":"uint256","name":"royaltyBps","type":"uint256"},{"internalType":"address","name":"primarySaleRecipient","type":"address"},{"internalType":"string","name":"uri","type":"string"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"address","name":"currency","type":"address"},{"internalType":"uint128","name":"validityStartTimestamp","type":"uint128"},{"internalType":"uint128","name":"validityEndTimestamp","type":"uint128"},{"internalType":"bytes32","name":"uid","type":"bytes32"}],"internalType":"struct ITokenERC721.MintRequest","name":"_req","type":"tuple"}],"name":"createItem","outputs":[{"internalType":"uint256","name":"tokenIdMinted","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getDefaultRoyaltyInfo","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPlatformFeeInfo","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"getRoyaltyInfoForToken","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_defaultAdmin","type":"address"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"string","name":"_contractURI","type":"string"},{"internalType":"address[]","name":"_trustedForwarders","type":"address[]"},{"internalType":"address","name":"_saleRecipient","type":"address"},{"internalType":"address","name":"_royaltyRecipient","type":"address"},{"internalType":"uint128","name":"_royaltyBps","type":"uint128"},{"internalType":"uint128","name":"_platformFeeBps","type":"uint128"},{"internalType":"address","name":"_platformFeeRecipient","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"forwarder","type":"address"}],"name":"isTrustedForwarder","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"string","name":"_uri","type":"string"}],"name":"mintTo","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"royaltyRecipient","type":"address"},{"internalType":"uint256","name":"royaltyBps","type":"uint256"},{"internalType":"address","name":"primarySaleRecipient","type":"address"},{"internalType":"string","name":"uri","type":"string"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"address","name":"currency","type":"address"},{"internalType":"uint128","name":"validityStartTimestamp","type":"uint128"},{"internalType":"uint128","name":"validityEndTimestamp","type":"uint128"},{"internalType":"bytes32","name":"uid","type":"bytes32"}],"internalType":"struct ITokenERC721.MintRequest","name":"_req","type":"tuple"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"mintWithSignature","outputs":[{"internalType":"uint256","name":"tokenIdMinted","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextTokenIdToMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"platformFeeBps","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"platformFeeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"primarySaleRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"salePrice","type":"uint256"}],"name":"royaltyInfo","outputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"royaltyAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_uri","type":"string"}],"name":"setContractURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_royaltyRecipient","type":"address"},{"internalType":"uint256","name":"_royaltyBps","type":"uint256"}],"name":"setDefaultRoyaltyInfo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_platformFeeRecipient","type":"address"},{"internalType":"uint256","name":"_platformFeeBps","type":"uint256"}],"name":"setPlatformFeeInfo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_saleRecipient","type":"address"}],"name":"setPrimarySaleRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"address","name":"_recipient","type":"address"},{"internalType":"uint256","name":"_bps","type":"uint256"}],"name":"setRoyaltyInfoForToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"thirdwebFee","outputs":[{"internalType":"contract ITWFee","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"royaltyRecipient","type":"address"},{"internalType":"uint256","name":"royaltyBps","type":"uint256"},{"internalType":"address","name":"primarySaleRecipient","type":"address"},{"internalType":"string","name":"uri","type":"string"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"address","name":"currency","type":"address"},{"internalType":"uint128","name":"validityStartTimestamp","type":"uint128"},{"internalType":"uint128","name":"validityEndTimestamp","type":"uint128"},{"internalType":"bytes32","name":"uid","type":"bytes32"}],"internalType":"struct ITokenERC721.MintRequest","name":"_req","type":"tuple"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"verify","outputs":[{"internalType":"bool","name":"","type":"bool"},{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}],"params":{"_req":["0xf7fdd1a239a6fbca88ac8aaf97a174831d91bde3","0xf7fdd1a239a6fbca88ac8aaf97a174831d91bde3",20000,"0xf7fdd1a239a6fbca88ac8aaf97a174831d91bde3","https://ipfs.moralis.io:2053/ipfs/QmeGLfFjvRTHHvhWnvkUfFZVGu4uozZxmDFPiiw5sZHCvr",0,"0x11142365DDbc92C3547b8A074289409B5432CA8b","0","0","0x0000000000000000000000000000000000000000000000000000000000000000"]}}, code=INVALID_ARGUMENT, version=abstract-signer/5.7.0)

**this code error **

Can you find out the actual line of code where this error is coming from? Maybe you are not passing the right value - where did you get all this code from?

I have taken the code from the documentation examples, with moralis there is no problem it works, the problem is that I want to migrate the code to ethers js from excuteFunction from moralis to ethers js to sign transactions with a custom wallet not by metamask.

the incoming values to the function are correct debug in the console.log, could you help me with an example of converting this function from moralis :arrow_up:

const sendOptions = {

        contractAddress: tokenAddress.toString().toLowerCase(),

        functionName: "createItem",

        abi: tokenErc721,

        params: {

          _req: [

          user.get("ethAddress"),

          user.get("ethAddress"),

          parseFloat(royal) * 2000,

          user.get("ethAddress"),

          metadataUrl,

          0,

          contracts.token,

          '0',

          '0',

          '0x0000000000000000000000000000000000000000000000000000000000000000'

        ],

        },

      };


         const tx: any = await Moralis.executeFunction(sendOptions)
        const result = await tx.wait(1);

for the same function but with a signer in ethers js

in the same way with a payment function:

        const sendOptions2 = {
          contractAddress: "0x11142365DDbc92C3547b8A074289409B5432CA8b",
          functionName: "approve",

          abi: abi.token,
          awaitReceipt: true, // should be switched to false
          params: {
            spender: "0xE76Bc6E52C2Db6054C4E63f2C9e72ADE240AC3DE",
            amount: Moralis.Units.ETH(price),
          },
        };

        let res = await Moralis.executeFunction(sendOptions2);
const sendOptions = {

          contractAddress: "0xE76Bc6E52C2Db6054C4E63f2C9e72ADE240AC3DE",

          functionName: "makeBid",

          abi: abi.marketplace22,

          awaitReceipt: true,

          params: {

            _nftContractAddress: tokenAddress,

            _tokenId: tokenId,

            _erc20Token: "0x11142365DDbc92C3547b8A074289409B5432CA8b",

            _tokenAmount: price,

          },

        };
        const addItemToMarket = await Moralis.executeFunction(sendOptions);
        await addItemToMarket.wait(2);

how convert 2 function moralis in ethers js with custom signer if i have a private key or mnemonic

You can create a wallet instance.

These two Moralis functions you want to migrate work? executeFunction() uses ethers.js under the hood, so it will work more or less in the same way. There is an example here for interacting with contracts with ethers.js.

Where is this warning from? It doesn’t seem related to contract interaction.

I already removed that error, the error is that the transaction options do not grab me, Yes, with the moralis function everything works perfectly, the problem is executing the same function but with ethers the options don’t grab me this error gives me right now.

async function mintNFTEmail(metadataUrl: string, tokenAddress:  string) {

      try {

        console.log("πŸš€ ~ file: MintState.tsx:977 ~ mintNFTEmail ~ tokenAddress", tokenAddress)

       

        const ethers = Moralis.web3Library;

        const web = new Web3(Moralis.provider);

        console.log('resTx')

   

        const ethAddress = userRender.attributes?.ethAddress ? userRender.attributes.ethAddress.toString().toLowerCase() : "";

        const privateKey = userRender.attributes?.privateKey

        ? userRender.attributes.privateKey

        : "";

        const mnemonic = userRender.attributes?.mnemonic ? userRender.attributes.mnemonic : "";

       

        const contractTokenKNRT = contracts.token;

        const collectionAddress = tokenAddress.toString().toLowerCase();

        console.log('resTx')

   

        const provider2 = new ethers.providers.WebSocketProvider("wss://polygon-mumbai.g.alchemy.com/v2/F1K_GUpFYDTcyNtye1IA7kPc_ant5-EH")

        // const provider = new ethers.providers.JsonRpcProvider(`${urlProvider}${apiAlchemy}`)

        console.log('resTx')

   

        const wallet = new ethers.Wallet(mnemonic);

        const walletConnected = await wallet.connect(provider2);

        console.log('resTx')

   

        const gasLimit = 9000000;

        const gasPrice = 1000000;

   

        let royal = 20 * 1000;

   

        console.log('resTx')

   

          const sendOptions = {

            contractAddress: collectionAddress,

            functionName: "createItem",

            abi: tokenErc721,

            params: {

              _req: [

                ethAddress,

                ethAddress,

                royal,

                ethAddress,

                metadataUrl,

                0,

                contractTokenKNRT,

                '0',

                '0',

                '0x0000000000000000000000000000000000000000000000000000000000000000'

            ],

            },

          };

          console.log('resTx')

          const sendOptions2 = {  

            gasLimit: 100000000,

            gasPrice: gasPrice,        

            params: {

              _req: [

                ethAddress,

                ethAddress,

                royal,

                ethAddress,

                metadataUrl,

                0,

                contractTokenKNRT,

                '0',

                '0',

                '0x0000000000000000000000000000000000000000000000000000000000000000'

            ],

            },

          }

          const sendOptions3 = {  

            value:{req: [

              ethAddress,

              ethAddress,

              royal,

              ethAddress,

              metadataUrl,

              0,

              contractTokenKNRT,

              '0',

              '0',

              '0x0000000000000000000000000000000000000000000000000000000000000000'

          ],}

          }

          const _req =  [

              ethAddress,

              ethAddress,

              royal,

              ethAddress,

              metadataUrl,

              0,

              contractTokenKNRT,

              '0',

              '0',

              '0x0000000000000000000000000000000000000000000000000000000000000000'

          ]

        const contract = new ethers.Contract(collectionAddress, tokenErc721, walletConnected);

        console.log('resTx')

        const tx = await contract.createItem(sendOptions3);

        const resTx = await tx.wait(2);

        console.log('resTx', resTx)

        return 123 //parseInt(tokenId.events[1].args[1]._hex, 16).toString()

      }catch (e: any) {

        console.log("ErrorMintNFT1", e)

        console.log("ErrorMintNFT2", e.message)

        return "-1";

      }

   

  }

Please look at the code, the examples that you gave me, I already tried it that way and in others, but it does not take the options to execute or it tells me invalid values or it stays waiting in the transaction and does nothing.

error :

ErrorMintNFT2 invalid hexlify value (argument="value", value="vicious young flight shrug guilt mother click match immune feed faint rhythm", code=INVALID_ARGUMENT, version=bytes/5.7.0)

and this way the error is:

async function mintNFTEmail(metadataUrl: string, tokenAddress:  string) {

      try {

        console.log("πŸš€ ~ file: MintState.tsx:977 ~ mintNFTEmail ~ tokenAddress", tokenAddress)

       

        const ethers = Moralis.web3Library;

        const web = new Web3(Moralis.provider);

        console.log('resTx')

        const royal = 20 * 2000;

        const ethAddress = userRender.attributes?.ethAddress ? userRender.attributes.ethAddress.toString().toLowerCase() : "";

        const privateKey = userRender.attributes?.privateKey

        ? userRender.attributes.privateKey

        : "";

        const mnemonic = userRender.attributes?.mnemonic ? userRender.attributes.mnemonic : "";

       

        const contractTokenKNRT = contracts.token;

        const collectionAddress = tokenAddress.toString().toLowerCase();

        console.log('resTx')

   

        console.log('resTx')

        const provider = new ethers.providers.JsonRpcProvider(`${urlProvider}${apiAlchemy}`);

        const signer = new ethers.Wallet(privateKey, provider);

        console.log('resTx')

        const sendOptions2 = {

            _req: [

              ethAddress,

              ethAddress,

              royal,

              ethAddress,

              metadataUrl,

              0,

              contractTokenKNRT,

              '0',

              '0',

              '0x0000000000000000000000000000000000000000000000000000000000000000'

            ],

        };

        console.log('resTx')

        const contract = new ethers.Contract(tokenAddress, tokenErc721, provider);

        const tokenId = await contract.connect(signer).createItem(sendOptions2);

       

        console.log('resTx')

   

        console.log('resTx')

        return 123 //parseInt(tokenId.events[1].args[1]._hex, 16).toString()

      }catch (e: any) {

        console.log("ErrorMintNFT1", e)

        console.log("ErrorMintNFT2", e.message)

        return "-1";

      }

  }

error:

ErrorMintNFT2 invalid address or ENS name (argument="name", value=undefined, code=INVALID_ARGUMENT, version=contracts/5.6.0)

and this way this is result but how get tonkenId

async function mintNFTEmail(metadataUrl: string, tokenAddress:  string) {

      try {

        console.log("πŸš€ ~ file: MintState.tsx:977 ~ mintNFTEmail ~ tokenAddress", tokenAddress)

       

        const ethers = Moralis.web3Library;

        const web = new Web3(Moralis.provider);

        console.log('resTx')

        const royal = 20 * 2000;

        const ethAddress = userRender.attributes?.ethAddress ? userRender.attributes.ethAddress.toString().toLowerCase() : "";

        const privateKey = userRender.attributes?.privateKey

        ? userRender.attributes.privateKey

        : "";

        const mnemonic = userRender.attributes?.mnemonic ? userRender.attributes.mnemonic : "";

       

        const contractTokenKNRT = contracts.token.toString().toLowerCase();

        const collectionAddress = tokenAddress.toString().toLowerCase();

        console.log('resTx')

   

        console.log('resTx')

        const provider = new ethers.providers.JsonRpcProvider(`${urlProvider}${apiAlchemy}`);

        const signer = new ethers.Wallet(privateKey, provider);

        console.log('resTx')

        const sendOptions = {

          contractAddress: collectionAddress,

          functionName: "createItem",

          abi: tokenErc721,

          params: {

            _req: [

              ethAddress,

              ethAddress,

              royal,

              ethAddress,

              metadataUrl,

              0,

              contractTokenKNRT,

              '0',

              '0',

              '0x0000000000000000000000000000000000000000000000000000000000000000'

          ],

          },

        };

        const sendOptions2 = [

              ethAddress,

              ethAddress,

              royal,

              ethAddress,

              metadataUrl,

              0,

              contractTokenKNRT,

              '0',

              '0',

              '0x0000000000000000000000000000000000000000000000000000000000000000'

        ]

       

        console.log('resTx')

        const contract = new ethers.Contract(tokenAddress, tokenErc721, provider);

        const tokenId = await contract.connect(signer).createItem(sendOptions2);

        console.log("πŸš€ ~ file: MintState.tsx:1126 ~ mintNFTEmail ~ tokenId", tokenId)

       

        console.log('resTx')

   

        console.log('resTx')

        return 123 //parseInt(tokenId.events[1].args[1]._hex, 16).toString()

      }catch (e: any) {

        console.log("ErrorMintNFT1", e)

        console.log("ErrorMintNFT2", e.message)

        return "-1";

      }

  }

and in this way I get this result but how do I get the token id because with tokenId.events[1].args[1]._hex, 16 I don’t get anything

this it result :

πŸš€ ~ file: MintState.tsx:1126 ~ mintNFTEmail ~ tokenId

1. {type: 2, chainId: 80001, nonce: 51, maxPriorityFeePerGas: BigNumber, maxFeePerGas: BigNumber, …}

  1. accessList: []
  2. chainId: 80001
  3. confirmations: 0
  4. data: "0x52258eaf0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000f7fdd1a239a6fbca88ac8aaf97a174831d91bde3000000000000000000000000f7fdd1a239a6fbca88ac8aaf97a174831d91bde30000000000000000000000000000000000000000000000000000000000009c40000000000000000000000000f7fdd1a239a6fbca88ac8aaf97a174831d91bde30000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011142365ddbc92c3547b8a074289409b5432ca8b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005068747470733a2f2f697066732e6d6f72616c69732e696f3a323035332f697066732f516d546d436f4346454436635559715a35636262683877635169387546316d416247335a3379574d724262776b7800000000000000000000000000000000"
  5. from: "0xf7fDd1a239A6FBCA88ac8AaF97A174831d91bDe3"
  6. gasLimit: BigNumber {_hex: '0x6190', _isBigNumber: true}
  7. gasPrice: null
  8. hash: "0x679f6a5c3dbcce4e02f40a1c1dd3d357bde9581cd68b702d1074a352fcb17a20"
  9. maxFeePerGas: BigNumber {_hex: '0x59682f1e', _isBigNumber: true}
  10. maxPriorityFeePerGas: BigNumber {_hex: '0x59682f00', _isBigNumber: true}
  11. nonce: 51
  12. r: "0xbce58a9899695722a5a4e22ed8529fc51c370db0e754d2940aea571cf3c41f0f"
  13. s: "0x09e5cbb59b8d410dce97a45e85455e4c39939134dad544979ac9ee36d5c5c01c"
  14. to: "0x58eE39a5f27dbE99c48F39Aca32C64BFef4d179C"
  15. type: 2
  16. v: 1
  17. value: BigNumber {_hex: '0x00', _isBigNumber: true}
  18. wait: (confirmations) => {…}
  19. [[Prototype]]: Object

You can run the wait() function in your result to get the transaction logs from the confirmed transactions.

Once you have the logs you can use ether js to decode the data from transaction logs.

let abi = [ ];
let interface = new ethers.utils.Interface(abi)

// logs is an array from the confirmed transaction object
logs.forEach((log) => {
    console.log(interface.parseLog(log));
});

I think I have not explained myself well or they do not understand the question, I explain again, the problem is that the transaction is never sent to the blockchain if I get into

As an example of one of the collections created, the transaction is not generated. I cannot wait for the transaction because it is not executed. I am doing something wrong that does not send the transaction. I am not successful in generating the transaction. This is the last code I have, sorry. the disaster of the code but I exhaust all the solutions so that the transaction is sent the result of the code below gives me an error, first I put the code of the function and last the error. thanks for the patience.

async function mintNFTEmail(metadataUrl: string, tokenAddress:  string) {

  console.log("πŸš€ ~ file: MintState.tsx:1187 ~ mintNFTEmail ~ metadataUrl", metadataUrl)

      try {

        console.log("πŸš€ ~ file: MintState.tsx:977 ~ mintNFTEmail ~ tokenAddress", tokenAddress)

       

        const ethers = Moralis.web3Library;

        const web = new Web3(Moralis.provider);

        const web3Provider = await Moralis.enableWeb3();

        const gasPrice = await web3Provider.getGasPrice();

        console.log('resTx')

        const royal = 20 * 2000;

        const ethAddress = userRender.attributes?.ethAddress ? userRender.attributes.ethAddress.toString().toLowerCase() : "";

        console.log("πŸš€ ~ file: MintState.tsx:1199 ~ mintNFTEmail ~ ethAddress", ethAddress)

        const privateKey = userRender.attributes?.privateKey

        ? userRender.attributes.privateKey

        : "";

        const mnemonic = userRender.attributes?.mnemonic ? userRender.attributes.mnemonic : "";

       

        const contractTokenKNRT = contracts.token.toString().toLowerCase();

        const collectionAddress = tokenAddress.toString().toLowerCase();

   

        console.log('resTx')

        const provider = new ethers.providers.JsonRpcProvider(`${urlProvider}${apiAlchemy}`);

        // const provider = new ethers.providers.JsonRpcProvider("https://speedy-nodes-nyc.moralis.io/06dd81188810ebb48d08e15a/polygon/mumbai")

        const gasLimit = 9000000;

       

        const signer1 = provider.getSigner(ethAddress);

        const signer = new ethers.Wallet(privateKey, provider);

        const signerConnect = signer.connect(provider);

       

        console.log('resTx');

      const contract1 = new ethers.Contract(collectionAddress, tokenErc721, signerConnect);

      const tx = await contract1.createItem({

        gasLimit: 6000000,

        gasPrice: gasPrice,

        params: {

          _req:[

            ethAddress,

            ethAddress,

            royal,

            ethAddress,

            metadataUrl,

            0,

            contracts.token,

            '0',

            '0',

            '0x0000000000000000000000000000000000000000000000000000000000000000'

          ]

        }

    })

      const tokenID = await tx.wait(3);

      console.log("πŸš€ ~ file: MintState.tsx:1238 ~ tx ~ tx", tx)

      console.log("πŸš€ ~ file: MintState.tsx:1238 ~ tokenID ~ tokenID", tokenID)

        return 123 //parseInt(tokenId.events[1].args[1]._hex, 16).toString()

      }catch (e: any) {

        console.log("ErrorMintNFT1", e)

        console.log("ErrorMintNFT2", e.message)

        return "-1";

      }

  }

error:

ErrorMintNFT1 Error: invalid address or ENS name (argument=β€œname”, value=undefined, code=INVALID_ARGUMENT, version=contracts/5.6.0)

This is what the contract function receives:

"MintRequest(address to,address royaltyRecipient,uint256 royaltyBps,address primarySaleRecipient,string uri,uint256 price,address currency,uint128 validityStartTimestamp,uint128 validityEndTimestamp,bytes32 uid)"

function contract:

function createItem(MintRequest calldata _req)  external
    nonReentrant
    onlyRole(MINTER_ROLE)
    returns (uint256 tokenIdMinted){

    address receiver = _req.to == address(0) ? _msgSender() : _req.to;
    tokenIdMinted = _mintTo(receiver, _req.uri);

   

    emit TokensMintedWithSignature(msg.sender, receiver, tokenIdMinted, _req);

    
}

Can you try adding some logs to check if any of the param addresses are undefined or invalid?

Yes, all the fields are verified and have their value, I think the error is how the parameters are passed to the function.