Skip to content

Conversation

@technophile-04
Copy link
Member

Description:

Updated the extension inline with latest args

Hardhat works nicely but with foundry encountered an error while challenges deployement:

Error
❯ yarn deploy --file DeployChallenges.s.sol
[⠊] Compiling...
[⠒] Compiling 1 files with Solc 0.8.28
[⠑] Solc 0.8.28 finished in 1.55s
Compiler run successful!
Traces:
  [18854707] → new DeployChallenges@0x9f7cF1d1F558E57ef88a59ac3D47214eF25B6A06
    └─ ← [Return] 93986 bytes of code

  [11835837] DeployChallenges::run()
    ├─ [0] VM::startBroadcast()
    │   └─ ← [Return]
    ├─ [0] VM::readCallers()
    │   └─ ← [Return] 2, 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720, 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720
    ├─ [5060588] → new NFTFlags@0x700b6A60ce7EaaEA56F065753d8dcB9653dbAD35
    │   ├─ emit OwnershipTransferred(previousOwner: 0x0000000000000000000000000000000000000000, newOwner: 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720)
    │   └─ ← [Return] 23156 bytes of code
    ├─ [0] console::log("NFT Flag contract deployed at", NFTFlags: [0x700b6A60ce7EaaEA56F065753d8dcB9653dbAD35]) [staticcall]
    │   └─ ← [Stop]
    ├─ [45457] NFTFlags::enable()
    │   ├─ emit Enabled(caller: 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720)
    │   └─ ← [Return]
    ├─ [520957] → new Challenge1@0xb19b36b1456E65E3A6D514D3F715f204BD59f431
    │   └─ ← [Return] 2487 bytes of code
    ├─ [0] console::log("Challenge #1 deployed at", Challenge1: [0xb19b36b1456E65E3A6D514D3F715f204BD59f431]) [staticcall]
    │   └─ ← [Stop]
    ├─ [226870] → new Challenge2@0x8ce361602B935680E8DeC218b820ff5056BeB7af
    │   └─ ← [Return] 1018 bytes of code
    ├─ [0] console::log("Challenge #2 deployed at", Challenge2: [0x8ce361602B935680E8DeC218b820ff5056BeB7af]) [staticcall]
    │   └─ ← [Stop]
    ├─ [267513] → new Challenge3@0xe1Aa25618fA0c7A1CFDab5d6B456af611873b629
    │   └─ ← [Return] 1221 bytes of code
    ├─ [0] console::log("Challenge #3 deployed at", Challenge3: [0xe1Aa25618fA0c7A1CFDab5d6B456af611873b629]) [staticcall]
    │   └─ ← [Stop]
    ├─ [873993] → new Challenge4@0xe1DA8919f262Ee86f9BE05059C9280142CF23f48
    │   ├─ emit OwnershipTransferred(previousOwner: 0x0000000000000000000000000000000000000000, newOwner: 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720)
    │   └─ ← [Return] 4125 bytes of code
    ├─ [0] console::log("Challenge #4 deployed at", Challenge4: [0xe1DA8919f262Ee86f9BE05059C9280142CF23f48]) [staticcall]
    │   └─ ← [Stop]
    ├─ [0] VM::deriveKey(<pk>) [staticcall]
    │   └─ ← [Return] <pk>
    ├─ [0] VM::addr(<pk>) [staticcall]
    │   └─ ← [Return] 0xFABB0ac9d68B0B445fB7357272Ff202C5651694a
    ├─ [25172] Challenge4::addMinter(0xFABB0ac9d68B0B445fB7357272Ff202C5651694a)
    │   ├─ emit MinterAdded(minter: 0xFABB0ac9d68B0B445fB7357272Ff202C5651694a)
    │   └─ ← [Return]
    ├─ [520557] → new Challenge5@0xeD1DB453C3156Ff3155a97AD217b3087D5Dc5f6E
    │   └─ ← [Return] 2485 bytes of code
    ├─ [0] console::log("Challenge #5 deployed at", Challenge5: [0xeD1DB453C3156Ff3155a97AD217b3087D5Dc5f6E]) [staticcall]
    │   └─ ← [Stop]
    ├─ [833272] → new Challenge6@0xf7Cd8fa9b94DB2Aa972023b379c7f72c65E4De9D
    │   └─ ← [Return] 4047 bytes of code
    ├─ [0] console::log("Challenge #6 deployed at", Challenge6: [0xf7Cd8fa9b94DB2Aa972023b379c7f72c65E4De9D]) [staticcall]
    │   └─ ← [Stop]
    ├─ [141609] → new Challenge7Delegate@0x12975173B87F7595EE45dFFb2Ab812ECE596Bf84
    │   ├─ emit OwnerChange(owner: 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720)
    │   └─ ← [Return] 585 bytes of code
    ├─ [354275] → new Challenge7@0x82Dc47734901ee7d4f4232f398752cB9Dd5dACcC
    │   └─ ← [Return] 1427 bytes of code
    ├─ [0] console::log("Challenge #7 deployed at", Challenge7: [0x82Dc47734901ee7d4f4232f398752cB9Dd5dACcC]) [staticcall]
    │   └─ ← [Stop]
    ├─ [104278] → new <unknown>@0x196dBCBb54b8ec4958c959D8949EBFE87aC2Aaaf
    │   └─ ← [Return] 409 bytes of code
    ├─ [0] console::log("Challenge #8 deployed at", 0x196dBCBb54b8ec4958c959D8949EBFE87aC2Aaaf) [staticcall]
    │   └─ ← [Stop]
    ├─ [411122] → new Challenge9@0x82C6D3ed4cD33d8EC1E51d0B5Cc1d822Eaa0c3dC
    │   └─ ← [Return] 1826 bytes of code
    ├─ [0] console::log("Challenge #9 deployed at", Challenge9: [0x82C6D3ed4cD33d8EC1E51d0B5Cc1d822Eaa0c3dC]) [staticcall]
    │   └─ ← [Stop]
    ├─ [321363] → new Challenge11@0x05B4CB126885fb10464fdD12666FEb25E2563B76
    │   └─ ← [Return] 1490 bytes of code
    ├─ [0] console::log("Challenge #11 deployed at", Challenge11: [0x05B4CB126885fb10464fdD12666FEb25E2563B76]) [staticcall]
    │   └─ ← [Stop]
    ├─ [1174822] → new Challenge12@0x2a264F26859166C5BF3868A54593eE716AeBC848
    │   └─ ← [Return] 5753 bytes of code
    ├─ [0] console::log("Challenge #12 deployed at", Challenge12: [0x2a264F26859166C5BF3868A54593eE716AeBC848]) [staticcall]
    │   └─ ← [Stop]
    ├─ [255325] NFTFlags::addAllowedMinterMultiple([0xb19b36b1456E65E3A6D514D3F715f204BD59f431, 0x8ce361602B935680E8DeC218b820ff5056BeB7af, 0xe1Aa25618fA0c7A1CFDab5d6B456af611873b629, 0xe1DA8919f262Ee86f9BE05059C9280142CF23f48, 0xeD1DB453C3156Ff3155a97AD217b3087D5Dc5f6E, 0xf7Cd8fa9b94DB2Aa972023b379c7f72c65E4De9D, 0x82Dc47734901ee7d4f4232f398752cB9Dd5dACcC, 0x196dBCBb54b8ec4958c959D8949EBFE87aC2Aaaf, 0x82C6D3ed4cD33d8EC1E51d0B5Cc1d822Eaa0c3dC, 0x05B4CB126885fb10464fdD12666FEb25E2563B76, 0x2a264F26859166C5BF3868A54593eE716AeBC848])
    │   └─ ← [Return]
    ├─ [0] console::log("Added allowed minters to NFTFlags") [staticcall]
    │   └─ ← [Stop]
    ├─ [0] VM::stopBroadcast()
    │   └─ ← [Return]
    ├─ [0] VM::projectRoot() [staticcall]
    │   └─ ← [Return] "/Users/shivbhonde/Desktop/github/se-2-blah-foundry-test/packages/foundry"
    ├─ [0] VM::toString(31337 [3.133e4]) [staticcall]
    │   └─ ← [Return] "31337"
    └─ ← [Revert] Usage of `address(this)` detected in script contract. Script contracts are ephemeral and their addresses should not be relied upon.



