2

How can I create this signature?

along with nonce,value,contract?

enter image description here

1 Answer 1

0

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));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.