1

hello every one hope you are doing fine.

i was trying to communicate with my smart contract which is deployed on the goeril test network but i m facing this error

Warning! Error encountered during contract execution [invalid opcode: opcode 0x29 not defined]

you can also see this issue on this link https://goerli.etherscan.io/tx/0x462ada46bd7b38bbd835a4ee18f41a1e03e6fc8641feb7bf3dff0099d0895519

below is my javascript code to interact with smart contract.

function createAccount(){
web3.eth.defaultAccount = ACCOUNT_ADDRESS;

web3.eth.getTransactionCount(web3.eth.defaultAccount, function (err, nonce) {
    console.log("nonce value is "+ nonce);
    const contract = new web3.eth.Contract(abi, address, {from: web3.eth.defaultAccount,gas: 3000000})
    const functionAbi = contract.methods.getBalance().encodeABI();
    var details = {
        "nonce": nonce,
        "gasPrice": web3.utils.toHex(web3.utils.toWei('47', 'gwei')),
        "gas": 300000,
        "to": address,
        "value": 0,
        "data": functionAbi,
    };
    const transaction = new EthereumTx(details, { chain: 'goerli' });
    transaction.sign(Buffer.from("8ccaa6aafdeecb5c01b07a4d9194b5b959df9fbdb9e2e57ba28c91c0bba4af18", 'hex'))
    var rawData = '0x' + transaction.serialize().toString('hex');
    web3.eth.sendSignedTransaction(rawData)
        .on('transactionHash', function (hash) {
            console.log(['transferToStaging Trx Hash:' + hash]);
        
        })
        .on('receipt', function (receipt) {
            console.log(['transferToStaging Receipt:', receipt]);
        })
        .on('error', console.error);
});}

my solidity code file 1

// SPDX-License-Identifier: GPL-3.0


pragma solidity >=0.7.0 <0.9.0;


import "./User.sol";

contract CryptoOp is User{

    constructor(){
        smart_contract_owner = msg.sender;
    }    

    function getBalance() public view returns (uint) {
        return address(this).balance;
    }

    function addFund() public isNotExists isValueSufficient payable returns(string memory){
        dataset[msg.sender].owner_balance += msg.value;
        return "Amount deposit successfully";
    }

    function sendFund(address payable receiver, uint _value) public isNotReceiver payable{
        require(dataset[msg.sender].owner_balance >= _value, "You have insufficient balance");
        (bool sent,) = receiver.call{value: _value}("");
        require(sent,"Failed to send");
        dataset[msg.sender].owner_balance-=_value;
        dataset[receiver].owner_balance+=_value;
    }

    function getMyBalance() public view isNotExists returns(uint){
        return dataset[msg.sender].owner_balance;
    }

    receive() external payable {
        dataset[msg.sender].owner_balance += msg.value;
    }

    fallback() external payable {
        dataset[msg.sender].owner_balance += msg.value;
    }

    

}

my solidity code file 2

// SPDX-License-Identifier: GPL-3.0


pragma solidity >=0.7.0 <0.9.0;

contract User {

    address public smart_contract_owner;

    mapping(address => UserDeatils) public dataset;

    struct UserDeatils{
        string owner_name;
        address owner_address;
        uint owner_balance;
        uint owner_isExists;
        uint creation_date;
    }

    function createAccount(string memory name) public isUserAlreadyExists returns(string memory){
        UserDeatils memory userDeatils =  UserDeatils(name, msg.sender, 0, 1, block.timestamp);
        dataset[msg.sender] = userDeatils;
        return "User created successfully";
    }


    modifier isUserAlreadyExists {
        require(dataset[msg.sender].owner_isExists == 0, "User already exists");
        _;
    }

    modifier isNotExists {
        require(dataset[msg.sender].owner_isExists == 1, "User not exists");
        _;
    }

    modifier isNotReceiver {
        require(dataset[msg.sender].owner_isExists == 1, "Receiver not exists");
        _;
    }

    modifier isValueSufficient {
        require(msg.value > 0, "Need to send more than 0 ether");
        _;
    }
}
2
  • 1
    could be an issue with the contract itself, would be helpful to see the code of your contract in addition to your javascript.
    – timsntech
    Mar 5, 2023 at 18:37
  • @timsntech hi i just update my question i add the solidity code also thank you for replying and help me Mar 7, 2023 at 15:35

1 Answer 1

0

It appears from the goerli transactions that you are making a call to 0x00, and not to an existing contract.

I guess the problem is "to": address, is undefined or 0x00. Try copying the correct address and see if anything changes.

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.