
Language diversity is just as crucial as client diversity, it can help making a smart contract chain more secure and resilient to bugs at compiler level. Also it can help sparking fresh ideas born from a brand-new codebase. Fe is a new EVM language, like Solidity and Vyper. However, Fe brings new opinions in term of readability, decidability and gas estimations.
In this guide we'll launch an ERC20 using Fe. Just keep in mind that whilst Fe is ready to be used on production, the dev tooling still needs to do a lot of catch-up compared to the other EVM languages. This guide is for both the early adopters and the curious.
Before we start
For this tutorial you will needMetamask or other wallet of your choice, with Scroll Sepolia funds that you can get from aSepolia faucet and then bridge them to L2 using theScroll Sepolia bridge. Alternatively, you can use aScroll Sepolia Faucet to get funds directly on L2.
On this guide we'll deploy on Scroll Sepolia, I'll explain the exact changes that are needed to deploy on any other EVM chain.
1. Installation
On Linux:
wget https://github.com/ethereum/fe/releases/download/v0.26.0/fe_amd64mvfe_amd64 fechmod +x fe
On Mac:
wget https://github.com/ethereum/fe/releases/download/v0.26.0/fe_macmvfe_mac fechmod +x fe
You will also need to install foundry in either Linux or Mac (needed for contract deployment)
curl-L https://foundry.paradigm.xyz | bash# now, reload your env vars, just close and reopen your terminalfoundryup
For more information check the officialFe andfoundry installation guide.
2. Create an ERC20 contract
Create the following file namederc20_token.fe
:
erc20_token.fe
structApproval{#indexedpubowner:address#indexedpubspender:addresspubvalue:u256}structTransfer{#indexedpubfrom:address#indexedpubto:addresspubvalue:u256}contractERC20{_balances:Map<address,u256>_allowances:Map<address,Map<address,u256>>_total_supply:u256_name:String<100>_symbol:String<100>_decimals:u8pubfn__init__(mutself,mutctx:Context){self._name="My Fe Token"self._symbol="MFeT"self._decimals=u8(18)self._mint(ctx,account:ctx.msg_sender(),value:1000_000_000_000_000_000_000_000)}pubfnname(self)->String<100>{returnself._name.to_mem()}pubfnsymbol(self)->String<100>{returnself._symbol.to_mem()}pubfndecimals(self)->u8{returnself._decimals}pubfntotalSupply(self)->u256{returnself._total_supply}pubfnbalanceOf(self,_account:address)->u256{returnself._balances[account]}pubfntransfer(mutself,mutctx:Context,recipient:address,value:u256)->bool{self._transfer(ctx,sender:ctx.msg_sender(),recipient,value)returntrue}pubfnallowance(self,owner:address,spender:address)->u256{returnself._allowances[owner][spender]}pubfnapprove(mutself,mutctx:Context,spender:address,value:u256)->bool{self._approve(ctx,owner:ctx.msg_sender(),spender,value)returntrue}pubfntransferFrom(mutself,mutctx:Context,sender:address,recipient:address,value:u256)->bool{assertself._allowances[sender][ctx.msg_sender()]>=valueself._transfer(ctx,sender,recipient,value)self._approve(ctx,owner:sender,spender:ctx.msg_sender(),value:self._allowances[sender][ctx.msg_sender()]-value)returntrue}pubfnincreaseAllowance(mutself,mutctx:Context,spender:address,addedValue:u256)->bool{self._approve(ctx,owner:ctx.msg_sender(),spender,value:self._allowances[ctx.msg_sender()][spender]+addedValue)returntrue}pubfndecreaseAllowance(mutself,mutctx:Context,spender:address,subtractedValue:u256)->bool{self._approve(ctx,owner:ctx.msg_sender(),spender,value:self._allowances[ctx.msg_sender()][spender]-subtractedValue)returntrue}fn_transfer(mutself,mutctx:Context,sender:address,recipient:address,value:u256){assertsender!=0assertrecipient!=0_before_token_transfer(from:sender,to:recipient,value)self._balances[sender]=self._balances[sender]-valueself._balances[recipient]=self._balances[recipient]+valuectx.emit(Transfer(from:sender,to:recipient,value))}fn_mint(mutself,mutctx:Context,account:address,value:u256){assertaccount!=address(0)_before_token_transfer(from:address(0),to:account,value)self._total_supply=self._total_supply+valueself._balances[account]=self._balances[account]+valuectx.emit(Transfer(from:address(0),to:account,value))}fn_burn(mutself,mutctx:Context,account:address,value:u256){assertaccount!=address(0)_before_token_transfer(from:account,to:address(0),value)self._balances[account]=self._balances[account]-valueself._total_supply=self._total_supply-valuectx.emit(Transfer(from:account,to:address(0),value))}fn_approve(mutself,mutctx:Context,owner:address,spender:address,value:u256){assertowner!=address(0)assertspender!=address(0)self._allowances[owner][spender]=valuectx.emit(Approval(owner,spender,value))}fn_setup_decimals(mutself,_decimals_:u8){self._decimals=decimals_}fn_before_token_transfer(from:address,to:address,_value:u256){}}
For more demos, checkthis repo.
3. Compile the contract
Generate the ABI and bytecode by running the following:
./fe build erc20_token.fe
For more information check theFe docs.
4. Deployment
You can deploy now on Scroll Sepolia by putting your private key onYOURPRIVATEKEY
and running the following command. Just make sure it has Scroll Sepolia Testnet funds.
If you are deploying on a chain other than Scroll Sepolia, change the rpc url fromhttps://sepolia-rpc.scroll.io/
to an RPC url from your chain of choice.
cast send--legacy--rpc-url https://sepolia-rpc.scroll.io/--private-key YOURPRIVATEKEY--create$(catoutput/ERC20/ERC20.bin)
The token should now be on your account fully ERC20 compatible. The transaction and token address should be displayed on the console, or you can find it onScroll Sepolia Etherscan or on the scan of the chain you deployed to.
Fe recommends using Anvil from foundry to deploy and interact with contracts, for more information check thefoundry docs.
Conclusion
It is still too early to decide which one I will use more in the future, as Fe is in a very early stage and is likely to undergo changes. However, I really like the idea of a new language with fresh ideas learned from Solidity's lessons. I doubt Solidity will cease to be the dominant language for many years, but I hope that new error analysis tools and gas calculators will lead to significant adoption of Fe and enable it to build a community. Personally, I will keep an eye on new developments and will be testing it in future projects!
Which one do like better? Do you still prefer Solidity or do you want to give Fe a try?
Thanks for watching this guide!
Follow Filosofía Código on dev.to and inYoutube for everything related to Blockchain development.
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse