Code to reproduce
I was testing transfer the ownership of a contract to another account, but did work though. no error , no output, just did not work. Can someone tell me what wrong?
my token contract:
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract DaTongToken is ERC20, Ownable {
uint256 private _SUPPLY_CAP;
/**
* @notice constructor
* @param _cap supply cap
*/
constructor(uint256 _cap) ERC20("My Token", "MYT") {
_SUPPLY_CAP = _cap;
_mint(msg.sender, 1024000000000);
}
/**
* @notice mint MYT tokens
* @param _to address to receive tokens
* @param _amount amount to mint
* @return status true if mint successful, false if failed
*/
function mint(address _to, uint256 _amount)
external
override
onlyOwner
returns(bool status)
{
if (totalSupply() + _amount <= _SUPPLY_CAP) {
_mint(_to, _amount);
return true;
}
return false;
}
function supply_cap() external view override returns(uint256) {
return _SUPPLY_CAP;
}
}
when i test it with transferOwnership, did not work though, here is my test script:
var Web3 = require("web3);
const web3 = new Web3(ALCHEMY_API);
const myToken = new web3.eth.Contract(MyTokenABI, MyTokenAddress);
await function main() {
await myToken.methods.transferOwnership(another_accout)
.call({from: deployer.address})
.then(console.log);
await myToken.methods.owner().call().then(console.log)
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
})
The result show that MyToken's owner is still the old one. Did anyone show know what i did wrong?
Environment
I'm using Hardhat 2.8.4, deploying the contract on Rinkeby via Alchemy.