Solidity libraries
With Filecoin Virtual Machine (FVM), Solidity developers can use existing libraries listed on this page in their FVM smart contracts.
OpenZeppelin
OpenZeppelin provides a library of battle-tested smart contract templates, including widely used implementations of ERC token standards. For a guided example that implements an ERC20 token on the Filecoin network, see Example using an ERC20 contract.
Benefits
OpenZeppelin offers the following to smart contract developers:
Implementations of standards like ERC20, ERC721, and ERC1155.
Flexible access control schemes like
Ownable
,AccessControl
, andonlyRole
.Useful and secure utilities for signature verification,
SafeMath
, etc..
Token standards, such as ERC20, are the most widely used smart contract libraries from OpenZeppelin. These contracts, listed below, implement both fungible and non-fungible tokens:
ERC20 is the simplest and most widespread token standard for fungible assets.
ERC721 is the standard solution for non-fungible tokens and is often used for collectibles and games.
ERC777 provides a richer standard for fungible tokens, supporting new use cases and backwards compatibility with ERC20.
ERC1155 is a new standard for multi-tokens, where a single contract represents multiple fungible and non-fungible tokens, and operations are batched for increased gas efficiency.
Using OpenZeppelin with FVM
The general procedure for using OpenZeppelin with FVM is as follows:
Install OpenZeppelin. For example, using
npm
:
Import the specific library you want to use.
In your smart contract, inherit the library.
Thanks to the FVM, your contract can be integrated and deployed on the Filecoin network with OpenZeppelin inheritance. For a guided example that implements an ERC20 token on the Filecoin network, see Example using an ERC20 contract.
Example using an ERC-20 contract
In the following tutorial, you’ll write and deploy a smart contract that implements the ERC-20 on the Calibration testnet using Remix and MetaMask:
Prerequisites
Let’s take an ERC20 contract as an example to write and deploy it on the Calibration testnet using Remix & MetaMask:
Remix.
MetaMask.
Test tokens (tFIL) from the faucet.
Procedure
In this procedure, you will create, deploy, mint and send an ERC20 token on Calibration using Remix and MetaMask.
Navigate to remix.ethereum.org.
Next to Workspaces, click the + icon to create a new workspace.
In the Choose a template dropdown, select ERC20 along with the Mintable checkbox
Click OK.
In the contract directory, open MyToken.sol.
Set the token
<name>
and<symbol>
:
Next, compile and deploy the contract on Filecoin.
At the top of the workspace, click the green play symbol to compile the contract.
Once the contract compiles, open the Deploy tab on the left.
Under the Environment dropdown, select Injected Provider - MetaMask.
In the MetaMask popup window, select Confirmed connection.
Click Deploy, and confirm the transaction on MetaMask. Your token contract will be deployed to the Calibration testnet once the network confirms the transaction.
In Remix, open the Deployed Contracts dropdown.
In the
mint
method, set:to
to your wallet address.amount
to1000000000000000000
(1FIL
).
Click Transact.
In MetaMask, confirm the transaction.
Once the network processes the transaction, the token is minted and sent to your network address. Congratulations, you’ve completed the tutorial!
Additional resources
Learn more about OpenZeppelin with the following resources:
DappSys
The DappSys library provides safe, simple, and flexible Ethereum contract building blocks for common Ethereum and Solidity use cases.
0x protocol
The 0x protocol library provides a set of secure smart contracts that facilitate peer-to-peer exchange of Ethereum-based assets.
Last updated