0

Someone could help me. Despite the similar questions i read, i don't see what is wrong. Thanks in advance, Claude

Here is detailed information about error

    imac-de-claude:TransactionContract claudevannier$ npx hardhat run ./scripts/deploy.js --network localhost
Error: incorrect number of arguments to constructor
    at ContractFactory.getDeployTransaction (/Users/claudevannier/TransactionContract/node_modules/ethers/src.ts/contract/factory.ts:87:19)
    at ContractFactory.deploy (/Users/claudevannier/TransactionContract/node_modules/ethers/src.ts/contract/factory.ts:105:31)
    at main (/Users/claudevannier/TransactionContract/scripts/deploy.js:11:34)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
imac-de-claude:TransactionContract claudevannier$ 

Here is my solidity contract.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract TransactionContract {
    address public accountX;
    address public accountY;
    address public owner;

    event TransactionEvent(address indexed sender, address indexed receiver, uint amount, string eventTrigger);

    constructor(address _accountX, address _accountY) {
        accountX = _accountX;
        accountY = _accountY;
        owner = msg.sender;
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "Only contract owner can call this function");
        _;
    }

    function triggerTransaction(uint _amount, string memory _eventTrigger) public {
        require(msg.sender == accountX, "Only account X can trigger this transaction");
        require(_amount > 0, "Amount must be greater than zero");
        
        // Transfer funds from accountX to accountY
        (bool success, ) = accountY.call{value: _amount}("");
        require(success, "Transfer failed");

        emit TransactionEvent(accountX, accountY, _amount, _eventTrigger);
    }

    // Fallback function to receive ETH
    receive() external payable {}
}

here is my script for deploy the contract

const hre = require("hardhat");

async function main() {
  const transac = await hre.ethers.getContractFactory("TransactionContract");
  const contract = await transac.deploy();

  await contract.deployed();

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

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

2 Answers 2

0

Your constructor has this signature: constructor(address _accountX, address _accountY). So it expects two parameters: _accountX and _accountsY.

When you are deploying, you don't provide any parameters. You should add the parameters to transac.deploy() as shown in the ethers documentation (https://docs.ethers.org/v6/api/contract/#ContractFactory-deploy) . Or, alternatively, remove the parameters from your constructor - depending on your needs.

0

Thank you Lauri for your answer.

In fact, my project takes in charge another program in PYTHON language that is responsible for entering the X (sender) and Y(receiver) accounts, the X private keys and a triggering event before calling the Solidity contract that I named TransactionContract.

I first wanted to deploy my "TransactionContract" contract with the deploy.js script to make sure it works before testing the interactive part that calls this contract (FO_Transact_tk.py).

I think this is not the right solution.

Can you tell me how to proceed for a better way?

Thank you in advance Claude

Here are the PYTHON script.

e#!/usr/bin/env python3

-- coding:Utf-8 --

import tkinter as tk from tkinter import messagebox from web3 import Web3 from dotenv import load_dotenv import os

Charger les variables d'environnement depuis un fichier .env

load_dotenv()

Configuration de Web3 pour se connecter au réseau local (localhost)

w3 = Web3(Web3.HTTPProvider('http://localhost:8545'))

Adresse du contrat

contract_address = Web3.toChecksumAddress(os.getenv('CONTRACT_ADDRESS'))

Charger le contrat

with open('TransactionContract.sol', 'r') as file: contract_source_code = file.readlines()

contract_source_code = ''.join(contract_source_code) compiled_contract = w3.eth.compile_contract(contract_source_code)

Adresse de l'utilisateur (compte X)

account_x_address = Web3.toChecksumAddress(os.getenv('ACCOUNT_X_ADDRESS'))

Adresse du compte Y

account_y_address = Web3.toChecksumAddress(os.getenv('ACCOUNT_Y_ADDRESS'))

Clé privée de l'utilisateur (compte X)

private_key = os.getenv('PRIVATE_KEY')

Créer l'instance du contrat

transaction_contract = w3.eth.contract(address=contract_address, abi=compiled_contract['abi'])

def trigger_transaction(): amount = amount_entry.get() event_trigger = event_entry.get()

# Vérifier si le montant est valide
try:
    amount = int(amount)
    if amount <= 0:
        raise ValueError("Amount must be a positive integer")
except ValueError as e:
    messagebox.showerror("Error", str(e))
    return

nonce = w3.eth.getTransactionCount(account_x_address)
transaction = transaction_contract.functions.triggerTransaction(amount, event_trigger, account_y_address).buildTransaction({
    'chainId': 1,
    'gas': 2000000,
    'gasPrice': w3.toWei('50', 'gwei'),
    'nonce': nonce,
})
signed_txn = w3.eth.account.signTransaction(transaction, private_key=private_key)
tx_hash = w3.eth.sendRawTransaction(signed_txn.rawTransaction)
messagebox.showinfo("Success", f"Transaction sent: {tx_hash.hex()}")

Créer la fenêtre Tkinter

root = tk.Tk() root.title("Trigger Transaction")

Entrée pour le montant

amount_label = tk.Label(root, text="Amount:") amount_label.grid(row=0, column=0, padx=10, pady=5) amount_entry = tk.Entry(root) amount_entry.grid(row=0, column=1, padx=10, pady=5)

Entrée pour l'événement déclencheur

event_label = tk.Label(root, text="Event Trigger:") event_label.grid(row=1, column=0, padx=10, pady=5) event_entry = tk.Entry(root) event_entry.grid(row=1, column=1, padx=10, pady=5)

Bouton pour déclencher la transaction

trigger_button = tk.Button(root, text="Trigger Transaction", command=trigger_transaction) trigger_button.grid(row=2, column=0, columnspan=2, padx=10, pady=10, sticky="we")

Lancer la boucle principale Tkinter

root.mainloop()

Your Answer

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

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