Filecoin Docs
BasicsStorage providersNodesNetworksSmart contractsReference
  • Welcome to Filecoin Docs
  • Basics
    • What is Filecoin
      • Crypto-economics
      • Blockchain
      • Storage model
      • Storage market
      • Retrieval market
      • Programming on Filecoin
      • Networks
    • The blockchain
      • Actors
      • Addresses
      • Blocks and tipsets
      • Consensus
      • Drand
      • Proofs
    • Assets
      • The FIL token
      • Wallets
      • Metamask setup
      • Get FIL
      • Transfer FIL
    • Interplanetary consensus
    • How storage works
      • Filecoin plus
      • Storage onramps
      • Filecoin and IPFS
    • How retrieval works
      • Basic retrieval
      • Serving retrievals
      • Saturn
    • Project and community
      • Forums and FIPs
      • Filecoin compared to
      • Filecoin FAQs
      • Related projects
      • Social media
      • The Filecoin project
      • Ways to contribute
  • Storage providers
    • Basics
      • Quickstart guide
    • Filecoin economics
      • Storage proving
      • FIL collateral
      • Block rewards
      • Slashing
      • Committed capacity
    • Filecoin deals
      • Storage deals
      • Verified deals
      • Filecoin programs and tools
      • Snap deals
      • Charging for data
      • Auxiliary services
      • Return-on-investment
    • Architecture
      • Software components
      • Storage provider automation
      • Sealing pipeline
      • Sealing rate
      • Sealing-as-a-service
      • Network indexer
    • Infrastructure
      • Storage
      • Network
      • Backup and disaster recovery
      • Reference architectures
    • Skills
      • Linux
      • Network
      • Security
      • Storage
      • Sales
      • Industry
    • PDP
      • Prerequisites
      • Install & Run Lotus
      • Install & Run YugabyteDB
      • Install & Run Curio
      • Enable PDP
      • Use PDP
  • Nodes
    • Implementations
      • Lotus
      • Venus
    • Full-nodes
      • Pre-requisites
      • Basic setup
      • Node providers
    • Lite-nodes
      • Spin up a lite-node
  • Smart contracts
    • Fundamentals
      • The Filecoin Virtual Machine
      • Filecoin EVM runtime
      • ERC-20 quickstart
      • Roadmap
      • Support
      • FAQs
    • Filecoin EVM-runtime
      • Actor types
      • Address types
      • FILForwarder
      • Difference with Ethereum
      • How gas works
      • Precompiles
    • Programmatic storage
      • Aggregated deal-making
      • Direct deal-making
      • Cross-Chain Data Bridge(CCDB)
      • Data replication, renewal and repair (RaaS)
      • RaaS interfaces
    • Developing contracts
      • Get test tokens
      • Remix
      • Hardhat
      • Foundry
      • Solidity libraries
      • Call built-in actors
      • Filecoin.sol
      • Direct deal-making with Client contract
      • Using RaaS
      • Verify a contract
      • Best practices
    • Advanced
      • Wrapped FIL
      • Oracles
      • Multicall
      • Multisig
      • FEVM Indexers
      • Cross-chain bridges
      • Aggregated deal-making
      • Contract automation
      • Relay
  • Networks
    • Mainnet
      • Explorers
      • RPCs
      • Network performance
    • Calibration
      • Explorers
      • RPCs
    • Local testnet
      • Get test tokens
    • Deprecated networks
  • Reference
    • General
      • Glossary
      • Specifications
      • Tools
    • Exchanges
      • Exchange integration
    • Built-in actors
      • Protocol API
      • Filecoin.sol
    • JSON-RPC
      • Auth
      • Chain
      • Client
      • Create
      • Eth
      • Gas
      • I
      • Log
      • Market
      • Miner
      • Mpool
      • Msig
      • Net
      • Node
      • Paych
      • Raft
      • Start
      • State
      • Sync
      • Wallet
      • Web3
  • Builder Cookbook
    • Overview
    • Table of Contents
    • Data Storage
      • Store Data
      • Retrieve Data
      • Privacy & Access Control
    • dApps
      • Chain-Data Query
      • Oracles
      • Cross-Chain Bridges
      • Decentralized Database
Powered by GitBook
LogoLogo

Basics

  • Overview
  • Crypto-economics
  • Storage model
  • Reference

Developers

  • The FVM
  • EVM-runtime
  • Quickstart
  • Transfer FIL

Contact

  • GitHub
  • Slack
  • Twitter
On this page
  • Accounts and assets
  • Create a wallet
  • Switch networks
  • Get some funds
  • Contract creation
  • Create a workspace
  • Customize the contract
  • Compile
  • Deploy
  • Use your contract
  • Mint your tokens
  • Add to MetaMask
  • Share your tokens

