🤔 What is TwNFT?
TwNFT is a simple web application that allows you to mint your tweets as NFTs for free.
It is my submission for the Thirdweb x Hashnode Hackathon.
🌐 What is Thirdweb?
Getting started with web3 can be difficult even though it is the hype nowadays. We need to write something called a smart contract, which is required to perform actions on the blockchain. To write smart contracts on the Ethereum blockchain, we need to learn a new programming language called Solidity.
Thirdweb provides us with smart contracts which have been written by professionals in the field. They also provide us SDKs which makes using these easy. This allows people with basic programming knowledge to make web3 applications with ease. Thirdweb also takes care of deploying these smart contracts to the blockchain.
Let us now go back to TwNFT
💡Where did the idea come from?
This hackathon was announced back on the 5th of January, 2022 but I didn't get a solid idea until the 18th of January. So where did it come from?
I came across an application called GitNFT from one of @Chris Bongers's articles. GitNFT lets you mint git commits as NFTs and that is when I thought, "How about minting tweets as NFTs?".
I did some research and didn't find any application that did this so it was a golden opportunity for me 🤩
📚 The tech stack
What technologies did I use for TwNFT?
- NextJS for the website
- TailwindCSS for styling
- Firebase for Twitter authentication and data storage
- Vercel for deploying the frontend
- Express for the backend API
- Heroku to deploy the backend
and of course...
- Thirdweb for web3 authentication and minting the NFT
🧐 How does TwNFT work?
One needs to first sign in with Twitter and then put in the tweet URL for the tweet they want to mint. Before minting, the image that will be minted can also be customized. One needs to assign a name to the NFT and optionally add a description (or else, the tweet's content will be used).
Before minting, we have 2 checks to ensure that the person minting the NFT owns that tweet (this is why they are asked to log in with Twitter) and if the tweet has been minted before or not. We don't allow minting the same tweet multiple times, and this is to ensure that every NFT minted is unique.
Now let us take a deeper dive into the web3 part
A deeper dive into web3 authentication with Thirdweb
Setting up authentication with Thirdweb is as easy as adding ~10 lines of code. I am using the @3rdweb/hooks
package for this application and it is a breeze. The @3rdweb/react
package is easier to implement as it also packs in the UI. However, if you want a custom UI (which I wanted), the hooks package is a better choice.
Do note that you need to be using ReactJS to use any of the aforementioned packages.
Coming to the code, firstly, you need to add the Thirdweb Provider to the application -
import { ThirdwebWeb3Provider } from "@3rdweb/hooks";
const connectors = {
injected: {},
walletconnect: {},
};
const supportedChainIds = [1, 4, 137, 250, 43114, 80001];
function MyApp({ Component, pageProps }) {
return (
<ThirdwebWeb3Provider
connectors={connectors}
supportedChainIds={supportedChainIds}
>
<Component {...pageProps} />
</ThirdwebWeb3Provider>
);
}
Then, it is as easy of using the useWeb3()
hook provided to us by either packages to retrieve the connectWallet
function. We have to now just call this function with the wallet type -
<button
onClick={() => {
connectWallet("injected");
}}
>
Login with Metamask
</button>
Here injected
is for the wallet injected in the browser. This is Metamask in most cases.
For a detailed guide on implementing web3 authentication with Thirdweb, check out their official guide.
A deeper dive into minting the NFT with Thirdweb
I am using the Thirdweb Typescript SDK for minting the NFT on the server-side. Minting should take place on the server-side for security reasons.
Minting with the Thirdweb SDK is extremely easy. Let us see how it works -
First, we initialize the SDK with our private key. Do keep this secret as anyone who has your private key can gain access to your wallet. I am using ethers
for initializing a wallet here.
const SDK = new ThirdwebSDK(
new ethers.Wallet(
process.env.PRIVATE_KEY,
ethers.getDefaultProvider("https://rinkeby-light.eth.linkpool.io/")
)
);
Next, we initialize the NFT Module that will let us mint the NFT -
const nftModule = sdk.getNFTModule(process.env.NFT_MODULE_ADDRESS);
At last, we call the mintTo
function asynchronously -
const result = await nftModule.mintTo(
payload.receiverAddress,
nftMedatada
);
Here the result gives us the NFT's tokenId
. The tokenId
is a unique identifier for the NFT in that collection.
Now, that is it. We have minted an NFT!!!
For a more detailed guide, you can check out Thirdweb's official guide on minting an NFT.
❓ What was this NFT Module?
Thirdweb provides us with many modules and the NFT Collection module is one of them. It allows you to mint an NFT in an NFT collection and that is what we just did!!!
The official collection for this project can be found on OpenSea here.
🖱️ Using TwNFT
To get started, log in with Twitter and head over to the /mint page.
Next, put in the URL to the tweet you want to mint in the textbox on the top and click the arrow -
You should now see a preview of the NFT, something a bit like this -
Feel free to customize the image by clicking on the buttons on the options bar -
Next, click on the "Connect Wallet" button and connect your Metamask wallet. Walletconnect support is coming soon.
You should now see a button saying "Mint NFT" instead of "Connect Wallet" on the options bar. Clicking that should bring up this modal where you can fill out the name of the NFT, and optionally add a description -
After some time, you should get the option to go to the tweet page -
The tweet page will look somewhat like this (do give the image some time to load for the first time) -
Notice that it says the NFT is still being minted and it is going to take 5-10 minutes. Check back after 5-10 minutes and this is what the page should look like -
The NFT is now under your wallet and you can do anything with it, including listing it for sale, selling it, and even transferring it to another wallet.
🖊️ Sidenote
Currently, TwNFT is running on the Rinkeby Test Network. This means all NFTs minted will be on the test network and not on the main network.
However, this is subject to change in the future.
✨ Conclusion
It has been a great journey over the last 13 days making TwNFT, squashing bugs, and implementing features. Excited to see how it goes 😆
Bye, and have a nice day 😁🤞
Top comments (18)
Interesting project, thanks for sharing.
One thing I'm not sure about is the mechanism for accessing the Tweets. It looks like you're effectively minting a screenshot of the Tweet, which does not include the Tweet ID itself. So, what happens if the Tweet is deleted? The Twitter developer policy states
In this case, you wouldn't know if the Tweet was deleted (because you don't have the Tweet ID, unless you kept and check back on the URL); plus since the image is on a blockchain, it cannot be removed, right?
There's also nothing here to stop me from minting your Tweets (or Tweets from anyone) and holding the NFT for them, I guess.
It's a cool project, but I think there are some other aspects to think about :-)
If the tweet gets deleted I cant really do anything. The owner of the NFT can technically burn the NFT but the image stays in IPFS (someone needs the CID to access it though). Also, this is not a screenshot of a tweet but a reproduction of it by retrieving data from the API.
As far as one minting someone else's tweet, it is not possible. When someone clicks the submit button on the mint form, a request is sent to the backend that verifies the ownership of the tweet by matching the tweet's owner's id to the logged in user's id.
ah, that's cool (and a good idea for the ownership!). Thanks for clarifying.
Important note: The image itself is off-chain, but the IPFS link is on-chain. IPFS being as it is technically means the link is slightly more durable than a regular link, but still not infinitely so.
Congratulations my brother, you did a good job. I am also very interested in the project
Very interesting! You can post on this Forem too! 😎
Supper
np 😉
can you accompany me on a supply and demand management project, location of saleswomen... and those who have motorbike or car breakdowns on the move...
what?😉
😂😂
humm
Why?
From a purely technical perspective, why not? It sounds like a cool project.
As for actual use, it's about as useless as NFTs in general.
I'm minting my toenail clippings as we speak
Free NFTs are very tempting. Thanks to this, we can get an NFT for free, which can be really worth a lot. That's why I highly recommend this post if anyone wants to get their free nft: nftmonk.com/how-to-get-nfts-for-fr...