I have been testing some contract that includes EIP712 signatures, with foundry.

As per this doc we need to pass the private key which is being accepted as a uint256.

(uint8 v, bytes32 r, bytes32 s) = vm.sign(ownerPrivateKey, digest);

And it is working fine as long as I am passing a uint256 and creating an address from the same uint using vm.addr.

The problem kicks in when I have created the address from a string using makeAddr() function, as shown in the pic below.

enter image description here

createActor Function:

   function createActor(string memory name) internal returns (address payable) {
        address payable actor = payable(makeAddr(name));
        // Transfer 50 eth to every actor
        vm.deal({ account: actor, newBalance: 50 ether });
        // Transfer 50K PUSH Tokens for every actor
        pushToken.transfer(actor, 50_000 ether);
        return actor;

What is the work around for this? What should I pass as the private key in the vm.sign function for the addresses that have been created using makeAddr?

Do let me know if the question was clear or if I need to add more details.

1 Answer 1


You can get a private key when you create an address. Use the following command instead of makeAddr(name): makeAddrAndKey(name)

Like this:

(address alice, uint256 key) = makeAddrAndKey("alice_channel_owner");
bytes32 digest = keccak256("hello");
(uint8 v, bytes32 r, bytes32 s) = vm.sign(key, digest);

console2.log("actor:", actor); // 0xFF56C91F1242236a49755655EF63CE6eba9B1FB0
console2.log("key:", key);  // 63033525494174347069753265686890270152002273482463513079811354675539312780180
console2.log("v:", v);  // v: 28
console2.logBytes32(r);  // 0xd79fe615dc4d78ab9359ed0720d9aecce919d4a408856888a295951082563cf9
console2.logBytes32(s);  // 0x5f505f2b24ae507082151b184595b977b03199e7ab4d6e69737306e36488ac9a
  • Hey, yeah you are right. I am using the same. Forgot to update the answer here. Thanks. Commented Dec 22, 2023 at 4:05

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.