0

I am stuck with this problem for a long time. Please help me ........

I deployed contract from Remix and its is working fine, But getting Invalid argument error in console after running this file in browser. And getting empty array while calling method to read stored value via .call()

Contract deployed on rinkeby testnet on address "0xB1131a52f23740444577cBfCa11A8F2b90e5CEd3" (Rinkeby testnet)

Console Output:

Default Account: 0xD3B2f24f27Eb75b941084Ef56065F51b9589dba6 index.html:69  
 Deployed Contract Address: 0xB1131a52f23740444577cBfCa11A8F2b90e5CEd3 index.html:77

//this is for .send() function
  invalid tuple value (argument="tuple", value="123", code=INVALID_ARGUMENT, version=abi/5.0.0-beta.153) index.html:80 

//this returned for .call() function*
 []length: 0__proto__: Array(0)

Solidity code:

pragma solidity >=0.4.22 <=0.8.0;

/**
 * @title Storage
 * @dev Store & retrieve value in a variable
 */

contract Storage {

    uint256 public number;

    constructor(uint256 num) public{
        number = num;
    }

    /**
     * @dev Store value in variable
     * @param num value to store
     */
    function store(uint256 num) public {
        number = num;
    }

    /**
     * @dev Return value 
     * @return value of 'number'
     */
    function retrieve() public view returns (uint256) {
        return number;
    }

}

HTML file:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <h1 id="h1">Welcome to Storage</h1>
  <input type="text" name="" id="storage">
  <p>Value of the storage is <Span id="value">0</Span></p>
  <div>
    <button id="get">Get Storage</button>
    <button id="set">Update Storage</button>
  </div>

  <!-- <scriptsrc="https://cdn.jsdelivr.net/gh/ethereum/web3.js@1.0.0beta.37/dist/web3.min.js"></script> -->

  <script src="./node_modules/web3/dist/web3.min.js"></script>


  <script>

    var abi = [
      {
        inputs: [[Object]],
        stateMutability: 'nonpayable',
        type: 'constructor'
      },
      {
        inputs: [],
        name: 'number',
        outputs: [[Object]],
        stateMutability: 'view',
        type: 'function'
      },
      {
        inputs: [],
        name: 'retrieve',
        outputs: [[Object]],
        stateMutability: 'view',
        type: 'function'
      },
      {
        inputs: [[Object]],
        name: 'store',
        outputs: [],
        stateMutability: 'nonpayable',
        type: 'function'
      }
    ];
    

    var atAddress = '0xB1131a52f23740444577cBfCa11A8F2b90e5CEd3';

    var web3 = new Web3(window.ethereum);

     // asyn function expression
    var interact = async () => {

      //get accounts
      var accounts = await web3.eth.getAccounts();
      console.log('Default Account: ' + accounts[0]);

      //contract instance
      var contract = new web3.eth.Contract(abi, atAddress , { from: accounts[0] });
    
      //check contract address
      console.log('Deployed Contract Address: ' + contract.options.address);
      

      try {
        //send a tx to store some integer value
        await contract.methods.store("123").send({from:accounts[0], gas: '1000000'})
        .then(function (result) {console.log(result) })
      }
      catch (error) { console.log(error.message) }

      //retrieve the stored value by calling method function
      console.log(await contract.methods.retrieve().call());

    }
    interact();        

  </script>
</body>

</html>

  • 1
    Get rid of that stuff: inputs: [[Object]]. It's plain wrong, and I have no idea where you got it from. You probably printed the ABI without parsing it right (for example, using JSON.stringify). This is simply not a valid ABI format. – goodvibration Sep 26 at 16:41
  • you abi is not correct – Majd TL Sep 26 at 16:43
  • And it's the second time I'm seeing this question here BTW. – goodvibration Sep 26 at 16:43
  • Ok let me correct my abi format and try again. – mohit kumar Sep 26 at 16:48
  • Thank you @goodvibration .Now I used the stringified version of abi direct from Remix and it worked fine and solved my problem. By the way earlier I was using abi (which itself was an object) from inside of my Contract Object (compiled in node using solc), which was being used to deploy contract in node using .depoy().send() method. I forgot web3 needs JSON for communication not object. Please correct me if I am wrong somewhere. – mohit kumar Sep 26 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.