Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't call smart contract method through Metamask 4.5 #3843

Closed
fukuball opened this issue Apr 3, 2018 · 7 comments
Closed

Can't call smart contract method through Metamask 4.5 #3843

fukuball opened this issue Apr 3, 2018 · 7 comments
Assignees
Labels

Comments

@fukuball
Copy link

fukuball commented Apr 3, 2018

I follow this example:
https://medium.com/metamask/calling-a-smart-contract-with-a-button-d278b1e76705

It works in Metamask 4.4
4 4

But Metamask upgrade to 4.5 yesterday, and things broken.
when calling smart contract method, Metamask will say insufficient balance,
but I do have the eths.
4 5

I wrote an working example online: https://www.obeobeko.com/dapp_test.html

var Web3 = require('web3');
var Eth = require('ethjs-query');
var EthContract = require('ethjs-contract');

var accounts;
var account;
var eth;
var eth_contract;

async function waitForTxToBeMined (txHash) {
  let txReceipt
  while (!txReceipt) {
    try {
      txReceipt = await eth.getTransactionReceipt(txHash);
      console.log(txReceipt);
    } catch (err) {
      return indicateFailure(err)
    }
  }
}

function listenForClicks(simpleStorage) {
    var button = document.querySelector('button.set');
    if (button != undefined) {
        button.addEventListener('click', function() {
            var value = document.getElementById('data-value').value;
            simpleStorage.set(value, {from: account})
            .then(function (txHash) {
              console.log('Transaction sent')
              console.dir(txHash)
              waitForTxToBeMined(txHash)
            })
            .catch(function(error) {
                // rejection
                console.log('reject');
                console.debug(error);
            });
        });
    }
}

window.StartApp = {
  start: async function() {

    eth = new Eth(web3.currentProvider);
    eth_contract = new EthContract(eth);

    var self = this;

    // Get the initial account balance so it can be displayed.
    web3.eth.getAccounts(function(err, accs) {
      if (err != null) {
        console.log("There was an error fetching your accounts.");
        return;
      }

      if (accs.length == 0) {
        console.log("Couldn't get any accounts! Make sure your Ethereum client is configured correctly.");
        return;
      }

      accounts = accs;
      account = accounts[0];
      console.log(account);

      web3.eth.getBalance(account, function(err, balance) {
        console.log(balance);
      });
    });

    const abi = [ { "constant": true, "inputs": [], "name": "data", "outputs": [ { "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "anonymous": false, "inputs": [ { "indexed": true, "name": "_from", "type": "address" }, { "indexed": false, "name": "value", "type": "uint256" } ], "name": "Set", "type": "event" }, { "constant": false, "inputs": [ { "name": "x", "type": "uint256" } ], "name": "set", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" } ];
    const addresss = '0x06e1c13546e04514a0cf8d842216a84745ac317a';
    const SimpleStorage = eth_contract(abi);
    const simpleStorage = SimpleStorage.at(addresss);
    // Listen to clicks from a <button> that trigger a function call of contract

    listenForClicks(simpleStorage);
  },
  getBalance: async function(address) {
    return await web3.eth.getBalance(address);
  }
};

window.addEventListener('load', function() {
  // Checking if Web3 has been injected by the browser (Mist/MetaMask)
  if (typeof web3 !== 'undefined') {
    // Use Mist/MetaMask's provider
    window.web3 = new Web3(web3.currentProvider);
    StartApp.start();
  }
});
<input id="data-value" type="text" placeholder="Enter a number">
<button class="set">Set Data!</button>
<script src="/js/dapp_test.js"></script>

Anyone to solve this issue? Thanks!

@Pedro-vk
Copy link
Contributor

Pedro-vk commented Apr 3, 2018

Same for me. I saw it this morning on other PC. I've been working fine all the day but this afternoon seems that have been upgraded the extension and I had the same problem calling a contract.

@mitsuaki-u
Copy link

Same issue

@jcrain
Copy link

jcrain commented Apr 4, 2018

I have this issue as well. Sends work, seems to just be contract calls.

@charlescrain
Copy link

Experiencing the same issue :(

@jperkinsx
Copy link

I'm getting this same issue too

@charlescrain
Copy link

charlescrain commented Apr 4, 2018

Just upgraded to the 4.5.2 and I'm still seeing this issue. On livenet and on ropsten

@frankiebee frankiebee self-assigned this Apr 4, 2018
@jdlee23
Copy link

jdlee23 commented Apr 4, 2018

i'm having the same issue as well

edit: note that i cannot transfer ERC 20 tokens calling smart contracts methods with metamask currently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants