How can I create this signature?
along with nonce,value,contract?
As you added the ethers.js
tag to your question, here an example how to do it with ethers. You can use ethers.utils.solidityKeccak256
to hash nonce, value, and address into a message you can sign using signMessage
.
const { ethers } = require('ethers');
const provider = new ethers.providers.JsonRpcProvider(YOUR_RPC_URL);
const signer = new ethers.Wallet(YOUR_PRIVATE_KEY, provider);
// get latest nonce for your account
const nonce = await provider.getTransactionCount(signer.address, 'latest');
// set value to 0 if you just want to sign without sending ether
const value = 0;
const message = ethers.utils.solidityKeccak256(
['uint256', 'uint256', 'address'],
[nonce, value, CONTRACT_ADDRESS]
);
const signature = await signer.signMessage(ethers.utils.arrayify(message));