Using this tutorial: Openzeppelin-upgrades , and OpenZeppelin Contracts Wizard Transparent upgradeable
Everything seems to be working but when deploying using Hardhat, The returned owner is 0x0., and I don't seem to get any errors either, Any help is appreciated, thanks!
Code to reproduce
Here is the deploy script
// scripts/deploy.js
async function main() {
const accounts = await ethers.provider.listAccounts();
console.log("Accounts[0]:", accounts[0]);
// We get the contract to deploy
const Sample = await ethers.getContractFactory("Sample");
console.log("Deploying Sample...");
const sample = await Sample.deploy();
await sample.deployed();
console.log("Sample deployed to:", sample.address);
await sample.initialize();
console.log("Sample initialized.");
console.log("Sample owner:", await sample.owner());
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
And here is the console Output when deploying:
Compilation finished successfully
Accounts[0]: 0x4Ce...
Deploying Sample...
Sample deployed to: 0xdDB...
Sample initialized.
Sample owner: 0x000...
Environment
Hardhat
Skyge
December 29, 2021, 1:56am
2
Hi, welcome!
Your script looks like ok, so could you please share your contract code at here?
And it seems like you only deploy an implementation without proxy contract.
Thank you for taking a look, I really appreciate it!
Here's the contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-ERC20PermitUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20VotesUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
/// @custom:security-contact TokenHandler@gmail.com
contract Sample is Initializable, ERC20Upgradeable, ERC20BurnableUpgradeable, PausableUpgradeable, OwnableUpgradeable, ERC20PermitUpgradeable, ERC20VotesUpgradeable {
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() initializer {}
function initialize() initializer public {
__ERC20_init("Sample", "SA");
__ERC20Burnable_init();
__Pausable_init();
__Ownable_init();
__ERC20Permit_init("Sample");
}
function pause() public onlyOwner {
_pause();
}
function unpause() public onlyOwner {
_unpause();
}
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
function _beforeTokenTransfer(address from, address to, uint256 amount)
internal
whenNotPaused
override
{
super._beforeTokenTransfer(from, to, amount);
}
// The following functions are overrides required by Solidity.
function _afterTokenTransfer(address from, address to, uint256 amount)
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable)
{
super._afterTokenTransfer(from, to, amount);
}
function _mint(address to, uint256 amount)
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable)
{
super._mint(to, amount);
}
function _burn(address account, uint256 amount)
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable)
{
super._burn(account, amount);
}
}
Again thank you so much for taking the time to look at this.