займ на карту онлайн кредит банк

Ethjs-contract package providing transaction related error when calling get function

0

I am integrating MetaMascara to my lottery DApp.
HTML

<script src="https://wallet.metamask.io/metamascara.js"></script> <script src="/javascripts/ethjs-query.min.js"></script> <script src="/javascripts/ethjs-contract.min.js"></script> 

Javascript

  const ethereumProvider = metamask.createDefaultProvider()   ethQuery = new Eth(ethereumProvider);   CONTRACT = new EthContract(ethQuery);   contract = CONTRACT(contractAbi, contractByteCode, {from: window.METAMASK_ACCOUNT, gas: 300000});   contractInstance = contract.at(contractAddress);   const accounts = await ethQuery.accounts();   window.METAMASK_ACCOUNT = accounts[0] || 'locked' 

Here’s success script(when getting a variable defined in contract).

  contractInstance.threshold();// success providing correct threshold 

Here’s error script(when calling a contract function, that is not transaction related)

  contractInstance.Function1(startTicketToSync); 

Uncaught (in promise) Error: [ethjs-rpc] rpc error with payload {“id”:6135743116650,”jsonrpc”:”2.0″,”params”:[{“gas”:”0x493e0″,”to”:”0x9b7e002a05efebe6e6c4fb8d15c9203dfc1e605f”,”data”:”0xdb493a6b0000000000000000000000000000000000000000000000000000000000000001″}],”method”:”eth_sendTransaction”} {“message”:”Undefined address – from address required to sign transaction.”,”code”:-32603}

When I call the function in Metamask extension available space it is providing appropriate information.(using web3)

  contract = web3.eth.contract(contractAbi);   contractInstance = contract.at(contractAddress);   contractInstance.Function1.call(startTicketToSync, callback); 

Smart contract solidity script

contract Contract1 is Ownable {     uint public threshold;     ...     function Function1(uint start) public returns (uint, uint, uint, bool ) {        require(start >= 1 && start <= currentTicket);         uint i;         for (i = start; i <= currentTicket; i++) {             if (tickets[i].holder == msg.sender && tickets[i].winAmt > 0) {                 return (i, tickets[i].ref, tickets[i].winAmt, tickets[i].paid);             }         }         return (currentTicket + 100, 0, 0, false);     }  } 

Finally I solved the issue, after 3 days brainstorming, but the error string is making the developers hard to find issue.

I have fixed this.

  const ethereumProvider = metamask.createDefaultProvider()   ethQuery = new Eth(ethereumProvider);   CONTRACT = new EthContract(ethQuery);   contract = CONTRACT(contractAbi, contractByteCode, {from: window.METAMASK_ACCOUNT, gas: 300000});   contractInstance = contract.at(contractAddress);   const accounts = await ethQuery.accounts();   window.METAMASK_ACCOUNT = accounts[0] || 'locked' 

TO

  const ethereumProvider = metamask.createDefaultProvider()   ethQuery = new Eth(ethereumProvider);   CONTRACT = new EthContract(ethQuery);   const accounts = await ethQuery.accounts();   window.METAMASK_ACCOUNT = accounts[0] || 'locked'   contract = CONTRACT(contractAbi, contractByteCode, {from: window.METAMASK_ACCOUNT, gas: 300000});   contractInstance = contract.at(contractAddress); 

Changed the order.
The error was because smart contract function was calling msg.sender, and when I set to origin, contract call address is default become undefined.

It took 3 days for me to fix( suddenly I got answer when posting to this platform), and hope this experience helps others solve this in 1min!