unitimes.media

Global perspective, unique insights

“How do you take a very simple token contract (issued and transferred only) and deploy it locally and on a test network and test its functionality? Hope this article is helpful.”

The development environment

No installation is required to enable Remix directly in any browser.

Remix is an Open Source Solidity smart Contracts development environment that provides basic compile, deploy locally or test the network, execute contracts, and more. Solidity is an official programming language designed and supported by Ethereum specifically for writing smart contracts.

Get a token contract

There are many examples of TOKEN contracts. The official website of Ethereum offers a MINIMUM VIABLE TOKEN:

This MyToken contract is really silly and only does two things:

• Token creation: A specified number of tokens are created when a contract is initiated, and the token owner is the Ethereum account that initiated the contract

• Transfer tokens: Transfer a specified number of tokens to the specified Ethereum account

For a complete Token contract, refer to the ERC20 Token manual.

Compile contracts using Remix

1. Click on the upper right corner + Add a file

Any name as long as the extension is.sol.

2. Copy the contract content to the file and compile it

Remix is automatically compiled by default, and if there is no red ERROR next to it, the compilation is successful.

Deploy the contract locally

1. Configure the network

Click run on the top left.

-Run-

Environment Selects JavaScript VM to indicate that all data is stored in local memory (function similar to TestrPC). It will provide 5 virtual accounts with 100ETH each, choose any account (remember).

-Testing Account-

2. Send the transaction deployment contract

Choose MyToken. You can see the Create button. InitialSupply (that is, the number of tokens to be issued) must be entered according to the contract. Enter a number and press Create to send the transaction deployment contract.

-Create-

After the contract is successfully deployed, you can see the interface to use the contract. Remix automatically generates a contract interface based on the content of the contract. As you can see, the contract has two functions: balanceOf(checking balances) and Transfer (transferring tokens).

– Contract interface –

You can see the log at the bottom. The deployment contract is actually done through a Ethereum transaction. Click Details to see the transaction Details.

-Log-

Enforce contract – Query balance

1. Select the account where the contract has just been initiated

– Click the icon to the right of the account to copy –

2. Enter the account

Please wrap the account with “”.

3. Click on the balanceOf

You can see the execution result next to it, which is the current token balance for this account.

– Balance query succeeded

An error condition

Note that “” is used because the data transfer is in JSON format. If you forget to type “”, you will see an error in log:

-JSON parameter format is incorrect –

Execute contracts – Transfer tokens

1. Select the account to be transferred out

Select the account from which the contract has just been initiated.

– Click the icon to the right of the account to copy –

2. Enter the account to be transferred

Select and copy another account. In the field following transfer in the contract interface, enter the transferred account and the number of tokens to be transferred. Accounts are also wrapped in “”, example

3. Click on the transfer

Click Transfer and you will see the log update.

– Transaction execution log-

4. Confirm balance updates

Query the balance that turn into account again, can see token balance increases!

– Transfer account balance increases –

An error condition

If the selected account token balance is insufficient, the transaction fails and you will see an error in log.

– Failed transaction log-

Test the network deployment contract

1. Install MetaMask

First, to connect to the test network, install MetaMask. It is the browser-side Ethereum wallet that connects to the Ethereum primary and test networks. Andrew needs to set up Ethereum accounts after him. Coach, I “just” want to learn Solidity with detailed steps.

-MetaMask-

– This is what it should look like when it’s successfully opened

– Remember to select RopstenTest Net-

2. Select a test network

Returning to Remix, this time Environment selects Injected Web3, and Remix will automatically connect to MetaMask.

– Success will see the same account and Ether balance as MetaMask –

3. Deployment contract

Then press Create to deploy the contract in the same manner as before, and you will see the MetaMask pop-up window. Click Submit to send the transaction directly.

– Use MetaMask to send transactions –

Wait a little while (because the transaction has to be confirmed) and the interface to use the contract will come out once the deployment is successful.

– The contract interface, of course, is the same length –

You can use the contract in the same way!

conclusion

Remix provides a development environment for Solidity smart contracts that can be easily compiled, deployed, executed and even debugged for beginners with little programming experience. But without version control, testing, and using it with other development tools, it would be inconvenient to actually develop dApps.

 

Originally written by Anderson

Original link:

https://medium.com/taipei-ethereum-meetup/ethereum-%E6%99%BA%E8%83%BD%E5%90%88%E7%B4%84%E9%96%8B%E7%99%BC%E7%AD%86%E8%A8 %98-%E7%B7%A8%E8%AD%AF%E5%92%8C%E9%83%A8%E7%BD%B2%E5%90%88%E7%B4%84%E7%9A%84%E7%AC%AC%E4%B8%80%E7%A8%AE%E5%A7%BF%E5%8B%A 2-%E4%BD%BF%E7%94%A8-remix-4528164d0fde

International fintech new media and community platform

UNITIMES

Address: unitimes. Media

Sina Weibo: @unitimes