Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(contracts): update repo #34

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 75 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,87 @@
# WORLD NFT
[CNT TOKEN](https://base-sepolia.blockscout.com/token/0x8d098d44032e93528049357611A25Dab4C20230e): This collection is made up world's continents (Africa, Asia, Europe, North America, South America, Australia, and Antarctica). Each continent NFT have an associated opensea metadata standard with a limited supply of 7 items.
Tokens are minted to the contract address immediately during deployment. Then contract owner get to kickstart the auction by calling the `createAuction` methods in ContinentAuction.sol. ContinentAuction.sol is the contract that manages the auctions and bidding. it is initialised with the token address on deployment so tha
This collection is made of up world's continents (Africa, Asia, Europe, North America, South America, Australia, and Antarctica). Each continent NFT have an associated opensea metadata standard with a limited supply of 7 items.
Tokens are minted to the contract address immediately during deployment. Then contract owner get to kickstart the auction by calling the `createAuction` methods in `ContinentAuction.sol`. `ContinentAuction.sol` is the contract that manages the auctions and bidding. it is initialised with the token address on deployment.

## Deployed to Base
[CNT TOKEN](https://base-sepolia.blockscout.com/token/0xC50C83af572e34c0E9de43Be504A3ee4793d59fd)
[Auction Contract](https://base-sepolia.blockscout.com/token/0x572610C23EdA4eD0799447f515D79565644E7161)
## Technologies
- Solidity
- Truffle
- Wagmi
- Express
- Typescript
- React
- Connectkits,
- Viem,
- ReactQuery
- Docker


## Requirement
Node 18 LTS/Hydrogen (LTS is recommended)
Yarn 1+ (1.22.19 is recommended)

## Setup
### Contracts
1. Create an .env file and add variables.
2. Install all the packages
3. Compile contracts
```
truffle compile && truffle migrate
```
4. Deploy contracts
```
truffle migrate --network sepolia
```

### Frontend
1. Change directory to client folder
```
cd client
```
2. Create an .env file and add variables using `.env.example`
3. Install all the packages
```
yarn
```
4. Start frontend application
```
yarn dev
```

## [Backend Endpoint](https://world-token-05ceac17e8ac.herokuapp.com)
### Backend
1. Change directory to client folder
```
cd backend
```
2. Create an .env file and add variables.
3. Install all the packages
```
yarn
```
4. Start backend server
```
yarn dev
```
### Endpoints

`/auctions` - merged token data from zora indexer and contract data to display the list of continents.
`/auctions` - merged token data from zora indexer and contract data to display the list of continents.

`/citizenship/join` - api to join a continent as a citizen after auction. transaction should be signed on the dapp and signed transaction hash is send to the backend to be executed.
`/citizenship/join` - api to join a continent as a citizen after auction. transaction should be signed on the dapp and signed transaction hash is send to the backend to be executed.

## [Frontend DAPP](https://world-q67k4f32u-payscout.vercel.app/)
The frontend showcases a public english auction where the highest bidder automatically wins the token after the deadline
Tools used - Wagmi, Connectkits, Viem, ReactQuery

## [IPFS Metadata Script](https://github.com/timi-codes/world-nft/blob/main/scripts/deploy_metadata.mjs)
## Deployment
[Frontend](https://world-nft-gamma.vercel.app/)

[Backend](https://world-token-05ceac17e8ac.herokuapp.com)

#### Contract( Chain - Base Sepolia)
[CNT TOKEN Contract ](https://base-sepolia.blockscout.com/token/0xC50C83af572e34c0E9de43Be504A3ee4793d59fd)

[Auction Contract](https://base-sepolia.blockscout.com/token/0x572610C23EdA4eD0799447f515D79565644E7161)

[IPFS Metadata Script](https://github.com/timi-codes/world-nft/blob/main/scripts/deploy_metadata.mjs)
This script spins up a [Helia](https://github.com/ipfs/helia) IPFS Node and Pinned collection to Pinata pinning services.
Tools: Helia, Pinata, IPFS Desktop

## Smart Contract

I developed two contracts. CNT is an ERC721 NFT. Tokens are minted to the contract address immediately during deployment. Then contract owner get to kickstart the auction by calling the `createAuction` methods in ContinentAuction.sol. ContinentAuction is initialised with the token address on deployment.
1. Deployed to [CNT TOKEN](https://base-sepolia.blockscout.com/token/0x8d098d44032e93528049357611A25Dab4C20230e) [File](https://github.com/timi-codes/world-nft/blob/main/contracts/ContinentToken.sol)
2. Auction Smart Contract [](https://github.com/timi-codes/world-nft/blob/main/contracts/ContinentAuction.sol)
## Contributors
- [timicodes](https://github.com/timi-codes)

2 changes: 1 addition & 1 deletion backend/src/controller/auction.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const getAuctions: RequestHandler<{}, ResponseData, {}, {}> = async (req,
status: BigInt(auction.status).toString(),
highestBid: BigInt(auction.highestBid).toString(),
bidIncrement: BigInt(auction.bidIncrement).toString(),
highestBidder: BigInt(auction.highestBidder).toString(),
highestBidder: auction.highestBidder,
startTime: convertToNumber(auction.startTime) > 0 ? new Date(convertToNumber(auction.startTime) * 1000) : null,
endTime: convertToNumber(auction.endTime) > 0 ? new Date(convertToNumber(auction.endTime) * 1000) : null,
bids: bids.map((bid: any) => ({
Expand Down
2 changes: 1 addition & 1 deletion backend/src/controller/citizenship.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const web3 = new Web3(process.env.WEB3_PROVIDER as string)
export const joinCitizenship: RequestHandler<{}, ResponseData, CitizenPayload, {}> = async (req, res) => {
try {
const { signed_trx_hash } = req.body

const trx = await web3.eth.sendSignedTransaction(signed_trx_hash)

return res.send({
Expand Down
9 changes: 4 additions & 5 deletions client/src/components/ContinentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ const ContinentCard = ({ continent }: { continent: Continent }) => {
const createAuction = () => {
writeContract({
abi: ContinentAuction.abi,
// address: AUCTION_CONTRACT_ADDRESS,
address: "0x0686b68Ed021883D5aCEeEE52c93E93937e1ed81",
address: AUCTION_CONTRACT_ADDRESS,
functionName: 'createAuction',
args: [BigInt(continent.tokenId), parseEther(startPrice), parseEther(bidIncrement.toString()), BigInt(duration)],
})
Expand All @@ -64,10 +63,10 @@ const ContinentCard = ({ continent }: { continent: Continent }) => {
const buyCitizenship = async () => {
writeContract({
abi: ContinentToken.abi,
address: "0xDD250DBa2b92C26150ab735FF9FE990A96B6b156",
address: TOKEN_CONTRACT_ADDRESS,
functionName: 'buyCitizenship',
args: [BigInt(continent.tokenId)],
value: parseEther("0.001")
value: parseEther(continent.citizenTax)
})
}

Expand Down Expand Up @@ -114,7 +113,7 @@ const ContinentCard = ({ continent }: { continent: Continent }) => {
<div className="flex items-center justify-between w-full mx-4 opacity-90 h-full mt-2">
{
continent.metadata.attributes.map((attr) => (
<div key={attr.trait_type}>
<div key={`${attr.trait_type}-${attr.value}`}>
<p className="text-xs font-light opacity-70">{attr.trait_type}</p>
<p className="-mt-0 text-[14px]"> {attr.value}</p>
</div>
Expand Down
12 changes: 12 additions & 0 deletions contracts/ContinentAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ contract ContinentAuction is Ownable {
emit AuctionStarted(_tokenId, auctions[_tokenId].startTime, auctions[_tokenId].endTime);
}

function endAuction(uint256 _tokenId) public onlyOwner {
Auction storage auction = auctions[_tokenId];

require(auction.endTime > 0 && auction.status != AuctionStatus.Pending, "Auction not started");
require(auction.endTime <= block.timestamp, "Auction not ended yet");

auction.status = AuctionStatus.Closed;
continentTokenContract.safeTransferFrom(address(this), auction.highestBidder, _tokenId);

emit AuctionEnded(auction.highestBidder, _tokenId, auction.highestBid);
}

function setAuctionStatus(uint256 _tokenId, AuctionStatus _status) public onlyOwner {
auctions[_tokenId].status = _status;
}
Expand Down
2 changes: 0 additions & 2 deletions truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ const path = require("path");
require('dotenv').config();

const HDWalletProvider = require('@truffle/hdwallet-provider');
const { pipeline } = require("stream");
const { hostname } = require("os");
const mnemonic = process.env.MNEMONIC;
const alchemyKey = process.env.ALCHEMY_API_KEY;

Expand Down
Loading