Git Product home page Git Product logo

token_1608139092543's Introduction

Token tutorial

This example dapp builds off learnings from our first tutorial, Hello World. We recommend you start there.

The goal of this tutorial is to teach you how to:

  • Write and deploy a smart contract that issues tokens
  • Build a web application that interacts with your smart contract
  • Understand the basics of Ethereum accounts and how they represent both users and smart contracts on the blockchain
  • Transfer tokens between Ethereum accounts by initiating transactions with your smart contract

If you'd like to learn more about how Ethereum works before diving in, we recommend you start here.

Introduction to tokens

What is a token?

Ethereum tokens are simply digital assets that are built on top of the Ethereum blockchain using smart contracts. Tokens are used across many Ethereum projects.

Why create a token?

A token can serve many purposes, such as a stablecoin, or to track a point system (such as Reddit's "community points"), or even to represent shares of voting rights over a project. By representing things as tokens, we can allow smart contracts to interact with them, exchange them, create or destroy them.

You may have heard of ERC20, a token standard established by the Ethereum community to promote interopability across applications. In this example, you'll create a more simple token but we invite you to extend the contract code in order to satisfy the formal specification.

The smart contract

At its core, a token contract is a mapping of addresses to balances, with some methods to add and subtract from those balances.

Let's find the smart contract.

Use the Explore panel on the left of the IDE to navigate to the Files/contracts/Token.sol file.

Return here once you've read through the file.

Every smart contract runs at an address on the Ethereum blockchain. You must compile and deploy a smart contract to an address before it can run. When using Studio, your browser simulates the network, but there are several test networks and one main network for the Ethereum blockchain.

1. Compile

Solidity is a compiled language, and you need to convert the Solidity code into bytecode before the contract can run. We will automatically compile the code every time you save your contract (by clicking the floppy disk icon at the top of a file) or when performing a deployment.

2. Deploy

Now let's deploy the Token.sol contract. In the left panel of the IDE, you'll find the Deploy panel (the rocket icon). Deploy the contract by selecting the "Deploy" button within the Deploy panel.

You should now see successful output from the IDE's Console (lower right panel) and a web form in the IDE's Browser. This form allows you to interact with your deployed token contract.

The web app (dapp)

As you learned in the Hello World example, dapps typically use a JavaScript convenience libraries that provide an API to make integrations with smart contract easier. In this project, you'll again be using web3.js.

Let's take a look at our application logic.

Use the Explore panel to navigate to the Files/app/app.js file.

Return here once you've read through the file.

Interact

Now that you have an understanding of the logic, let's use the app UI to interact with the contract!

Find your Ethereum address

At the top right of the IDE, find the Account dropdown menu (the "Default" account is pre-selected). Click to "Copy address" (the paper icon), then paste your address into the "Mint new tokens" address input field. Enter an amount and click "Mint".

Behind the scenes, submitting the form should trigger our JavaScript function, createTokens, which creates an Ethereum transaction to call the public function, mint on your smart contract and to update the contract's state.

View you transactions

Find the "Transactions" tab on the right panel of the IDE. Here you can inspect all transactions you've triggered on your deployed contract.

Mint tokens

Try using the Account dropdown menu to create a new Ethereum account, then transfer tokens to that account from your "Default" account (the account you deployed the contract on). You can verify if this worked using the "Check balance of address" form.

Next Steps

Congratulations! You've made it through our second tutorial. You've taken another important step towards building on Ethereum.

Our final Ethereum Studio tutorial is our most complex example. We recommend you build a "CryptoPizza NFT" next.

Learn more

Want to learn more about Ethereum tokens?

Ready to move on from Ethereum Studio? Here's some other useful online resources to continue your dapp development journey:

  • CryptoZombies: Learn Solidity building your own Zombie game
  • Open Zeppelin Ethernaut: Complete levels by hacking smart contracts
  • ChainShot: Solidity, Vyper and Web3.js coding tutorials
  • Consensys Academy: Online Ethereum developer bootcamp
  • Remix: Web-based IDE for working on Solidity and Vyper smart contracts with in-line compile errors & code auto-complete

Local development

Looking to set up a local Ethereum development environment? Start here.

token_1608139092543's People

Contributors

mingder78 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.