Pratham Prasoon Profile picture
Dev Rel Engineer @MovementLabsxyz 🥑🔬 Python, JavaScript, & Rust junkie. Building things I love with blockchains by the day, working on AI at night 🛠️

Nov 21, 2021, 15 tweets

You make your own cryptocurrency on the blockchain with JavaScript in just these 9 lines of code.

Here's how it works🧵

We'll be using thirdweb's JavaScript sdk to make this happen.

To start you'll need to setup Metamask and store your private key, here's a guide that'll take you through the entire process.

🔗 thirdweb.com/portal/guides/…

Next head over to thirdweb.com/start, you will be guided through a setup process.

These steps are to get your metamask setup with the thirdweb interface.

These steps are for choosing the chain network, we'll go with the rinkeby testnet.

Our currency will be minted on this "fake" test network called rinkeby for free.

Now we can create the project to which we'll be adding the NFT module to create our own currency 🤑

Adding the Token module, some details... and ther you go!

We actually can now mint our currency straight from the dashboard.

But we don't do that, we're JavaScript programmers.

Make sure you copy the "module address" from the previous step which we'll use in the code.

Just click on the pill and it'll copy it for you.

Now onto the code.

Using these commands we'll install the thirdweb sdk and the types library.

Additionally you can install TypeScript if you want to.

We'll import the thirdweb library and ethers js for connecting our wallet and also import the private key that you should remember from the metamask guide.

Remember to store your private key safely and do not share them with anyone.

We will now instantiate the sdk, add our private key and connect to the blockchain.

Now can add the module address from the dashboard and the finally use it to mint our currency.

This piece of code mints 1000 Pratham coin, notice how we `ethers.utils.parseUnits("1000",18)` instead of just passing '1000'.

Here's why...

Transactions on the blockchains are incredibly precise, upto 18 decimals.

Passing 1 as the amount would not mint 1 Pratham coin but instead mint 0.000...18 zeros...1, to compensate for this we use ethers here.

The number being passed it 1000 x 10^18 = 1000 for the blockchain

Also, we cannot simple use the regular `1000 * (10**18)` math expression in JavaScript because Js is capped to 2^64 - 1 numbers.

Solidity which is on the backend of thirdweb is capped to 2^256 -1 numbers.

tldr; Js cannot handle big numbers, which is why we use ethers.

Now looking at the dashboard you'll see that our cryptocurrency has been minted.

Congrats, now its time to use it 😉

If you liked this thread make sure you retweet it and follow @PrasoonPratham

Want to read this thread later?

Save it as a link and you'll find lots of other awesome web3 content on our portal.

thirdweb.com/portal/guides/…

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling