I have added the compiler options in truffle-config.js -
compilers: {
solc: {
version: "0.8.16",
settings: {
optimizer: {
enabled: false,
runs: 200
}
}
}
}
I am deploying an upgradable erc20 contract using truffle. To do that I am using OpenZeppelin truffle suite.
truffle console --network testnet
truffle(testnet)> compile --all
truffle(testnet)> migrate
for migrate, I have 1_deploy_contracts.js as below
const { deployProxy } = require('@openzeppelin/truffle-upgrades');
const PolarizeV1 = artifacts.require('Erc20Token');
module.exports = async function (deployer) {
const instance = await deployProxy(Erc20Token, [], { deployer, initializer: 'initialize' });
}
This deploys 3 contracts for me:
Erc20Token
proxyAdmin
TransparentUpgradeableProxy
Now, The proxy (TransparentUpgradeableProxy) is verified automatically on the testnet with optimiser shows as "Yes with 200"
Now my aim is to deploy this proxy with NO optimisations since the life cycle of the contract is suppose to last indefinitely.
Then I checked the verified code on bsc scan testnet. I found this: So I traced back the code where open-zeppelin library adds this settings which turned out to be in
node_modules/@openzeppelin/upgrades-core/artifacts/build-info.json
There I manually edited the build-info.json and set enabled: false .
I could also see the same solc compiler version in build-info.json which matches with the verified proxy contract on testnet, you can see that in first image.
"solcLongVersion": "0.8.2+commit.661d1103",
Still the problem persists. Do let me know or point to any relevant resources
UPDATE:
I tried with hardhat as well, and the result is same. On both places I'm using deployProxy module of open-Zeppelin.
So either, the problem is with deployProxy. Please help.
I was able to solve the issue by deploying each of the contract individually and verifying them individually by flattening the code using truffle-flattener. Make sure after flattening, remove all but top one // SPDX-License-Identifier: MIT licenses from the flatten code.
And for TransparentUpgradeableProxy there are three input to constructor, while verifying make sure to find the abi code for arguments by using https://abi.hashex.org/ Also use this this link to find proper bytecode for your constructor arguments. Happy Coding.
deploy.js
const { ethers } = require("hardhat");
async function main() {
const Erc20 = await ethers.getContractFactory("erc20");
const Admin = await ethers.getContractFactory("ProxyAdmin");
const Proxy = await ethers.getContractFactory("TransparentUpgradeableProxy");
const erc20 = await Erc20.deploy();
const admin = await Admin.deploy();
const iface = new ethers.utils.Interface(["function initialize()"]);
const encodedFunctionData = iface.encodeFunctionData(
"initialize",
[]
)
const proxy = await Proxy.deploy(erc20.address, admin.address, encodedFunctionData, { gasLimit: 2000000 });
console.log(`Address of proxy: ${proxy.address}`);
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
I'll keep the bounty if we can do it using the truffle or hardhat plugins deployProxy
not sure about truffle but are you the following setting with hardhat it will work. I was stuck once with same problem after 2 days got to know that you gotta put it inside the compiler indent. If it helps dun forget to accept the answer.
solidity: {
compilers: [
{
version: "0.8.13",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
],
},
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.