So you actually want to learn public blockchain and not just re-post generic “blockchain is revolutionary” articles on LinkedIn & Twitter. The best way to jump-start technical learning is doing a small side project and putting it into production in my opinion. You can even use this for your blockchain startup idea. We created a fictional character cards trading platform on Ethereum and I will briefly explain its smart contract below for you to replicate in building your own project.
Our project, Cryptochars.com is a marketplace in which traders can buy, sell, trade, and discuss digital fictional characters such as Sherlock Holmes. We emulated rare, collectible cards with Ethereum tokens, and each of these tokens follow Ethereum’s ERC-721 protocol. ERC-721 is a free, open standard that describes how to build non-fungible or unique tokens on the Ethereum blockchain. While most tokens are fungible (every token is the same as every other token in the case of cryptocurrencies), ERC-721 tokens are all unique. You can think of them like rare, one-of-a-kind collectables.
ERC721 tokens can be used in any exchange, but their value is a result of the uniqueness and rareness associated with each token. The standard defines the functions name , symbol , totalSupply , balanceOf , ownerOf , approve , takeOwnership , transfer , tokenOfOwnerByIndex , and tokenMetadata . It also defines two events: Transfer and Approval. I will not get into the details of these standard functions but they can be found on Ethereum’s web site. You can use Ethereum’s online editor Remix for modifying the Solidity smart contract code.
Here’s a step by step recipe for you to create your own similar digital collectible project on Ethereum:
- Study the Cryptochars.com site marketplace and see what you want to replicate versus change. Buy and sell a character if you want to experience the mechanism. (You need metamask for desktop or coinbase wallet for mobile trading, and some ETH coins).
- Copy the smartcontract code of Cryptochars.com from: https://etherscan.io/address/0x7eda2301cb535e2ea8ea06237f6443b6268e2b2a#code
- Open https://remix.ethereum.org and paste the smart contract code there as a new file. Remix is an online Solidity (Ethereum smart contract coding language) editor. You can write your code there and deploy it from there straight to Ethereum main net or any of the test networks such as Ropsten.
- Edit the lines 48 to 55. Define your own token name, token prices and how their price increase with each trade, etc. in this section. You probably do not want to change the lines above as they mostly define the ERC-721 protocol.
- Lines 58–88 define the storage for tokens, owners, etc. Change their names to make them make sense according to your own project. You can define new storage buckets or delete some if not needed. You probably need to understand the data mechanisms a little to be able to do that. You can study that from Ethereum docs. Be careful with storage design as storing data permanently is the most expensive piece when transacting with smart contracts. Unlike regular code, Solidity on Ethereum requires GAS (transaction fees) most of the times you run it (depending on functions you call). Cryptochars.com defines each character with its Wikipedia unique id succeeded by _ and the character’s name, ie; 27159_Sherlock Holmes. Each character token also has a sequential token id kept internally in the smart contract.
- Lines 90–118 define the access modifiers. These are special roles that have privileges when running transactions. Typical roles you would need are Clevel, CEO, CFO, COO to perform the related operations.
- Lines 119–158 in the constructor. It initializes the contract with its initial set of data. In our case we defined who the C level officers are (you do not need to modify this), bonus mechanism parameters (you can delete all the bonus related functionality if you want), and the first batch of characters(modify these according to your project). You can also create characters after you create the smart contract as we also built a function for that. Consider the GAS spend optimization for these decisions.
- Lines 160–234 are the public functions; they can be called from outside the contract. Private functions can not be called from outside the contract. Our public functions getting character details, changing character details (on C Level can), overriding character price (only owner can), getting character tokens of a user, getting contract balance, etc. This project takes 6% commission on each trade to pay for its hosting and maintenance costs. You can modify this as you want on line 275.
- Below the functions are the function definitons of ERC-721 (above we only declared them). The withdrawfunds function enables getting funds out of the contract balance (only C Level can ).
- At the very bottom we defined a safemath library for preventing overflows when working with uint, as this can become material with monetary functions.
- Compile your code in remix, fix errors and deploy it to Ropsten network. You can get free ETH tokens for deployment from Ropsten faucet (GAS is needed for contract deployment).
- Test your smart contract functions extensively from Remix.
- Develop your front end and tie your smartcontract (using the ABI) to your code. We developed with Node.js, Vue storefront and deployed to Firebase. We used github, Google docs and trello for development processes.
- If all is well, deploy to Ethereum main net. Note your contract number. Also verify your code (there’s a process for it).
- Create social media profiles on Instagram, Twitter, Facebook, etc and share your project.
- Submit your Dapp (distributed ledger app) to Dapp indices such as State of the Dapps: https://www.stateofthedapps.com/dapps/cryptochars , Dapp.com: https://www.dapp.com/dapp/CryptoChars , DappRadar: https://dappradar.com/app/1042/cryptochars , DappStore: https://dappstore.link/dapp/cryptochars .
So, that’s it! Now you should have your own smart contract digital collectibles platform on Ethereum. Users of it can trade cards using ETH cryptocurrency. More importantly, you can talk knowledgeably about blockchain, ethereum and smart contracts unlike many.