I've been trying to get MetaMask to produce a signature for a sha3 hash that I can verify in solidity. I've tried eth_sign, personal_sign, eth_signTypedData, and I've had 0 success.

My test suite runs fine (Truffle), but I can not for the life of me get MetaMask to play nice, and I can't find a working example anywhere.

What do I do?


Here's a working example: https://github.com/ConnextProject/ethcalate-2waypayment/blob/master/contracts/ChannelManager.sol

Relevant code:

bytes32 fingerprint = keccak256(channelId, nonce, balanceA, balanceB);
bytes32 signTypedDataFingerprint = keccak256(
    keccak256("bytes32 hash"),
require(ECTools.isSignedBy(signTypedDataFingerprint, sigA, channel.agentA) == true);

This is what we do on the client/dapp side (https://github.com/ConnextProject/ethcalate-client/blob/master/src/Ethcalate.js):

async signTx ({ channelId, nonce, balanceA, balanceB }) {
  // fingerprint = keccak256(channelId, nonce, balanceA, balanceB)
  let hash = abi
      ['bytes32', 'uint256', 'uint256', 'uint256'],
      [channelId, nonce, balanceA, balanceB]
  hash = `0x${hash}`
  console.log('hash: ', hash)

  const sig = await new Promise((resolve, reject) => {
        method: 'eth_signTypedData',
        params: [
              type: 'bytes32',
              name: 'hash',
              value: hash
        from: this.web3.eth.accounts[0]
      function (err, result) {
        if (err) reject(err)
        if (result.error) {
  console.log('sig: ', sig)
  return sig
  • Does this result in a Metamask prompt per channel update? – rnbrady Jul 4 '18 at 14:52
  • Yes it does for Metamask. However, there will surely be other wallet implementations which have different ways to handle this. Spankchain's browser wallet autosigns channel update transactions. – rhlsthrm Jul 4 '18 at 17:45

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.