signTransaction with Moralis

Hi everyone,

I am trying automatically deploy a smart contract when user enters certain parameters and clicks the create button. I am using solc to compile the smart contract and then deploy it using web3.js. I am following a Youtube tutorial to learn so please don’t assume I know my stuff :slight_smile: To do that I need the user to sign. “web3.eth.accounts.signTransaction()” method requires “from address” and “private key”. Is it possible to call a Moralis method to do the signing here instead of the web3.js method? The user is already logged in using Moralis Web3 Auth. So what I want to do basically is replace the “web3.eth.accounts.signTransaction()” with a Moralis function or call the current wallet provider to do the signing and filling the “from: address” in this function. If you have any knowledge about this please let me know. Thank you in advance!

    const erc20Minter = new web3.eth.Contract(abi);
    const deployTx = erc20Minter.deploy({
        data: bytecode
    });

    const createTransaction = await web3.eth.accounts.signTransaction({
        from: myAddress,     //HERE
        data: deployTx.encodeABI(),
        gas: '4000000000',
    },
    privateKey //HERE
    );

const createReceipt = await web3.eth.sendSignedTransaction(
        createTransaction.rawTransaction
    );

if you remove the private key, doesn’t automatically pop up metamask?

Hi, I have this problem too. I want to sign the transaction without a private key. Is there a way?

You will have to write the code if you want to sign with a private key. Moralis sdk doesn’t have a function that uses a private key.

Should I use web 3 functions?

You can do it with web3 or with ethers.

1 Like

Unfortunately it does not. I also couldn’t find the solution with web3 or ethers.