Was this helpful?

Edit on GitHub
Export as PDF
  1. Smart contracts
  2. Fundamentals

ERC-20 quickstart

In this quickstart tutorial we’ll walk through how to deploy your first smart-contract to the Filecoin network.

PreviousFilecoin EVM runtimeNextRoadmap

Last updated 6 months ago

Was this helpful?

We’re going to install a browser-based wallet called MetaMask, create a new wallet address, supply some test currency to that wallet, and then use a browser-based development environment called Remix to deploy a smart contract to the Filecoin network. We’re going to be creating an ERC-20 token in this quickstart. The ERC-20 contract is used a lot in representing a massive array of tokens across multiple blockchains, primarily the Ethereum blockchain.

If you’re an Ethereum developer, check out the .

Accounts and assets

We’re going to be using MetaMask, a cryptocurrency wallet that lives in your browser making it very easy for users to interact with web3-based sites!

Create a wallet

Before we can interact with the Filecoin network, we need funds. But before we can get any funds, we need somewhere to put them!

  1. Open your browser and visit the .

  2. Install the wallet by clicking the Download for button. MetaMask is available for Brave, Chrome, Edge, Firefox, and Opera.

  3. Once you have installed MetaMask, it will open a Get started window.

  4. Click Create a new wallet.

  5. Enter a password to secure your MetaMask wallet. You will need to enter this password every time you use the wallet.

  6. Follow the prompts until you get to the Secret Recovery Phrase window. Read the information about what this recovery phrase is on this page.

  7. Eventually you should get to the Wallet creation success page!

  8. Once you’ve done that, you should have your account set up!

Switch networks

  1. Enable the Testnets toggle and enter Filecoin into the search bar.

  2. Scroll down to find the Filecoin – Calibration testnet.

  3. In MetaMask click Next.

  4. Click Connect.

  5. Click Approve when prompted to Allow this site to add a network.

  6. Click Switch network when prompted by MetaMask.

  7. Open MetaMask from the browser extensions tab:

  8. You should see the Filecoin Calibration testnet listed at the top.

Nice! Now we’ve got the Filecoin Calibration testnet set up within MetaMask. You’ll notice that our MetaMask window shows 0 TFIL. Test-filecoin (TFIL) is FIL that has no value in the real world, and developers use it for testing. We’ll grab some TFIL next.

Get some funds

  1. In your browser, open MetaMask and copy your address to your clipboard:

  2. Paste your address into the address field, and click Send Funds.

That’s all there is to it! Getting tFil is easy!

Contract creation

Create a workspace

In Remix, workspaces are where you can create a contract, or group of contracts, for each project. Let’s create a new workspace to create our new ERC-20 token.

  1. Open the dropdown menu and click create a new workspace.

  2. In the Choose a template dropdown, select ERC20.

  3. Under Customize template > Features, check the Mintable box.

  4. Enter a fun name for your token in the Workspace name field. Something like CorgiCoin works fine.

  5. Click OK to create your new workspace.

Customize the contract

The contract template we’re using is pretty simple. We just need to modify a couple of variables.

  1. Click the compiler icon to open the compiler panel. Update the compiler version by selecting 0.8.20 from the compiler dropdown.

  2. Under the contract directory, click MyToken.sol.

  3. In the editor panel, replace MyToken with whatever you’d like to name your token. In this example, we’ll use CorgiCoin.

  4. On the same line, replace the second string with whatever you want the symbol of your token to be. In this example, we’ll use CRG.

That’s all we need to change within this contract. You can see on line 4 that this contract is importing another contract from @openzeppelin for us, meaning that we can keep our custom token contract simple.

Compile

  1. Click the green play symbol at the top of the workspace to compile your contract. You can also press CMD + s on MacOS or CTRL + s on Linux and Windows.

  2. Remix automatically fetches the three import contracts from the top of our .sol contract. You can see these imported contracts under the .deps directory. You can browse the contracts there, but Remix will not save any changes you make.

Deploy

