Как создать токен на bep20
Перейти к содержимому

Как создать токен на bep20

  • автор:

Как создать BEP-20 в сети Binance Smart Chain

Блокчейн-технологии сейчас находятся на такой стадии развития, что практически каждый желающий может освоить алгоритмы создания собственных токенов. Так, относительно недавно появилась платформа Binance Smart Chain. Используя эту экосистему, можно создавать токены BEP-20, о чем мы расскажем в сегодняшней статье.

BEP-20 — стандарт токенов, играющий роль технической спецификации в сети Binance. К основному функционалу BEP-20 относятся возврат баланса, перевод средств и т. п.

Почему я обратил внимание на токены BEP-20:

  • на комиссию уходит $0,05, при этом время обработки блока составляет 3 секунды;
  • BEP-20 могут использоваться в качестве основы для создания аналогичных токенов;
  • к токену можно привязать цифровые валюты из других блокчейнов.

BEP-20 является расширением ERC-20, поэтому данные протоколы совместимы между собой. Несмотря на общие черты двух стандартов токенов, между ними есть некоторые различия. К примеру, BEP-20 используется в смарт-цепочке Binance, а ERC-20 применяется в сети Ethereum. Последний стандарт подходит для разработки любых сгенерированных токенов в блокчейне ETH. BEP-20 применяется только для создания себе подобных смарт-контрактов.

How to create and deploy a BEP-20 token to the Binance smart chain

How To Create And Deploy A BEP20 Token To The Binance Smart Chain

BEP-20 is the token standard of the Binance Smart Chain (BSC). The Binance Smart Chain is a programmable blockchain with support for smart contracts and EVM compatibility. This makes it a good candidate for building decentralized applications.

To interact with the BSC blockchain, a token based on the BEP-20 standard, BNB, is required to pay for transactions, just like Ether is used to pay for gas fees in the Ethereum blockchain. In fact, the BEP-20 standard is an extension of the ERC–20 standard on Ethereum. This makes it possible to build decentralized apps on the Binance Smart Chain using current Ethereum tooling.

In this tutorial, we’ll code a sample BEP-20 token by implementing the BEP-20 token standard, deploy it to the Binance Smart Chain testnet using Remix, verify the token source code on BscScan, and, finally, import the deployed token into MetaMask.

We’ll cover the following in detail:

This guide assumes prior knowledge of Solidity and EVM. Here’s a good resource on Solidity and one on EVM.

Implementing the BEP-20 Token Proposal

A BEP-20 token requires certain functions to enable other accounts to interact with it properly. You can take a look at these as outlined in the official BEP-20 proposal. I recommend reading through the proposal to familiarize yourself with the required functions.

Most real-world tokens, however, extend this proposal in different ways. For example, most tokens add the ability to:

  • Mint and burn tokens
  • Transfer ownership of the token contract to a different address
  • Pause/play the token contract as an emergency stop mechanism

For the purposes of this tutorial, we’ll implement the base BEP-20 proposal and allow minting and burning of tokens. You can extend this even more as an exercise to get more familiar with working with tokens.

There are a few prerequisites to coding a BEP-20 token:

    0.5.16 or above

After coding the token in Remix, you can test, and then deploy it to a public network.

For now, open Remix and create a new Token.sol file under /contracts . Make sure it is open in the editor.

Let’s start coding out the BEP-20 token!

