Signing Messages
Summary
Signing Data with TT Wallet
Sign Typed Data v3 and Sign Typed Data v4
const msgParams = {
types: {
EIP712Domain: [
{ name: "name", type: "string" },
{ name: "version", type: "string" },
{ name: "chainId", type: "uint256" },
{ name: "verifyingContract", type: "address" },
],
Person: [
{ name: "name", type: "string" },
{ name: "wallet", type: "address" },
],
Mail: [
{ name: "from", type: "Person" },
{ name: "to", type: "Person" },
{ name: "contents", type: "string" },
],
},
primaryType: "Mail",
domain: {
name: "Ether Mail",
version: "1",
chainId: 1,
verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
},
message: {
from: { name: "Cow", wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826" },
to: { name: "Bob", wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB" },
contents: "Hello, Bob!",
},
};
const from = window.ethereum.selectedAddress;
const params = [from, JSON.stringify(msgParams)];
const method = "eth_signTypedData_v3"; // Or eth_signTypedData_v4
window.ethereum.sendAsync(
{
method,
params,
from,
},
(err, result) => {
if (err) return console.dir(err);
if (result.error) {
alert(result.error.message);
}
if (result.result) {
console.log("TYPED SIGNED:" + JSON.stringify(result.result));
}
}
);Personal_sign
Last updated