Now that we’ve successfully compiled our contract, we need to deploy it somewhere! This is where our previous MetaMask setup comes into play.

  1. Click the Deploy tab from the left.

  2. Under the Environment dropdown, select Injected Provider - MetaMask.

  3. MetaMask will open a new window confirming that you want to connect your account to Remix.

  4. Click Next:

  5. Click Connect to connect your tFIL account to Remix.

  6. Back in Remix, under the Account field, you’ll see that it says something like 0x11F... (5 ether). This value is 5 tFIL, but Remix doesn’t support the Filecoin network so doesn’t understand what tFIL is. This isn’t a problem, it’s just a little quirk of using Remix.

  7. Under the Contract dropdown, ensure the contract you created is selected.

  8. Gather your MetaMask account address and populate the deploy field in Remix.

  9. Click Deploy.

  10. MetaMask will open a window and as you to confirm the transaction. Scroll down and click Confirm to have MetaMask deploy the contract.

  11. Back in Remix, a message at the bottom of the screen shows that the creation of your token is pending.

  12. Wait around 90 seconds for the deployment to complete.

On the Filecoin network, a new set of blocks, also called a tipset, is created every thirty seconds. When deploying a contract, the transaction needs to be received by the network, and then the network needs to confirm the contract. This process takes around one to two tipsets to process – or around 60 to 90 seconds.

Use your contract

Now that we’ve compiled and deployed the contract, it’s time to actually interact with it!

Mint your tokens

Let’s call a method within the deployed contract to mint some tokens.

  1. Back in Remix, open the Deployed Contracts dropdown, within the Deploy sidebar tab.

  2. Expand the mint method. You must fill in two fields here: to and amount.

  3. The to field specifies where address you want these initial tokens sent to. Open MetaMask, copy your address, and paste it into this field.

  4. This field expects an attoFil value. 1 FIL is equal to 1,000,000,000,000,000,000 attoFil. So if you wanted to mint 100 FIL, you would enter 100 followed by 18 zeros: 100000000000000000000.

  5. Click Transact.

  6. MetaMask will open a window and ask you to confirm the transaction:

Again, you must wait for the network to process the transaction, which should take about 90 seconds. You can move on to the next section while you’re waiting.

Add to MetaMask

Currently, MetaMask has no idea what our token is or what it even does. We can fix this by explicitly telling MetaMask the address of our contract.

  1. Go back to Remix and open the Deploy sidebar tab.

  2. Under Deployed Contracts, you should see your contract address at the top. Click the copy icon to copy the address to your clipboard:

  3. Open MetaMask, select Assets, and click Import your tokens:

  4. In the Token contract address field, paste the contract address you just copied from Remix and then click Add custom token. MetaMask should autofill the rest of the information based on what it can find from the Filecoin network.

  5. Click Import token:

  6. You should now be able to see that you have 100 of your tokens within your MetaMask wallet!

Share your tokens

You may notice that we are currently connected to the Ethereum Mainnet. We need to point MetaMask to the Filecoin network, specifically the . We’ll use a website called to give MetaMask the information it needs quickly.

Go to .

Go to and click Send Funds.

The faucet will show a transaction ID. You can copy this ID into a Calibration testnet to view your transaction. After a couple of minutes, you should see some tFIL transferred to your address.

The development environment we’re going to be using is called Remix, viewable at . Remix is an incredibly sophisticated tool, and there’s a lot you can play around with! In this tutorial however, we’re going to stick to the very basics. If you want to learn more, check out .

Open .

Having a bunch of tokens in your personal MetaMask is nice, but why not send some tokens to a friend? Your friend needs to create a wallet in MetaMask as we did in the and sections. They will also need to import your contract deployment address like you did in the section. Remember, you need to pay gas for every transaction that you make! If your friend tries to send some of your tokens to someone else but can’t, it might be because they don’t have any tFil.

Calibration testnet
chainlist.org
chainlist.org
faucet.calibration.chainsafe-fil.io
block explorer
remix.ethereum.org
the Remix documentation
remix.ethereum.org
Was this page helpful?
Add your tokens to MetaMask
Create a wallet
Switch networks
FEVM Hardhat kit
MetaMask website
Get started with MetaMask.
Create a password for your MetaMask wallet.
Wallet creation successful!
Default MetaMask page.
Search for Filecoin testnets in Chainlist.
Click next in MetaMask.
Open MetaMask from the browser extensions tab.
Copy your address to your clipboard.
Create a new workspace.
Set workspace details.
Update the compiler version
Open the MyToken contract.
Change token name.
Change token ticket.
Compile the contract.
Compile and get the dependencies
Select the deploy tab.
Select MetaMask within Remix.
Click next in MetaMask.
Click Connect in MetaMask.
Remix and MetaMask linked.
Select contract in Remix.
Copy the address in MetaMask
Populate the deploy address
Click Deploy in Remix.
Deployment confirmation in Remix.
Deployment complete.
Deploy the contracts.
Open the mint method.
Enter your address.
Click transact.
Confirm message in MetaMask.
Copy your contract address.
Import your address details.
Complete your asset details.
MetaMask showing a new token.