sry for the potentially googleable question but i really am not able to find the answer rn
how do i get the code of a local contract (i.e. imported or in the same file)?
i don't mean someAddress.code but the code of a contract whose source code is present but that is not necessarily deployed
Jul 27, 2022, 9:33 AM
You mean bytecode?
Should be inside the build folder after compiling
Jul 27, 2022, 9:39 AM
yeah
yeah but i want to access it from solidity
Jul 27, 2022, 9:39 AM
Ah in contract
type(ContractName).creationCode
Jul 27, 2022, 9:41 AM
thanks
i also just noticed that i don't actually need it bc it looks like in solidity 0.7 and 0.8 you can use create2 w/o assembly
Jul 27, 2022, 9:43 AM
create2 without assembly? How does that work o.O
Jul 27, 2022, 9:43 AM
well my old approach was:
uint256 salt = ...;
bytes memory code = "\x60\xa0\x60\x40\x52...";
address addr;
assembly {
addr := create2(0, add(code, 0x20), mload(code), salt)
if iszero(extcodesize(addr)) {
revert(0, 0)
}
}
bytes memory code = "\x60\xa0\x60\x40\x52...";
address addr;
assembly {
addr := create2(0, add(code, 0x20), mload(code), salt)
if iszero(extcodesize(addr)) {
revert(0, 0)
}
}
oh you said without
i thought you said with
sry
without assembly: https://github.com/Uniswap/v3-core/blob/main/contracts/UniswapV3PoolDeployer.sol#L35
Jul 27, 2022, 9:45 AM
Oooh noice
So you pass in salt and compiler takes it as a create2 deployment
Hmm I'm wondering if we can do the same on normal deployments by passing salt to constructor
Jul 27, 2022, 9:50 AM
wdym by "normal deployments"?
Jul 27, 2022, 9:52 AM
Without using a parent contract
Like, directly deploying a contract
Jul 27, 2022, 10:10 AM
via an EOA? i don't think there is a create2-like option
the salt is not passed to the constructor. the constructor is called after the contract's address was already determined
Jul 27, 2022, 10:24 AM
Yeah I was thinking how does the compiler understands its a create2 deployment
Check the impl
Probably the invert operator
One is 'NOT' and the other is 'Bitwise NOT'
Jul 27, 2022, 11:26 AM