errecover returns address 0 for valid eip712 signatures generated with viem. works fine with etherv5
09:34 18 Jun 2026

My contract verifies eip712 signatures fine when generated with etherv5 but failsin viem. erecover returns address(0) when generated using viem. verifyTypedData returns true on the frontend so the signature is good.

does viem format differently than ethers ?

contract function:

function verify(address signer, address to, uint256 amount, uint8 v, bytes32 r, bytes32 s) public view returns (bool) {
    bytes32 structHash = keccak256(abi.encode(TYPEHASH, to, amount));
    bytes32 hash = _hashTypedDataV4(structHash);
    return ecrecover(hash, v, r, s) == signer;
}

frontend:
const sig= await walletClient.signTypedData({ 
domain,
types, 
primaryType:'Mint',
message 
});

const r = sig.slice(0, 66) as `0x${string}`;
const s = `0x${sig.slice(66, 130)}` as `0x${string}`;
const v = parseInt(sig.slice(130, 132), 16);
ethereum viem