Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to compile and deploy Ethernet Square Smart contracts using Remix

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to use Remix to compile and deploy Ethernet Square smart contracts", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use Remix to compile and deploy ethersquare smart contracts.

Remix is an open source Solidity intelligent contract development environment that provides basic functions such as compiling, deploying to the local or testing network, executing contracts, and so on. Solidity is the official design and supported development language of ethernet ethereum, specifically for writing smart contracts.

This article hopes to deploy a very simple token contract (can only be issued and transferred) on the local and test network to test its functionality.

Describe in detail the steps of using Remix and the problems that may be encountered in using it.

It is a pity that I have developed an Ethernet Square Ethereum intelligent contract before, but I have not recorded the development process and the problems encountered. Start again this time, start from the most basic, and learn step by step.

Development environment

No installation is required, just launch Remix in any browser.

Obtain a token contract

There are many examples of token contracts, and the Ethereum website provides a minimum executable token contract (MINIMUM VIABLE TOKEN):

Pragma solidity ^ 0.4.0X contract MyToken {/ * This creates an array with all balances * / mapping (address = > uint256) public balanceOf; / * Initializes contract with initial supply tokens to the creator of the contract * / function MyToken (uint256 initialSupply) public {balanceOf [msg.sender] = initialSupply / / Give the creator all initial tokens} / * Send coins * / function transfer (address _ to, uint256 _ value) public {require (balanceOf [msg.sender] > = _ value); / / Check if the sender has enough require (balanceOf [_ to] + _ value > = balanceOf [_ to]); / / Check for overflows balanceOf [msg.sender]-= _ value / / Subtract from the sender balanceOf [_ to] + = _ value; / / Add the same to the recipient}}

This MyToken contract is really simple and can only do two things:

Create tokens: create a specified number of tokens when initiating a contract. The token owner is the Ethereum account that initiated the contract.

Transfer tokens: transfer a specified number of tokens to a specified Ethereum account

As for a complete token contract, please refer to the ERC20 Token handheld.

Compile contracts with Remix

Click the upper right corner + add a contract name as long as the extension is ".sol".

Copy the contract content to the contract and compile the Remix default settings will compile automatically, as long as there is no red error prompt next to it, the compilation is successful.

Deploy contracts locally

1. Set up the run on the upper left of the network click.

Environment chooses JavaScript VM to mean that all data exists locally (function similar to testrpc). It will provide five virtual accounts, each with 100 ETH, and choose any one (remember to use it later).

two。 Send deal deployment contract selection MyToken. You can see the create button. And it has been shown that initialSupply (that is, the number of tokens to be issued) must be entered according to the content of the contract. Enter a catalog point create to send the transaction deployment contract.

After the contract is successfully deployed, you can see the user interface of the contract. Remix will automatically generate the corresponding contract user interface according to the content of the contract. You can see that the contract has two functions: balanceOf (query balance) and transfer (transfer token).

You can see the log below (record each operation). In fact, the deployment contract is completed through an Ethereum transaction, and click Details to see the details of the transaction.

Execute the contract  -  to query the balance

1. Select the account that just initiated the contract

You can click the button on the right to copy

two。 Enter an account and note that you want to enclose the account with "". Example:

"0xca35b7d915458ef540ade6068dfe2f44e8fa733c"

3. Click balanceOf

You can see the execution result, that is, the token balance of the current account.

A possible error.

To make it clear, because the data is transmitted in JSON format, add "". If you forget "", you will see an error message in log:

Execute the contract  -  transfer tokens

1. Select the account you want to export. Select the account of the contract you just initiated.

two。 Enter the account you want to transfer and select and copy another account. Enter the number of tokens to be transferred to the account and the number of tokens to be transferred at the input location behind transfer in the contract interface. The account also needs to be enclosed in "", for example:

"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db", 10

3. Click transfer, click transfer, and you will see the log update after success.

4. Confirm that the balance is updated when you inquire about the balance transferred to the account, you can see that the token balance has increased!

Error condition if the account token you choose to transfer is insufficient, the transaction will fail and you will see an error message in log.

Testing the network deployment contract

1. To install MetaMask, first, to connect to the test network, you need to install MetaMask. It is a browser-side Ethereum wallet that can connect to Ethereum public and test networks. You need to set up an Ethereum account after installation, so I won't go into details here.

This is what happens after a successful startup.

We chose Ropsten Test Net.

two。 Select Test Network

Back to Remix, this time Environment selects Injected Web3,Remix to automatically connect to MetaMask.

After a successful connection, you will see the same account and Ether balance as MetaMask.

3. The deployment contract then follows in the same way, press create to deploy the contract, and you will see a pop-up window for MetaMask. Directly press submit to send the deal.

Wait a moment (you need to wait for the transaction to be confirmed), and the user interface of the contract will come out after the deployment is successful.

At this point, I believe you have a deeper understanding of "how to use Remix to compile and deploy Ethernet Square smart contracts". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report