Declare a license and the version of Solidity the token is written in (we’ll be using the latest version 0.8 and above.

Create a new contract declaration called Token .

Next, let’s initialize the variables and events required to implement the BEP-20 token standard one by one:

If you read the proposal, you’ll notice the variables share the same name as some functions. This is useful because in Solidity v0.8 and above, public variables automatically generate getter functions.

So, in effect, we’ll have the following functions available automatically:

  • name()
  • symbol()
  • decimals()
  • totalSupply()
  • owner()
  • balanceOf()
  • allowance()

Next, we define the constructor of the token contract. In this constructor, we specify the token’s details, such as name, symbol, etc. We mint (i.e., create) a specified amount of tokens and transfer them to the owner of the token.

Currently, we hardcode these values directly inside the constructor definition, but it’s also possible to retrieve them from the constructor arguments.

We can now start defining the functions that are not automatically created for us. Remember, all public variables have getter functions defined automatically by Solidity 0.8 and above.

Over 200k developers use LogRocket to create better digital experiences

Learn more →

getOwner()

getOwner() returns the address of the owner of the BEP-20 token. It simply returns the owner variable we initialized in the constructor .

transfer(address _to, uint256 _value)

transfer(address _to, uint256 _value) transfers a specified amount of tokens to an address. This function basically deducts an amount ( _value ) from whichever address called the function. The deducted amount is then added to the address specified in the argument ( _to ).

transferFrom(address _from, address _to, uint256 _value)

transferFrom(address _from, address _to, uint256 _value) transfers a specified amount of tokens from one address to another. This method differs from transfer in the sense that it allows an account to transfer tokens on behalf of another account.

To achieve this functionality, an allowance is approved by the recipient ( _to ) beforehand. All calls to this function then uses the preapproved allowance to make transfers.

An example use case of this method is a smart contract transferring tokens on your behalf and/or charging fees.

approve(address _spender, uint256 _value)

approve(address _spender, uint256 _value) allows an account ( _spender ) to withdraw from another account (the caller) multiple times, up to the specified amount ( _value ). This method is what makes transferFrom possible because an account is able to authorize another account to make transfers on its behalf.

mint(uint256 _amount)

mint(uint256 _amount) allows the token owner to create a specified amount ( _amount ) of new tokens and transfer them to themself. This increases the total supply of the token.

More great articles from LogRocket:

  • Don’t miss a moment with The Replay, a curated newsletter from LogRocket how LogRocket’s Galileo cuts through the noise to proactively resolve issues in your app
  • Use React’s useEffect to optimize your application’s performance
  • Switch between multiple versions of Node how to use the React children prop with TypeScript creating a custom mouse cursor with CSS
  • Advisory boards aren’t just for executives. Join LogRocket’s Content Advisory Board. You’ll help inform the type of content we create and get access to exclusive meetups, social accreditation, and swag.

burn(uint256 _amount)

burn(uint256 _amount) allows a token holder to burn (i.e., destroy) a specified amount of existing tokens from their own account. This operation decreases the total supply of the token.

Your source code should look exactly the same as the above.

Deploying the token contract using Remix

Now that we’re done coding the token, it’s time to deploy it. For this tutorial, we’ll deploy the token contract using Remix.

Before we get started, we need:

  • A browser with MetaMask installed so we can sign the transaction of deploying the token contract via Remix as well as interact with the token. Follow these instructions to setupMetaMaskwith the right Binance Smart Chain network
  • Some BNB to pay for the cost of deploying a new contract. If you’re deploying to the testnet, head over to the BSC testnet faucet and request some funds using the account you set up in the previous step. It might take a few seconds, but once you verify that you have some BNB via MetaMask, continue

Now that we have MetaMask configured and some BNB in our development account, we can go ahead and deploy the token contract to a public BSC network.

If you’ve been following this tutorial, then you already have Remix open. Otherwise, open Remix, create a new contract file, and paste in the contents of your token source code.

On the left sidebar, click on the Solidity compiler option (at the time of writing, it’s the second option), and click Compile Token.sol.

Click on the Deploy and run transactions option (third option).

Set the ENVIRONMENT to Injected Web3. A MetaMask prompt should pop up asking you to confirm the transaction. If it doesn’t, ensure you have MetaMask installed and configured on the right BSC network.

Click the Deploy button, confirm the transaction, and you should be able to see your contract under the Deployed Contracts section.

Copy the address of the deployed contract; you’ll need it in the next section. Simply click the Copy icon beside the deployed contract.

Verifying and publishing your token contract on BscScan

Once you have your token deployed on a public network, you may want to verify the source code on BscScan.

BscScan is a tool that allows you to view transactions occurring on the BSC network (both mainnet and testnet). When you verify the source code on BscScan, you lend extra legitimacy to the token because it allows everyone to see what’s going on under the hood of the token.

Thankfully, doing this verification is relatively easy, as long as you have access to the source code.

First, let’s view the deployed contract on BscScan (full GIF walkthrough below).

Navigate to the homepage. If you deployed to mainnet, visit BscScan Mainnet. If you deployed to testnet, visit BscScan testnet.

Paste in the address of the deployed contract you copied from the previous step into the search bar and hit enter.

You should see details of the token. Click on the Contract tab below the token details.

Click Verify and Publish and fill in the form as shown below.

Make sure the compiler version is exactly the same as in Remix and that the license field is set to the same as in the source code (in this case, GNU Public License 3.0). Then, click Continue.

You should see an input box to paste in the contract smart code. Copy the source code from the Remix editor, paste it in the box, and click Verify and Publish.

The token contract is now deployed and verified on BscScan, so it’s now possible to import the token in MetaMask and make transactions with it.

Importing the token into MetaMask

Now that the token contract is deployed on a public network, we can interact with it via MetaMask just like we would with any other token. However, there are a few steps to take before this is possible (full GIF walkthrough below).

First, open MetaMask and ensure that it is on the right network; it should be a Binance Smart Chain network.

Next, ensure that you’re using the same account that you deployed the token contract with. Also ensure that you’re on the Assets tab and then click Import tokens.

Paste in the deployed token contract address you copied earlier. MetaMask should read the token symbol and decimals automatically.

Click Add Custom Token and confirm the operation by clicking Import Tokens. That’s it!

You should now be able to perform actions such as sending tokens to another address. The Swap functionality may or may not be available, depending on the network you’ve deployed to.

Conclusion and next steps

If you followed this tutorial all the way to the end, you should have a good understanding of the BEP-20 proposal, how to use Remix for coding and deployment, how to verify a token’s source code on BscScan, and how to import any token into MetaMask using the token address.

You can build on this knowledge by:

  • Implementing any additional custom functionality DApp to consume the token
  • Creating a liquidity pool for the token

Deploying a BEP-20 token on the Binance Smart Chain is not as difficult as you may imagine. I hope this tutorial helps you get started!

Join organizations like Bitso and Coinsquare who use LogRocket to proactively monitor their Web3 apps

LogRocket Dashboard Free Trial Banner

Client-side issues that impact users’ ability to activate and transact in your apps can drastically affect your bottom line. If you’re interested in monitoring UX issues, automatically surfacing JavaScript errors, and tracking slow network requests and component load time, try LogRocket.https://logrocket.com/signup/

LogRocket is like a DVR for web and mobile apps, recording everything that happens in your web app or site. Instead of guessing why problems happen, you can aggregate and report on key frontend performance metrics, replay user sessions along with application state, log network requests, and automatically surface all errors.

# How to create BEP20 Token

BEP20 Token Generator is a distributed application that runs on the Binance Smart Chain (BSC) network, using specially-developed Smart Contracts to enable users to build their BEP20 Tokens.

Easily deploy Smart Contract for a Standard, Capped, Mintable, Burnable BEP20 Token.

Create a BEP20 Token in less than a minute.

No login. No setup. No coding required.

# Create Token

# Choose your token type

Choose between different token types and features.

Token Types

# Enter your details

Enter your preferred Token name and symbol. Choose your supply and Token type.

Token Details

# Confirm your transaction

Confirm your transaction using MetaMask.

Token Confirm

# Waiting for confirmation

Waiting for your transaction to be confirmed.

Token Waiting

# View your token

Your token is ready to use, view on BscScan or add to MetaMask.

Token Confirmed

# Verified source code

Your source code will be automatically verified on BscScan.

Token Source Code

# Features

# Detailed

Your Token will be fully compliant with the BEP20 definition and compatible with any BEP20 wallet all around the world. It will have a name, a symbol and a decimals amount.

# Burnable

Your Token can be burnt. It means that you can choose to reduce the circulating supply by destroying some of your tokens.

# Mintable

You will be able to generate tokens by minting them. Only token owner will be able to mint. You can also disable minting if you don’t want to generate tokens anymore.

# Supply Type

Your token supply will be 10.000. The entire token supply will be generated during deploy and sent to Token Owner wallet. You can’t increase or reduce supply later.

# Fixed Supply

The entire token supply will be generated during deploy and sent to Token Owner wallet. You can’t increase or reduce supply later.

# Capped Supply

You can define an initial supply to sent to Token Owner’s wallet. You can increase or reduce supply later by minting or burning tokens (if allowed). You won’t be able to generate more tokens than the defined supply cap.

# Unlimited Supply

You can define an initial supply to sent to Token Owner’s wallet. You can increase or reduce supply later by minting or burning tokens (if allowed). You will be able to generate unlimited tokens without an upper limit.

# Access Type

Your Token doesn’t need an access type because of there are not actions that needs privileges.

# Ownable

Your Token will have an Owner. The account you use to deploy your Token will be owner by default and will be able to mint new tokens or call the finish minting function. You can transfer token ownership to addresses or Smart Contract.

# Role Based

Your Token will have Roles. Accounts with "MINTER" role will be able to mint new tokens. Accounts with "ADMIN" role will be able to add or remove roles to minters or other admins. The account you use to deploy your Token will be ADMIN and MINTER by default. In addition your Token will have the Ownable behaviour too.

# Operable Token (ERC1363)

The Operable Token is a BEP20 compatible Token that can make a callback on the receiver contract to notify token transfers or token approvals.

# Token Recover

There are lots of tokens lost forever into Smart Contracts. It allows the contract owner to recover any BEP20 token sent into the contract for error.

# View App

# Disclaimer

BEP20 Token Generator and its author are free of any liability regarding Tokens built using this App, and the use that is made of them. Tokens built on BEP20 Token Generator, their projects, their teams, their use of Token (as well as anything related to Token) are in no way connected to BEP20 Token Generator or its author.

BEP20 Token Generator’s code is provided under MIT License. Anyone can use it as per their needs. The App’s purpose is to make people able to tokenize their ideas without coding or paying large amounts for it. Source code is public and well tested and continuously updated to reduce risk of bugs and introduce language optimizations. Anyway the purchase of tokens involves a high degree of risk. Before acquiring tokens, it is recommended to carefully weighs all the information and risks detailed in Token owner’s Conditions.

# Contacts

If you have a technical or support question, a privacy concern, complaint, or any type of question, please open an issue here

How to Create Your Own BEP20 Token on Binance Smart Chain Today

.

Launching a BEP20 token on Binance Smart Chain is easier than you may think.

Arguably, one of the best ways to learn more about the inner workings of cryptocurrency is by launching your own digital token. And the good news is: anyone can create their own BEP20 token on Binance Smart Chain.

Now let’s jump in and walk you through how that works.

Binance Smart Chain

Before you venture off to create your own cryptocurrency, you need to pick a blockchain platform that is appropriate for your use cases.

If you’re looking for a platform with low fees, fast transaction times, and smart contract compatibility, then look no further than Binance Smart Chain (BSC).

As a chain that runs parallel to Binance Chain, Binance Smart Chain is specifically designed to cater to smart contracts and the creation of decentralized applications (DApps).

Smart Contracts

Simply put, smart contracts are code that runs on a blockchain designed for specific apps or services.

For example, if you want to make a decentralized voting application, a smart contract would be the voting logic that needs to run on the blockchain.

The biggest smart contract blockchain thus far, Ethereum, is also cross-compatible with Binance Smart Chain. However, unlike Smart Chain, Ethereum has substantially higher transaction fees.

The BEP20 Token Standard

Creating a BSC token is surprisingly easy. These tokens conform to a standard called BEP20, which is similar to the Ethereum standard ERC20.

The token standard ensures basic functionality for the token, such as transferring, returning a balance, viewing token ownership, etc.

You can view the API for BEP20 here. Keep in mind that BSC tokens can be swapped for “regular” Binance Chain tokens that conform to their own standard, BEP2.

Also, any transaction that occurs with these tokens on-chain will require a fee paid in BNB. This fee is compensation for validators for securing the network.

Let’s explore how to create these tokens below.

Creating a BEP20 Token Using Token Create

Fill out all the details for your token

Select ‘Create Token’ and approve the transaction

The link for step one can be viewed in the Trust Wallet Dapp Browser by typing in cointool.app/bnb/BSCCreateToken in the address bar. Make sure you are set to the Smart Chain network on the top right.

For step two, you’ll need to give your token a name and a symbol. You’ll also need to specify the initial supply quantity of your token, and the number of decimal places each token can be divided into.

Check Mark Settings In Token Create

There are also further checkmark settings outlined below.

Can Burn:This check specifies whether your tokens can be burned to decrease the supply.

Can Mint: Minting specifies the opposite, whether more tokens can be created to increase the initial supply.

Can Pause: This check specifies whether your token and all associated operations can be halted and resumed whenever needed. This pausing operation can be used in case of a software vulnerability or a malicious attack. Be aware that enabling pausing gives authority to whoever is allowed to pause or unpause, such as the creator of the token, and this central authority may not suit certain use cases.

Blacklist:Accounts can also be blacklisted if they act malicius. Depending on the use case, it may be better for some tokens to have this feature turned off. Similar to the pausing feature, enabling blacklists causes central authority, which may not suit certain use cases.

Create Token

Once you select ‘Create Token’, the next interface will show you the fee for the creation. This fee will be in BNB.

The token will be created once you approve this transaction fee.

Adding A Custom BEP20 Token To Trust Wallet

Now that you’ve created your token, how can you get it to display inside your Trust Wallet? Simple. Follow the steps below.

Inside the wallet, select the icon of the two sliders in the top right corner.

Scroll all the way to the bottom of the token list and select ‘Add Custom Token’.

Set the network to ‘Smart Chain’.

Enter your smart contract address right below the network setting.

Enter the Name, Symbol, and the number of Decimals that your token was divided into.

Now, if you go back to your wallet, your token will be there waiting on display!

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *