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

eth_sign requires 32 byte message hash #33

Closed
AllLuckly opened this issue Apr 7, 2022 · 4 comments
Closed

eth_sign requires 32 byte message hash #33

AllLuckly opened this issue Apr 7, 2022 · 4 comments

Comments

@AllLuckly
Copy link

AllLuckly commented Apr 7, 2022

error: JSON-RPC error -32000: eth_sign requires 32 byte message hash


  @override
  Future<String> sign(String message, String address) async {
    // TODO: implement sign
    final result = await connector.sendCustomRequest(
      method: 'eth_sign',
      params: [address, message],
    );

    return result;
  }

@HaoCherHong
Copy link
Contributor

Did you use MetaMask as provider? seems something related to this:
web3/web3.js#4780

@HaoCherHong
Copy link
Contributor

HaoCherHong commented May 9, 2022

This should work if you were using MetaMask
Please check the comment below

import 'dart:convert';
import 'package:crypto/crypto.dart';

// ...
  const messageToSign = "TEST";
  final bytes = utf8.encode(messageToSign);
  final messageHash = sha256.convert(bytes);
  final signature = await provider.sign(
      message: '0x$messageHash', address: session.accounts[0]);

@HaoCherHong
Copy link
Contributor

Using personal_sign instead solves the problem, please check:
https://github.com/RootSoft/walletconnect-dart-sdk/pull/39/files

@RootSoft
Copy link
Owner

#38 (comment)

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

No branches or pull requests

3 participants