-
We use blockchain & AI to prevent deepfake
-
We records and manages the deep fake status on the blockchain in a decentralized form by determining the AI status with a single API call, uploading IPFS image data, and issuing NFTs with the uploaded image.
-
Chainlink Functions : The ability to determine deepfakes with AI is transparently determined by a third party through chainlink functions.
-
FileCoin(WEB3Storage) : The results of the AI's deepfake determination are recorded in IPFS storage and then issued as nFTs to permanently immortalize the deepfake.
-
Polygon : Polygon, which supports various services including chainlink functions and has a fast speed and an active NFT market, was selected as the network.
graph TD
A[Client] -->|GET /execute| B[Server]
B -->|Invoke Chainlink functions| C[Chainlink Node]
C -->|Request AI Analysis| O[AI Server]
O -->|Analysis Result| C
C --> D[Return transaction & requestId to Server]
B -->|Store metadata| E[Web3_Storage]
E --> F[Return tokenURI]
B -->|Mint NFT| G[NFT Contract]
G --> H[Return mint tx]
B -->|Response| A
A[Client] -->|POST /api/upload| J[Server]
J -->|Store image| K[Web3_Storage]
K --> L[Return cid]
J -->|Insert in DB| M[MongoDB]
M --> N[Confirm insertion]
J -->|Response| I
O --> P[Access data from MongoDB]
M --> P
style O fill:#f9d71c,stroke:#333,stroke-width:4px
opensea assets link : https://testnets.opensea.io/assets/mumbai/0x6b08108e2Cc129258886faE62e9E4f6e84832Ff2
frontend client and AI server
AI server is open to public so that nodes from chainlink functions could call
# up mongodb
docker compose -f docker-compose.mongodb.yml up -d
# pip install
pip install -r requirements.txt
# run server
python app.py
cd ./deepfake_platform/client
npm install
npm run build
npm run start
guide to run api server in local
cd deepfake_platform/api_server
npm install
npm run start
This API-Server provides an interface to invoke Chainlink functions, store metadata on Filecoin (via Web3.Storage), mint NFTs, and handle image uploads with a determination of whether they're deepfakes or not. Additionally, it interacts with a MongoDB database for data insertion operations.
Set up Node.js and npm.
Install required npm packages and relevant software:
express
ethers
mongodb
@chainlink/functions-toolkit
dotenv
web3-storage
This endpoint performs several operations:
- Invokes Chainlink functions.
- Stores metadata on Filecoin through Web3.Storage.
- Mints an NFT with a provided address and token URI.
sequenceDiagram
participant Client
participant Server
participant Chainlink
participant Web3_Storage
participant NFT_Contract
Client->>Server: GET /execute
activate Server
Server->>Chainlink: Invoke Chainlink functions
activate Chainlink
Chainlink-->>Server: Return transaction hash & requestId
deactivate Chainlink
note over Server: Process Chainlink response
Server->>Web3_Storage: Store metadata on Filecoin
activate Web3_Storage
Web3_Storage-->>Server: Return tokenURI
deactivate Web3_Storage
note over Server: Prepare data for NFT minting
Server->>NFT_Contract: Mint NFT with tokenURI
activate NFT_Contract
NFT_Contract-->>Server: Return mint transaction hash
deactivate NFT_Contract
note over Server: Compile response details
Server-->>Client: Send Chainlink tx, tokenURI, mint tx & Opensea link
deactivate Server
No request parameters are needed for this endpoint.
A string displaying the Chainlink transaction, the decoded Chainlink response (commented out in the given code), the token URI on Filecoin, the mint transaction for the NFT, and a link to view the minted NFT on Opensea (Mumbai Testnet).
GET /execute
This endpoint allows a user to upload an image. It determines if the image is a deepfake and stores this information, alongside the image's CID from Filecoin, in a MongoDB database.
image: The image file to be uploaded.
Returns the cid of the uploaded image on Filecoin.
Using a tool like curl, the request could look like:
curl -X POST -F "image=@path_to_image.jpg" http://your_api_url/api/upload
sequenceDiagram
participant Client
participant Server
participant Web3_Storage
participant MongoDB
Client->>Server: POST /api/upload (image)
Server->>Web3_Storage: Store image on Filecoin
Web3_Storage->>Server: Return cid of image
Server->>MongoDB: Insert image cid and deepfake status
MongoDB->>Server: Confirm insertion
Server->>Client: Send back cid
RPC_URL_MATIC=https://polygon-mumbai.infura.io/v3/
PRIVATE_KEY=
MUMBAI_SCAN=
POLYGON_MUMBAI_RPC_URL=https://polygon-mumbai.infura.io/v3/
PUBLIC_KEY=
WEB3STORAGE_TOKEN=
We need WEB3STORAGE_TOKEN for IPFS upload on FileCoin
homepage : https://web3.storage/ module : https://www.npmjs.com/package/web3.storage
cd contracts
npm install
npm run start
- deployChainlink : deploy FunctionsConsumer contract for Chainlink Functions
- deployNFT : deply ERC721 NFT
- getTokenURI : getTokenURI of NFT
- ERC721 contract (ERC721, ERC721URIStorage, ERC721Pausable, Ownable, ERC721Burnable)
- FunctionsConsumer contract (Consumer Contract for chainlink functions)
PRIVATE_KEY=
TEST_PRIVATE_KEY=
MUMBAI_SCAN=
POLYGON_MUMBAI_RPC_URL=https://polygon-mumbai.infura.io/v3/
RPC_URL_MATIC=https://polygon-mumbai.infura.io/v3/