...
/Deploying the Auction Smart Contract
Deploying the Auction Smart Contract
Learn how to deploy a smart contract to Ganache and use the Truffle console to interact with it.
We’ve covered the theory of deploying smart contracts with the Truffle Framework. Now, we'll deploy the Auction
smart contract. While we could deploy it directly to the Mainnet or Goerli, it would be a good idea to first see how it works in a testing environment. For this, we can use one of the local Ethereum implementations, such as Ganache, which we'll cover in this lesson.
Deploy the Auction
smart contract
To deploy the Auction
smart contract, we first need to have an Ownable
instance that'll be sold at the auction. Therefore, we'll write a migration script that deploys the Ownable
instance and then passes its address to the constructor of the Auction
.
const Ownable = artifacts.require('./Ownable.sol')const Auction = artifacts.require('./Auction.sol')module.exports = async function(deployer) {await deployer.deploy(Ownable, 'ticket')const ownable = await Ownable.deployed()await deployer.deploy(Auction, ownable.address)const auction = await Auction.deployed()await ownable.transferOwnership(Auction.address)await auction.startAuction(3600)}
We then start an auction using the startAuction
method. But before we can call it, we need to transfer ownership of the Ownable
instance to the auction contract using transferOwnership
.
Where to deploy the contract
With Truffle, we could deploy our contract to the Mainnet or a test network like Goerli. However, before we do this, it would be a good idea to deploy our smart contract to a local blockchain network. A local test network works in a similar manner to the Remix IDE and emulates Ethereum’s behavior and its JSON-RPC API.
With Truffle, ...