Call built-in actors
Filecoin built-in actors can be invoked in a smart contract using either the Protocol API or the Zondax filecoin.solifity library. This page provides instructions on how to use each method.
For conceptual information on built-in actors, including their purposes, how they work and available types, see the conceptual guide
Built-in actors can be invoked using the Protocol JSON-RPC API or the Zondax filecoin.sol API.
APIs compared
The Protocol JSON-RPC API:
Is maintained by Protocol Labs (PL).
Uses JSON-RPC, a standardized way to encode remote procedure calls in JSON that can be transported using HTTP or WebSockets.
Provides a language agnostic interface for Filecoin functionality.
Allows applications to access Filecoin functionality using HTTP or WebSockets calls to a Filecoin node, like the Lotus daemon.
Requires authentication for some API calls.
Serves as the foundation for language-specific libraries (some of which are maintained by organizations other than PL) such as filecoin.js.
The Zondax filecoin.sol API:
Protocol API
Smart contracts can directly access built-in actors and methods using the Protocol API. Links to the reference guides for each of the available actor methods is listed below:
Filecoin.sol
Smart contracts can access built-in actor methods with the filecoin.sol
library, a set of Solidity libraries that allow Solidity smart contracts to seamlessly call methods of Filecoin built-in actors. The filecoin.sol
library supports cross-platform calls to real Filecoin built-in actors. This section contains information on the actors and methods available from filecoin.sol
, along with installation instructions and working examples of smart contracts that call built-in actor methods.
To invoke built-in actor methods using filecoin.sol
, follow these steps:
Review the available actors and methods.
Available actors and methods
The majority of the Account, DataCap, Storage Market, Miner, Storage Owner and Verified Registry actor methods are supported and are listed below. Cron, Payment Channel, Reward and System actor methods are currently not supported.
Account
DataCap
Miner
Multisig
Storage market
Storage power
Verified registry
Import filecoin.sol
The filecoin.sol
library is embeddable into your smart contract, which means it does not need be present on chain first. Instead, you can just import the library and call the available methods. The filecoin.sol
library can be added via npm
or manually imported into your contract. The npm
-based import is simpler, and is recommended.
Import filecoin.sol with npm
Install yarn if you don’t have it installed.
Install
filecoin.sol
:
Until mid-2023, Zondax was the legacy maintainer of Filecoin.sol. Protocol Labs took over the project, and are in the process of moving NPM packages over to the protocollabs
NPM account.
Import filecoin.sol manually
Navigate to your smart contract project folder
<my-project>
:
Create a folder named
libs
:
Move into the
libs
directory:
Copy the Zondax contracts with the methods you wish to call from the contracts folder into
libs
.
Call a built-in actor
Once you’ve either imported particular contracts manually or simply installed filecoin.sol
using npm, create a callable method to access the built-in actor methods the way you normally would in a Solidity smart contract. Working examples of smart contracts that call built-in actor methods are available in the reference guide.
Last updated