== Logs ==
  NFT Flag contract deployed at 0x700b6A60ce7EaaEA56F065753d8dcB9653dbAD35
  Challenge #1 deployed at 0xb19b36b1456E65E3A6D514D3F715f204BD59f431
  Challenge #2 deployed at 0x8ce361602B935680E8DeC218b820ff5056BeB7af
  Challenge #3 deployed at 0xe1Aa25618fA0c7A1CFDab5d6B456af611873b629
  Challenge #4 deployed at 0xe1DA8919f262Ee86f9BE05059C9280142CF23f48
  Challenge #5 deployed at 0xeD1DB453C3156Ff3155a97AD217b3087D5Dc5f6E
  Challenge #6 deployed at 0xf7Cd8fa9b94DB2Aa972023b379c7f72c65E4De9D
  Challenge #7 deployed at 0x82Dc47734901ee7d4f4232f398752cB9Dd5dACcC
  Challenge #8 deployed at 0x196dBCBb54b8ec4958c959D8949EBFE87aC2Aaaf
  Challenge #9 deployed at 0x82C6D3ed4cD33d8EC1E51d0B5Cc1d822Eaa0c3dC
  Challenge #11 deployed at 0x05B4CB126885fb10464fdD12666FEb25E2563B76
  Challenge #12 deployed at 0x2a264F26859166C5BF3868A54593eE716AeBC848
  Added allowed minters to NFTFlags
Error: script failed: Usage of `address(this)` detected in script contract. Script contracts are ephemeral and their addresses should not be relied upon.
make: *** [deploy] Error 1

