[New Year's Plan] Red Packet Coins for Chinese New Year | Smart Contract Development Plan #1

科技隨筆
·
·
IPFS
·
The 2022 Chinese New Year is coming at the end of January! Speaking of the New Year, it is more or less inevitable for the family to reunite for a reunion dinner. It is this time again. As a social animal, have you decided how many red envelopes you will give to your family this year? For this New Year's Eve, force relatives to download wallets, and directly shoot the fortune coins, red envelope coins, wait-and-wait coins, and university extension coins that you designed to them during the New Year!

happy New Year!

After careful consideration, I decided to start a special project in January to share with you how to issue your own cryptocurrency. This year, I will force my relatives to download wallets for the new year, and directly transfer your fortune coins, red envelope coins, sit-and-wait coins, university Yanbitong was shot at them during the Chinese New Year. In addition to allowing them to experience the feeling of getting cryptocurrency for the first time, maybe you can also think about your own token economy, for example, 100 million NT dollars can be exchanged for one candle. A big meal or something, not so romantic.

So this month is expected to take about four weeks and a total of four articles. Get your coins ready before the New Year. Let’s send your own cryptocurrency to friends and relatives around as a blessing, it will be cool! We will test it on the local side first, and then send it to the Ethereum test network. All operations on the Ethereum test network are free of money, and of course the money above has no value at all. After confirming that there is no problem with our smart contract on the Ethereum testnet, we can consider sending coins on the Ethereum mainnet or Polygon, or sending coins on the testnet to relatives.

Well... But there are some things that I haven't had time to write in my article. In this article, we will briefly talk about the things that may be used in the future. If there is something that is not clear or wrong, please leave a message and tell me, I will follow up. make adjustments in the article. This article is to let everyone warm up first, divided into six themes:

1. Blockchain Explorer

2. Smart Contracts

3. Solidity

4. Remix

5. Ethereum mainnet and testnet

6. Prepare in advance

Please pay special attention! Since some things in this article will need to be connected to external URLs, I will type out the URLs. These sites will never ask you to enter any wallet private keys or mnemonics, or ask you to pay first. To use it, remember to check the URL before operation. If possible, try not to go to Google to search directly, so as not to accidentally fall into a scam or phishing website.

blockchain browser

Regarding the blockchain browser, I mentioned in my previous article "I bought the last Travelloggers with 10,000 yuan" what is a blockchain browser, how to use it, and what special functions it has. If you haven't read it, you can go back and read it first. Check it out and do some manipulation and research. Since we are going to develop our own programs in the future and use these codes to issue our own cryptocurrency, be sure to touch a browser like Etherscan before playing with these things. The URL is https://etherscan.io/ and put your Copying the wallet address and checking the balance will be very helpful to our future development staff.

smart contract

Since the birth of Bitcoin in 2009, in the past, if people wanted to create their own cryptocurrency, they had to create their own chain first, because the blockchain at that time was a ledger, and the transaction content recorded in the ledger was written. The currency will be the currency issued on it, so it is usually faster to copy the code of Bitcoin directly, change it, and resend a blockchain of your own, or take a snapshot of it and directly fork out a new currency. In short, if you want to issue your own cryptocurrency, you must first create your own blockchain, and then you have to have miners to help maintain this new blockchain. The threshold is quite high and it is very troublesome, so in 2015, ethereum appeared. Square, and smart contracts.

The emergence of Ethereum helps everyone to build the infrastructure of a blockchain. Everyone can use Ethereum as a foundation and write smart contract code on it to issue their own tokens. Because you don't need to build your own blockchain, but attach your own tokens to Ethereum, which greatly reduces the threshold for issuing currency, so all kinds of cryptocurrencies, and even NFTs, have sprung up like mushrooms after a rain. emerge.

Normally, if you want to issue your own currency, you need to write a smart contract, but on application platforms such as OpenSea, we can issue and transfer our own NFT without writing a program. In fact, we call the smart contract developed by OpenSea behind it. Oh here.

A smart contract is simply a code that runs on the blockchain. In addition to our goal of issuing our own cryptocurrency this time, smart contracts can also be used to write many different decentralized applications (Dapps), but We won't talk about it more, you can think of them as one vending machine with different functions, choose a different vending machine, throw a coin in, tell the machine the service we need now, and the vending machine will automatically spit it out As a result, compared to our development goal this time, it will be to throw the wallet address and parameters into it, hoping that this smart contract can create a new Canadian currency, and can have the service of transferring money to other people's wallet addresses.

Solidity

Solidity is a new programming language influenced by C++, Python and JavaScript, and its goal is to develop smart contracts. With Solidity, we can write applications with business logic and automatically run these services on the Ethereum Virtual Machine (EVM) after compilation, so for procedural people, although the logic is similar when learning Solidity. , but you need to learn more about business knowledge, otherwise you will not be able to fully understand the code!

Due to the decentralization and immutability of the blockchain, once these applications are placed on the blockchain, they cannot be modified, so there is no need to worry about being destroyed by anyone, and no one can arbitrarily change the game rules of this smart contract .

Here is the sample code for Solidity, to see what it might look like:

 // SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

contract Variables {
    // State variables are stored on the blockchain.
    string public text = "Hello";
    uint public num = 123;

    function doSomething() public {
        // Local variables are not saved to the blockchain.
        uint i = 456;

        // Here are some global variables
        uint timestamp = block.timestamp; // Current block timestamp
        address sender = msg.sender; // address of the caller
    }
}

If you have learned JavaScript, you should feel quite similar. If you don’t understand it at all, it doesn’t matter. After you start writing it, you can study it later. For these examples, there is a website at https://solidity-by-example.org/ variables/ , there will be newer versions of Solidity code examples to learn from.

Remix

Remix is an online Solidity programming language editing environment provided by Ethereum to developers. The website is https://remix.ethereum.org/ . The screen you see should be similar to this:

On the far left, you can see six icons from the top.

The first is Remix's logo.

The second is the file manager, which is already selected when the web page is opened. The file manager allows us to see all the files in the current Remix online development environment.

The third one is Solidity's compiler. Its purpose is very important. After we write the program (smart contract), we rely on this compiler to convert the code that humans can understand into the language that the computer can understand. Let the computer do what we want it to do.

The fourth is to release and execute the smart contract that has just been compiled. It does not mean that the compilation of the smart contract is completed. Like our theme this time, issuing our own cryptocurrency, then before letting the computer execute the smart contract, we must still First tell it some important parameters, such as the name of the currency, the total circulation, which blockchain to issue on, which wallet to send all the money to, etc. Complete release of our smart contract!

The fifth looks like a plug, we should not use it this time, this Plugin manager can add some extra kits to help us develop different smart contracts.

The sixth is the setting, and at the bottom on the left, for example, you can change the background theme to a light color function.

Just click on the file manager and select a program file, and the code will be opened in the largest block on the right. This is where the program is written, and the lower part on the right is when we want to publish or execute the compiled version. When writing the code, it will display the success or error, which can help us detect errors in the program or contract.

After that, we will develop and issue our own cryptocurrency on Remix, because Remix is an online integrated development environment officially provided by Ethereum. Such a Buddha-hearted tool makes us completely unnecessary to install a bunch of different versions of the environment on the computer beforehand. Reduce the development threshold and the opportunity for errors. If there is a version upgrade of Solidity in the future, it will be easy to switch.

Ethereum's mainnet and testnet

Mainnet refers to the Ethereum blockchain that we usually use. The ether coins and various things in circulation on it are true, but if we are developers today, we must not want to write our own. Every time the program wants to be executed and verified, it must be put on the blockchain, because all operations on the chain are a considerable fee, and program development is usually not in place at one time, and it is always necessary to repeatedly verify to avoid What kind of loopholes are there.

At this time, it is time for the testnet to appear. You can think of the testnet as the same Ethereum, but the ether and all the currencies in circulation are toy banknotes. Common Ethereum testnets include Ropsten, Rinkeby, Kovan , Goerli, etc. Note that different testnets represent different blockchains!

Although any of the above operations also need to consume ether, but that is fake ether, the real world does not exist, it only exists in fantasy (real ether does not seem to exist in the real world...), then these ether How to get coin toy banknotes? So an interesting first step, we are going to collect the money now, free money!

First of all, you must have Metamask first, because we will develop on it later. Usually, we will install the plug-in directly on the Chrome browser. If you don't have it, the URL of Metamask is https://metamask.io/ , and you can also go to the Internet Check how to set up and start using the Metamask wallet on the road, remember to keep the mnemonic or private key, don't tell anyone, otherwise once someone knows your private key, they have the right to steal all the money in the wallet. , be sure to pay attention!

There is a place in the testnet, as long as you give it the wallet address, it will send fake ether to that wallet, probably because sending money is like running water, also known as Faucet, in different testnets There are different faucet URLs. Metamask should pay attention when switching the mainnet. If you receive ether on the Ropsten testnet, but the wallet network is still on the ethereum mainnet, the money you receive for free will not be available. display.

Two steps for Metamask to switch to the Kovan testnet:

1. Click the drop-down menu of "Ethereum Main Network" in Metamask


2. Select Kovan Testnet


Then, copy your wallet address, and we go to the faucet to collect money! The URL is https://linkfaucet.protofire.io/kovan , and the page will look like this after opening:

The Network on the left shows the test network Kovan for Ethernet access. Of course, you can click on the drop-down menu to switch to a different test network, but our development will be on Kovan this time, so just get the ETH of the Kovan test network. Enter the wallet address, press I'm not a robot and Sand request.

After pressing, the faucet will send a transaction, transfer the ETH and LINK coins to us on the chain, and see "Waiting for confirmation" indicating that these assets are on the chain, you can wait for a while until it becomes "Request complete" and it is successful ! Go back and open your Metamask wallet to see the 10 Kovan LINK and 0.1 Kovan ETH just sent. Again, the money here is just a toy banknote. Even if you have 100,000,000 ETH, its asset value is 0!

a

After reading this warm-up, the main thing to do is to read this article first, then prepare a Metamask wallet, switch it to the Kovan testnet, and then go to the faucet to receive free testnet ether; The learning part is learning to use a blockchain browser, and seeing what the Solidity programming language and Remix development environment might look like.

Next articleWe are about to start building our own cryptocurrency on Remix, so stay tuned!


Finally, thank you for taking the time out of your busy schedule to read my articles. If you still like these content, I hope to get your follow-up and support. You are also welcome to click this link to find me on other platforms .

See you next time o((>ω< ))o~

Original link ITechNote technology essay

CC BY-NC-ND 2.0

Like my work? Don't forget to support and clap, let me know that you are with me on the road of creation. Keep this enthusiasm together!

logbook icon
科技隨筆| 科技閱讀 | 程式語言 | 理財規劃 | 工具推薦 | 音樂盛宴 | 生活雜談 | 科技隨筆中,不只有科技! 在這裡,我會隨筆記下科技閱讀、程式語言、理財規劃、音樂饗宴以及生活雜談等等內容。 邀請您在過程中與我一同分享也一同成長。 讓我們在人生的旅途中不斷學習,努力成為更棒的人吧~ 在其他平臺關注我: https://linkby.tw/itechnote.co
  • Author
  • More

【音樂月報 #13】2022年10月號

【音樂月報 #12】2022年9月號

【音樂月報 #11】2022年8月號