'Stack underflow (0 <=> 2) when deploying a smart contract

I'm developing a contract and a Web 3.0 using Hardhat, Ethers.js, Node.js and Web3.0 (Metamask) to do ETH smart contracts and transactions and I'm getting a rare error when trying to execute the function 'eth_sendTransaction' while deploying a contract, not transferring ETH from one account to another, from Metamask's RPC API.

The code that I have is:

async function awaitContract(contractAddress, currentAccount, parsedAmount) {
    return await ethereum.request({
        method: 'eth_sendTransaction',
        params: [{
            from: currentAccount, //window.ethereum.request({ method: "eth_accounts" })[0]
            gas: '0x124F80',
            value: parsedAmount._hex,
            data: contractAddress', //contract address (0x....)
        }]
    });
}

I first compile and deploy the contract to the blockchain, but then I want to create new specific instances of the contract using eth_sendTransaction I get the error.

According to Metamask's RPC API docs (https://eth.wiki/json-rpc/API#eth_sendtransaction), If I don't specify the address to but I specify the data field, a new contract should be created.

My surprise comes when I go to search the transaction result to Etherscan and I see the following error:

Warning! Error encountered during contract execution [stack underflow (0 <=> 2)]



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source