Getting this error when I execute my smart contract function "purchase" using nodejs, it's a very simple smart contract so i'm stuck as to why i keep getting this error.


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

import "@openzeppelin/contracts/access/Ownable.sol";

contract ProductPage is Ownable {
    event PayDay(uint256 date);
    constructor() {}
    function purchase() external payable {}
    function contractBalance() public view returns(uint256) {
                return address(this).balance;
    function withdraw() public onlyOwner {
        if (address(this).balance != 0) {
            (bool success,) = msg.sender.call{value: address(this).balance}("");
            require(success, "Failed to send Ether");
        emit PayDay(block.timestamp);


        const pay = async (e) => {
                try {
                        const tx = contract
                                .send({from: accounts[0], value:web3.utils.toWei("1", "ether")})
                                        method: 'eth_sendTransaction',
                                        params: [
                                                        from: accounts[0],
                                                        to: contractAddress,
                                                        data: tx,
                } catch(err) {
                await setOpen(false);


enter image description here

1 Answer 1


My fault, forgot to edit the deploy migrations file(i.e 2_deploy_contracts.js)

  • Accept your own answer and provide more details if you think would be helpful to any other user Commented Jun 22, 2021 at 3:55
  • What did you forget to edit? I have the same issue but my smart contract functions fine and can accept payment programmatically
    – Dominic
    Commented Dec 20, 2021 at 13:00

Your Answer

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