-
An auctioneer creates an auction in the smart contract. He decides the auction duration. Also, the auctioneer gives allowance to the Auction contract for a particular NFT, which will be the prize of the auction. Once the auction is created, the Auction contract takes the NFT from the auctioneer.
-
Any user who is willing to bid for an NFT has a positive USDC token balance. This user gives USDC allowance to the Auction smart contract.
-
The bidder places a bid by choosing an auction ID and the amount of USDC he is willing to offer. If his offer is higher than the current highest bid, then the bidder's offer is accepted
-
Once the time frame for an auction ends, anyone can terminate the auction, triggering the transfer of NFT to the highest bidder.
-
Bidders (other than the winner) will be albe to withdraw their USDC invested in the auction process.
Note
This contract interacts with 3 contracts: USDC Token (ERC20 Contract), Auction and NFT Contracts
Note
Hardhart Ignition is like a deployment manager. It helps publish smart contracts in a very reliable and structured way. It can resolve dependencies between contracts and other deployment steps.
Note
Deployment Ignition Script: It's a reusable script for publishing smart contracts.
Resources: https://hardhat.org/ignition/docs/getting-started
$ mkdir ignition
$ mkdir ignition/modules
$ mkdir ignition/modules/auctionDeployment.js
#auctionDeployment.js
const { buildModule } = require("@nomicfoundation/hardhat-ignition");
module.exports = buildModule("DeployAuction", m => {
const owner = m.getAccount(0);
const initialOwner = m.getParameter("initialOwner", owner);
const usdcAddress = m.getParameter("usdcAddress", ethers.ZeroAddress);
// Auction Constructor
const auction = m.contract("Auction", [initialOwner, usdcAddress]);
return { auction };
});
==amoyParams.json==
{
"DeployAuction": {
"usdcAddress": "0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582"
}
}
This takes the usdcAddress parameter for the DeployAuction module from auctionDeployment.js to this "0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582".
npx hardhat ignition deploy ignition/modules/auctionDeployment.js --paramaters ignition/amoyParams.json
npm i @nomicfoundation/hardhat-ignition-ethers
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
export default buildModule("Apollo", m => {
const apollo = m.contract("Rocket", ["Saturn V"]);
m.call(apollo, "launch", []);
return { apollo };
});
Note
Modules are created by calling the ==buildModule== function, which requires a module ID and a callback function. This is where the module definition actually happens.
The m parameter passed into the callback is an instance of a ModuleBuilder, which is an object with methods to define and configure your smart contract instances
These ModulBuilder methods create a Future object, which represents the result of an execution step that Hardhat Ignition needs to run to deploy a contract instance or interact with an existing one. E.G. (contract and call methods). "Contract method" deploys the contract instance, specifying "Saturn V" as the only constructor parameter. "Call method" executes the contract methods "launch"
The below command runs the local node
npx hardhat node
Executing Hardhat Ignition
npx hardhat ignition deploy ignition/modules/Apollo.ts --network localhost