I am following the challenges from the speedrunEthereum and right now I am stuck on challenge 2 and not getting why the transferOwnership is not a function since I am also inheriting the Ownable from openzeppelin.
pragma solidity 0.8.4;
// SPDX-License-Identifier: MIT
import "@openzeppelin/contracts/access/Ownable.sol";
import "./YourToken.sol";
contract Vendor is Ownable {
uint256 public constant tokensPerEth = 100;
event BuyTokens(address buyer, uint256 amountOfETH, uint256 amountOfTokens);
YourToken public yourToken;
constructor(address tokenAddress) {
yourToken = YourToken(tokenAddress);
}
function buyTokens() public payable {
uint256 tokensAmount = tokensPerEth * msg.value;
yourToken.transfer(msg.sender,tokensAmount);
emit BuyTokens(msg.sender,msg.value,tokensAmount);
}
}
deployment script:
// deploy/01_deploy_vendor.js
const { ethers } = require("hardhat");
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();
const chainId = await getChainId();
// You might need the previously deployed yourToken:
const yourToken = await ethers.getContract("YourToken", deployer);
// Todo: deploy the vendor
const vendor = await deploy("Vendor", {
from: deployer,
args: [yourToken.address],
log: true,
});
// Todo: transfer the tokens to the vendor
console.log("\n ๐ต Sending all 1000 tokens to the vendor...\n");
const transferTransaction = await yourToken.transfer(
vendor.address,
ethers.utils.parseEther("1000")
);
console.log("\n โ confirming...\n");
await sleep(5000); // wait 5 seconds for transaction to propagate
await transferTransaction.wait();
// ToDo: change address to your frontend address vvvv
console.log("\n ๐คน Sending ownership to frontend address...\n")
const ownershipTransaction = await vendor.transferOwnership("0x64b2a2caf782c54998F5d0667AE71D7bF898Bc5F");
console.log("\n โ confirming...\n");
const ownershipResult = await ownershipTransaction.wait();
};
I am not getting why the transferOwnership is not a function. Since it's public also in openzeppelin.
yarn run v1.22.19
$ yarn workspace @scaffold-eth/hardhat deploy --reset
$ hardhat deploy --export-all ../react-app/src/contracts/hardhat_contracts.json --reset
Nothing to compile
deploying "YourToken" (tx: 0xe5375d58ee48aa8b33b3b97b79d503eb3d7a3c92b90ac312a2d386209a16ff1b)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 637479 gas
deploying "Vendor" (tx: 0x2df0779ea222307500ecc0e0201255f2bf84c3f53e9810c588b3aeb5b3b92ec0)...: deployed at 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 with 331303 gas
๐ต Sending all 1000 tokens to the vendor...
โ confirming...
๐คน Sending ownership to frontend address...
An unexpected error occurred:
Error: ERROR processing /home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/deploy/01_deploy_vendor.js:
TypeError: vendor.transferOwnership is not a function
at Object.module.exports [as func] (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/deploy/01_deploy_vendor.js:33:45)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at DeploymentsManager.executeDeployScripts (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1055:22)
at DeploymentsManager.runDeploy (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/node_modules/hardhat-deploy/src/DeploymentsManager.ts:891:5)
at Environment._runTaskDefinition (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)
at Environment.run (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/node_modules/hardhat/src/internal/core/runtime-environment.ts:129:14)
at SimpleTaskDefinition.action (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/node_modules/hardhat-deploy/src/index.ts:528:32)
at Environment._runTaskDefinition (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)
at Environment.run (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/node_modules/hardhat/src/internal/core/runtime-environment.ts:129:14)
at SimpleTaskDefinition.action (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/node_modules/hardhat-deploy/src/index.ts:605:5)
at DeploymentsManager.executeDeployScripts (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1058:19)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at DeploymentsManager.runDeploy (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/node_modules/hardhat-deploy/src/DeploymentsManager.ts:891:5)
at Environment._runTaskDefinition (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)
at Environment.run (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/node_modules/hardhat/src/internal/core/runtime-environment.ts:129:14)
at SimpleTaskDefinition.action (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/node_modules/hardhat-deploy/src/index.ts:528:32)
at Environment._runTaskDefinition (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)
at Environment.run (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/node_modules/hardhat/src/internal/core/runtime-environment.ts:129:14)
at SimpleTaskDefinition.action (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/node_modules/hardhat-deploy/src/index.ts:605:5)
at Environment._runTaskDefinition (/home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 1
Command: /usr/bin/node
Arguments: /usr/lib/node_modules/yarn/lib/cli.js deploy --reset
Directory: /home/rishabh/Documents/practice/solidity-practice/challenge-2-token-vendor/packages/hardhat
Output:
info Visit https://yarnpkg.com/en/docs/cli/workspace for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The contract should have the transferOwnership function. Are you sure that you're not running with an old version of the code that did not have Ownable?