I think we encountered a similar error here scaffold-eth/create-eth#312 but with the verification script, now it is happening with the Deploy script...cc @rin-st if you can spot something easily? (not urgent! will also try to debug it on wednesday, just tagged incase you can easily spot)

I tried running npx create-eth@latest -s foundry and there deployments works nicely with YourContract.sol

@technophile-04 technophile-04 marked this pull request as draft August 25, 2025 09:54
@vercel
Copy link

vercel bot commented Aug 25, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
ctf.buidlguidl.com Error Error Aug 27, 2025 8:46am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
ctf-devcon Ignored Ignored Aug 27, 2025 8:46am

@rin-st
Copy link
Member

rin-st commented Aug 25, 2025

I tried running npx create-eth@latest -s foundry and there deployments works nicely with YourContract.sol

yarn deploy works, but if I run yarn deploy --file DeployYourContract.s.sol, I'm getting the same error:

Details

yarn deploy --file DeployYourContract.s.sol
[⠊] Compiling...
No files changed, compilation skipped
Traces:
  [5527936] → new DeployYourContract@0x9f7cF1d1F558E57ef88a59ac3D47214eF25B6A06
    └─ ← [Return] 27494 bytes of code

  [998049] DeployYourContract::run()
    ├─ [0] VM::startBroadcast()
    │   └─ ← [Return]
    ├─ [0] VM::readCallers()
    │   └─ ← [Return] 2, 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720, 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720
    ├─ [747408] → new YourContract@0x25C74B7124baE93364213a6124a5e45bB0e98889
    │   └─ ← [Return] 3595 bytes of code
    ├─ [0] VM::stopBroadcast()
    │   └─ ← [Return]
    ├─ [0] VM::projectRoot() [staticcall]
    │   └─ ← [Return] "/Users/liana/Documents/prog/buidl-guidl/create-eth/qf/packages/foundry"
    ├─ [0] VM::toString(31337 [3.133e4]) [staticcall]
    │   └─ ← [Return] "31337"
    └─ ← [Revert] Usage of `address(this)` detected in script contract. Script contracts are ephemeral and their addresses should not be relied upon.


Error: script failed: Usage of `address(this)` detected in script contract. Script contracts are ephemeral and their addresses should not be relied upon.
make: *** [deploy] Error 1

But they both do the same! Both execute function run of DeployYourContract which has ScaffoldEthDeployerRunner modifier. ScaffoldEthDeployerRunner has exportDeployments() function inside, which has this.getChain() code, and this cause an error. Let's remember this, run() -> ScaffoldEthDeployerRunner modifier -> exportDeployments() -> this.getChain()

But why in the first case we have error, and in the second is not?

Difference:

[1] When running yarn deploy --file DeployYourContract.s.sol (error), run() -> ScaffoldEthDeployerRunner modifier -> exportDeployments() -> this.getChain(), this of this.getChain() refers to DeployYourContract.s.sol which is script contract. That's why we get error: "Script contracts are ephemeral and their addresses should not be relied upon."

[2] When running yarn deploy, we run Deploy.s.sol, which creates DeployYourContract instance which is not script contract. this of this.getChain() refers to DeployYourContract instance, it's allowed and doesn't throw error.

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "./DeployHelpers.s.sol";
import { DeployYourContract } from "./DeployYourContract.s.sol";

contract DeployScript is ScaffoldETHDeploy {
    function run() external {
        DeployYourContract deployYourContract = new DeployYourContract();
        deployYourContract.run();
    }
}

Returning to this extension. There's two solutions

  1. Update DeployHelpers.s.sol so there will be no this keyword. After the change both deploy versions should work and we'll avoid similar errors for deploying in other projects. I'll create PR to create-eth soon. Update: Update deployHelpers scaffold-eth/create-eth#338
  2. Simpler version just to make this extension work. Change arguments of Deploy.s.sol so resulting contract will be
import "./DeployHelpers.s.sol";
import { DeployChallenges } from "./DeployChallenges.s.sol";

contract DeployScript is ScaffoldETHDeploy {
    function run() external {
        DeployChallenges deployChallenges = new DeployChallenges();
        deployChallenges.run();
    }
}

and yarn deploy works

@technophile-04
Copy link
Member Author

technophile-04 commented Aug 27, 2025

[1] When running yarn deploy --file DeployYourContract.s.sol (error), run() -> ScaffoldEthDeployerRunner modifier -> exportDeployments() -> this.getChain(), this of this.getChain() refers to DeployYourContract.s.sol which is script contract. That's why we get error: "Script contracts are ephemeral and their addresses should not be relied upon."

[2] When running yarn deploy, we run Deploy.s.sol, which creates DeployYourContract instance which is not script contract. this of this.getChain() refers to DeployYourContract instance, it's allowed and doesn't throw error.

Ohhhh yesss! Also foundry making this changes not allowing script contracts addresses to be used makes sense! TYSM Rinat for explanation and the fix 🙌

Once we release the create-eth new version 1.0.4 will merge this PR 🙌...already updated the version at 8fa0ebd

Copy link
Member

@rin-st rin-st left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Lgtm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants