Filecoin.sol
External Solidity libraries can help developers create their applications quicker by offloading some of the work to already existing smart contracts.
The Filecoin Solidity library allows developers to:
Interact with Filecoin built-in actors.
Simplify the interaction with the Filecoin storage market, miner actors, the verified registry for Filecoin Plus automation, and more.
Use Filecoin-specific data types such as
FilAddress,FilActorId,Cid, storage deals, and more.OpenZeppelin-like utilities specific to Filecoin.
CBOR serialization and deserialization for parameters and return data.
In order to access exported Filecoin built-in actor methods in your smart contract, you will need to import Filecoin.sol in your Solidity project. As they are embeddable libraries, they don’t need to be present on-chain. You can just import the library you desire and call its methods.
Once the library is installed in your project, you can write Solidity code to call APIs from different built-in actors using Filecoin-specific data types or data conversions from the utility library.
Add to your contract
Run the following command in your Solidity project, which is created using any smart contract development framework such as Hardhat or Foundry.
npm install filecoin-solidity-apiWorks on
Filecoin.sol calls Filecoin built-in actors from contracts deployed to Filecoin EVM networks. Use it on Filecoin mainnet or Calibration testnet with the current FVM actors and the Filecoin Solidity API package shown above. For local development, use a Filecoin EVM-compatible local network that exposes the same built-in actor precompiles.
Usage
Once installed, you can call built-in actors in the library after importing them into your smart contract.
You can find the list of supported built-in actors and methods in the Filecoin.sol documentation. You can access certain Filecoin-related features through these actors:
AccountAPI.sol: validates signatures from an address.MinerAPI.sol: manages storage provider operation.MarketAPI.sol: manages storage deals on Filecoin.PowerAPI.sol: manages storage power for each storage provider and the whole network.DataCapAPI.solandVerifRegAPI.sol: manages DataCap and verified clients for Filecoin Plus.
Unlike OpenZeppelin contracts, you do not need to inherit contracts to use their features. With Filecoin.sol you just need to call the methods from those solidity contracts:
Filecoin.sol also offers several utility libraries to help developers convert data types for different variables, including FIL addresses, big integers, actor IDs, and CBOR. Import only the utilities your contract uses. For example:
Example
We can write a simple Solidity smart contract to query basic information for a Filecoin storage deal:
Next steps
Check out these links to learn more about the Filecoin.sol library.
Last updated