1

Hi im tyring to deploy my contract bug following error

Deploying TaskContract...
Error: factory runner does not support sending transactions (operation="sendTransaction", code=UNSUPPORTED_OPERATION, version=6.6.2)
    at makeError (/Users/daniel/Code/solidity/task-app-hardhat/blockchain/node_modules/ethers/src.ts/utils/errors.ts:677:21)
    at assert (/Users/daniel/Code/solidity/task-app-hardhat/blockchain/node_modules/ethers/src.ts/utils/errors.ts:694:25)
    at ContractFactory.deploy (/Users/daniel/Code/solidity/task-app-hardhat/blockchain/node_modules/ethers/src.ts/contract/factory.ts:107:15)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at main (/Users/daniel/Code/solidity/task-app-hardhat/blockchain/scripts/deploy.js:9:24) {
  code: 'UNSUPPORTED_OPERATION',
  operation: 'sendTransaction'
}

My contract code:

// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;

contract TaskContract {
    event AddTask(address recipient, uint taskId);
    event DeleteTask(uint taskId, bool isDeleted);

    struct Task {
        uint id;
        string taskText;
        bool isDeleted;
    }

    Task[] tasks;
    mapping(uint256 => address) taskToOwner;

    function addTask(string memory taskText, bool isDeleted) external {
        uint taskId = tasks.length;
        tasks.push(Task(taskId, taskText, isDeleted));
        taskToOwner[taskId] = msg.sender;
        emit AddTask(msg.sender, taskId);
    }

    function getMyTasks() external view returns (Task[] memory) {
        Task[] memory temporary = new Task[](tasks.length);
        uint counter = 0;

        for (uint i = 0; i < tasks.length; i++) {
            if (taskToOwner[i] == msg.sender && tasks[i].isDeleted == false) {
                temporary[counter] = tasks[i];
            }
        }

        Task[] memory result = new Task[](counter);

        for (uint i = 0; i < counter; i++) {
            result[i] = temporary[i];
        }
        return result;
    }

    function deleteTask(uint taskId, bool isDeleted) external {
        if (taskToOwner[taskId] == msg.sender) {
            tasks[taskId].isDeleted = isDeleted;
            emit DeleteTask(taskId, isDeleted);
        }
    }
}

and my deployment file:

const { ethers } = require("hardhat");

async function main() {
  // Compile the contract
  const TaskContract = await ethers.getContractFactory("TaskContract");

  // Deploy the contract
  console.log("Deploying TaskContract...");
  const taskContract = await TaskContract.deploy();

  // Wait for the contract to be mined
  await taskContract.deployed();

  console.log("TaskContract deployed to:", taskContract.address);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

my config file:

require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();

const { INFURA_API_KEY, SEPOLIA_PRIVATE_KEY } = process.env;

module.exports = {
  solidity: "0.8.15",
  networks: {
    sepolia: {
      url: `https://eth-sepolia.g.alchemy.com/v2/${INFURA_API_KEY}`,
      account: [`${SEPOLIA_PRIVATE_KEY}`],
    },
  },
};

2 Answers 2

0

I think using hardhat-deploy plugin is a good approach.

And about your issue, i think your .env private key is incorrect. check that.

0

In hardhat.config.js, you should use accounts instead of account

require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();

const { INFURA_API_KEY, SEPOLIA_PRIVATE_KEY } = process.env;

module.exports = {
  solidity: "0.8.15",
  networks: {
    sepolia: {
      url: `https://eth-sepolia.g.alchemy.com/v2/${INFURA_API_KEY}`,
      accounts: [`${SEPOLIA_PRIVATE_KEY}`],
    },
  },
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.