How to structure _signTypedData params #3426
-
Greetings to whomever reads this,On our project we were using this structure to handle meta transactions. const dataToSign = JSON.stringify({
types: {
EIP712Domain: [
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'verifyingContract', type: 'address' },
{ name: 'salt', type: 'bytes32' },
],
MetaTransaction: [
{ name: 'nonce', type: 'uint256' },
{ name: 'from', type: 'address' },
{ name: 'functionSignature', type: 'bytes' },
],
},
domain: {
name: <tokenName>,
version: '1',
verifyingContract: <contractAddress>,
salt: '0x' + (80001).toString(16).padStart(64, '0'),
},
primaryType: 'MetaTransaction',
message: {
nonce: <nonce>,
from: <walletAddress>,
functionSignature: <hashGeneratedFromContractMethodsEncodeABI>
},
})
web3.currentProvider.sendAsync(
{
jsonrpc: '2.0',
id: 999999999999,
method: 'eth_signTypedData_v3',
params: [walletAdr, dataToSign],
},
async function (err, result)
// extra logic
}
) And it was working pretty well. Due to transitioning into wagmi I need to convert this structure to _signTypedData, but i cant convert it. let domain = {
name: <tokenName>,
version: '1',
chainId: 80001,
verifyingContract: <verifyingContractAddress>,
salt: '0x' + (80001).toString(16).padStart(64, '0'),
}
let types = {
EIP712Domain: [
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'verifyingContract', type: 'address' },
{ name: 'salt', type: 'bytes32' },
],
MetaTransaction: [
{ name: 'nonce', type: 'uint256' },
{ name: 'from', type: 'address' },
{ name: 'functionSignature', type: 'bytes' },
],
}
const value = {
from: {
name: 'User',
wallet: <userWalletAddress>,
},
// to: {
name: <tokenName>,
wallet: <tokenContractAddress>,
},
contents: {
nonce: <nonce>,
from: <userWalletAddress>,
functionSignature: <hashGeneratedFromContractMethodsEncodeABI>
},
}
wallet._signTypedData(domain, types, value).then(res => {
console.log('signedTypedData =>', res)
}) I read the ethers.js documentation and tried to convert the first structure into the second, but it does not work. Examples on the documents are fairly simple and I couldn't find any material on how to structure them. I don't even know what I'm doing wrong. While it is not my field of expertise, I am hoping that someone can point me in the right direction. All of the dynamic values are correct and none of them is undefined on the runtime i double checked that. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
{
"types": {
"MetaTransaction": [
{ "name": "nonce", "type": "uint256" },
{ "name": "from", "type": "address" },
{ "name": "functionSignature", "type": "bytes" }
]
},
"domain": {
"name": null,
"version": "1",
"verifyingContract": null,
"salt": null
},
"value": {
"nonce": null,
"from": null,
"functionSignature": null
}
} this works. |
Beta Was this translation helpful? Give feedback.
this works.