bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 52쪽 중 15쪽
ector | ✖️ |
| PreCommitSectorBatch | ✖️ |
| PreCommitSectorBatch2 | ✖️ |
| ProveCommitAggregate | ✖️ |
| ProveCommitSector | ✖️ |
| ProveReplicaUpdates | ✖️ |
| ProveReplicaUpdates2 | ✖️ |
| Read fee debt | ✖️ |
| Read initial pledge total | ✖️ |
| Read peer ID, multiaddr | ✔️ |
| Read pre-commit deposit | ✖️ |
| RepayDebt | ✔️ |
| ReportConsensusFault | ✖️ |
| SubmitWindowedPoSt | ✖️ |
| TerminateSectors | ✖️ |
| WithdrawBalance | ✔️ |
#### **Multisig**
| Method | Supported? |
| --------------------------- | ---------- |
| AddSigner | ✔️ |
| Approve | ✔️ |
| Cancel | ✔️ |
| ChangeNumApprovalsThreshold | ✖️ |
| Constructor | ✖️ |
| List signers and threshold | ✖️ |
| LockBalance | ✔️ |
| Propose | ✔️ |
| RemoveSigner | ✔️ |
| SwapSigner | ✔️ |
| UniversalReceiverHook | ✔️ |
#### **Storage market**
| Method | Supported? |
| ------------------------- | ---------- |
| ActivateDeals | ✖️ |
| AddBalance | ✔️ |
| ComputeDataCommitment | ✖️ |
| Constructor | ✖️ |
| CronTick | ✖️ |
| GetBalance | ✔️ |
| GetDealActivation | ✔️ |
| GetDealClient | ✔️ |
| GetDealClientCollateral | ✔️ |
| GetDealDataCommitment | ✔️ |
| GetDealEpochPrice | ✔️ |
| GetDealLabel | ✔️ |
| GetDealProvider | ✔️ |
| GetDealProviderCollateral | ✔️ |
| GetDealTerm | ✔️ |
| GetDealVerified | ✔️ |
| OnMinerSectorsTerminate | ✖️ |
| PublishStorageDeals | ✔️ |
| VerifyDealsForActivation | ✖️ |
| WithdrawBalance | ✔️ |
#### **Storage power**
| Method | Supported? |
| ---------------------------------------- | ---------- |
| Compute pledge collateral for new sector | ✖️ |
| Constructor | ✖️ |
| CreateMiner | ✔️ |
| CurrentTotalPower | ✖️ |
| EnrollCronEvent | ✖️ |
| Get miner count, consensus count | ✔️ |
| Get miner’s QA power | ✖️ |
| Get network bytes committed? | ✖️ |
| Get network epoch pledge collateral | ✖️ |
| Get network epoch QA power | ✖️ |
| Get network total pledge collateral? | ✖️ |
| MinerRawPower | ✔️ |
| NetworkRawPower | ✔️ |
| OnEpochTickEnd | ✖️ |
| SubmitPoRepForBulkVerify | ✖️ |
| UpdateClaimedPower | ✖️ |
| UpdatePledgeTotal | ✖️ |
#### **Verified registry**
| Method | Supported? |
| --------------------------- | ---------- |
| AddVerifiedClient | ✔️ |
| AddVerifier | ✖️ |
| ClaimAllocations | ✖️ |
| Constructor | ✖️ |
| ExtendClaimTerms | ✔️ |
| GetClaims | ✔️ |
| List claims | ✖️ |
| List/check verifiers | ✖️ |
| List/get allocations | ✖️ |
| RemoveExpiredAllocations | ✔️ |
| RemoveExpiredClaims | ✔️ |
| RemoveVerifiedClientDataCap | ✖️ |
| RemoveVerifier | ✖️ |
| UniversalReceiverHook | ✔️ |
### 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`](#import-filecoinsol-with-npm) or [manually imported](#import-filecoinsol-manually) into your contract. The `npm`-based import is simpler, and is recommended.
#### **Import filecoin.sol with npm**
1. Install the Filecoin Solidity API package:
```shell
npm install filecoin-solidity-api
```
{% hint style="info" %}
Use the maintained `filecoin-solidity-api` package and import paths. Older examples may use legacy Zondax package names or repository paths; do not copy those into new projects.
{% endhint %}
#### **Import filecoin.sol manually**
1. Navigate to your smart contract project folder `<my-project>`:
```shell
cd my-project
```
2. Create a folder named `libs`:
```shell
mkdir libs
```
3. Move into the `libs` directory:
```shell
cd libs
```
4. Copy the Filecoin Solidity API contracts with the methods you wish to call from [the contracts folder](https://github.com/filecoin-project/filecoin-solidity/tree/master/contracts/v0.8) into `libs`. Preserve the subdirectories such as `types`, `utils`, and `cbor`, because the actor API files import those dependencies.
### Call a built-in actor
Once you’ve either imported particular contracts manually or installed `filecoin-solidity-api` using npm, create a callable method to access the built-in actor methods the way you normally would in a Solidity smart contract. See the [Filecoin.sol guide](/build-on-filecoin/developing-contracts/filecoin.sol) for npm import examples and the [reference guide](/reference/built-in-actors/filecoin.sol) for actor-specific method examples.
[Was this page helpful?](https://airtable.com/apppq4inOe4gmSSlk/pagoZHC2i1iqgphgl/form?prefill_Page+URL=https://docs.filecoin.io/build/developing-contracts/call-built-in-actors)
# 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.
```shell
npm install filecoin-solidity-api
```
## Works 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.
```solidity
// contracts/MyFilecoinContract.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import { MarketAPI } from "filecoin-solidity-api/contracts/v0.8/MarketAPI.sol";
import { MarketTypes } from "filecoin-solidity-api/contracts/v0.8/types/MarketTypes.sol";
import { Errors } from "filecoin-solidity-api/contracts/v0.8/utils/Errors.sol";
contract MyFilecoinContract {
function getDealTerm(uint64 dealID) public view returns (MarketTypes.GetDealTermReturn memory) {
(int256 exitCode, MarketTypes.GetDealTermReturn memory result) = MarketAPI.getDealTerm(dealID);
Errors.revertOnError(exitCode);
return result;
}
}
```
You can find the list of supported built-in actors and methods in the [Filecoin.sol documentation](/reference/built-in-actors/filecoin.sol). 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.sol` and `VerifRegAPI.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:
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import { MinerAPI } from "filecoin-solidity-api/contracts/v0.8/MinerAPI.sol";
import { CommonTypes } from "filecoin-solidity-api/contracts/v0.8/types/CommonTypes.sol";
import { MinerTypes } from "filecoin-solidity-api/contracts/v0.8/types/MinerTypes.sol";
import { Errors } from "filecoin-solidity-api/contracts/v0.8/utils/Errors.sol";
contract MinerQuery {
function getVestingFunds(uint64 minerActorID) public view returns (MinerTypes.VestingFunds[] memory) {
CommonTypes.FilActorId minerID = CommonTypes.FilActorId.wrap(minerActorID);
(int256 exitCode, MinerTypes.VestingFunds[] memory vestingFunds) = MinerAPI.getVestingFunds(minerID);
Errors.revertOnError(exitCode);
return vestingFunds;
}
}
```
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:
```solidity
import { Actor } from "filecoin-solidity-api/contracts/v0.8/utils/Actor.sol";
import { BigInts } from "filecoin-solidity-api/contracts/v0.8/utils/BigInts.sol";
import { FilAddresses } from "filecoin-solidity-api/contracts/v0.8/utils/FilAddresses.sol";
```
## Example
We can write a simple Solidity smart contract to query basic information for a Filecoin storage deal:
```solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.18;
import "filecoin-solidity-api/contracts/v0.8/MarketAPI.sol";
import "filecoin-solidity-api/contracts/v0.8/types/CommonTypes.sol";
import "filecoin-solidity-api/contracts/v0.8/types/MarketTypes.sol";
import "filecoin-solidity-api/contracts/v0.8/utils/Errors.sol";
contract StorageDealQuery {
// Query the start epoch and duration, in epochs, of a deal proposal.
function get_deal_term(uint64 dealID) public view returns (MarketTypes.GetDealTermReturn memory) {
(int256 exitCode, MarketTypes.GetDealTermReturn memory result) = MarketAPI.getDealTerm(dealID);
Errors.revertOnError(exitCode);
return result;
}
// Query the storage provider who stores the data for this deal.
function get_deal_provider(uint64 dealID) public view returns (uint64) {
(int256 exitCode, uint64 result) = MarketAPI.getDealProvider(dealID);
Errors.revertOnError(exitCode);
return result;
}
// Query the collateral required from the storage provider for this deal proposal.
function get_deal_provider_collateral(uint64 dealID) public view returns (CommonTypes.BigInt memory) {
(int256 exitCode, CommonTypes.BigInt memory result) = MarketAPI.getDealProviderCollateral(dealID);
Errors.revertOnError(exitCode);
return result;
}
}
```
#### Next steps
Check out these links to learn more about the Filecoin.sol library.
* [Filecoin-Solidity GitHub](https://github.com/filecoin-project/filecoin-solidity)
* [Built-In Actor APIs](/reference/built-in-actors/filecoin.sol)
* [FEVM Hardhat Kit](https://github.com/filecoin-project/fevm-hardhat-kit/)
[Was this page helpful?](https://airtable.com/apppq4inOe4gmSSlk/pagoZHC2i1iqgphgl/form?prefill_Page+URL=https://docs.filecoin.io/build/developing-contracts/filecoin.sol)
# Solidity libraries
With Filecoin Virtual Machine (FVM), Solidity developers can use existing libraries listed on this page in their FVM smart contracts.
## OpenZeppelin
[OpenZeppelin](https://www.openzeppelin.com/contracts) 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](/build-on-filecoin/developing-contracts/erc-20-quickstart).
### Benefits
OpenZeppelin offers the following to smart contract developers:
* Implementations of standards like ERC20, ERC721, and ERC1155.
* Flexible access control schemes like `Ownable`, `AccessControl`, and `onlyRole`.
* Useful and secure utilities for signature verification, math, strings, and cryptography.
Token standards, such as [ERC20](https://docs.openzeppelin.com/contracts/5.x/erc20), are the most widely used smart contract libraries from OpenZeppelin. These contracts, listed below, implement both *fungible* and *non-fungible* tokens:
* [ERC20](https://docs.openzeppelin.com/contracts/5.x/erc20) is the simplest and most widespread token standard for fungible assets.
* [ERC721](https://docs.openzeppelin.com/contracts/5.x/erc721) is the standard solution for non-fungible tokens and is often used for collectibles and games.
* [ERC1155](https://docs.openzeppelin.com/contracts/5.x/erc1155) is a multi-token standard where a single contract represents multiple fungible and non-fungible tokens, and operations are batched for increased gas efficiency.
* [ERC6909](https://docs.openzeppelin.com/contracts/5.x/erc6909) is a compact multi-token standard for managing several token IDs in one contract.
### Using OpenZeppelin with FVM
The *general* procedure for using OpenZeppelin with FVM is as follows:
1. Install OpenZeppelin. For example, using `npm`:
```shell
npm install @openzeppelin/contracts
```
2. Import the specific library you want to use.
3. 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](/build-on-filecoin/developing-contracts/erc-20-quickstart).
### Example using an ERC-20 contract
In the following tutorial, you’ll write and deploy a smart contract that implements the [ERC-20](https://docs.openzeppelin.com/contracts/5.x/erc20) 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.
* [MetaMask connected to the Calibration testnet](/networks-and-tools/networks/calibration).
* Test tokens (tFIL) [from the faucet](https://faucet.calibnet.chainsafe-fil.io/funds.html).
**Procedure**
In this procedure, you will create, deploy, mint and send an [ERC20](https://docs.openzeppelin.com/contracts/5.x/erc20) token on Calibration using Remix and MetaMask.
1. Navigate to [remix.ethereum.org](https://remix.ethereum.org/).
2. Next to **Workspaces**, click the **+** icon to create a new workspace.
3. In the **Choose a template** dropdown, select **Blank**.
4. Click **OK**.
5. In the **contracts** directory, create a file named **MyToken.sol**.
6. Paste the following contract:
```solidity
// contracts/MyToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
contract MyToken is ERC20, Ownable {
constructor(address initialOwner) ERC20("Calibration Gold", "CGLD") Ownable(initialOwner) {}
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
}
```
7. Next, compile and deploy the contract on Filecoin.
8. At the top of the workspace, click the green play symbol to compile the contract.
9. Once the contract compiles, open the **Deploy** tab on the left.
10. Under the **Environment** dropdown, select **Injected Provider - MetaMask**.
11. In the MetaMask popup window, select **Confirmed connection**.
12. Set `initialOwner` to your wallet address, click **Deploy**, and confirm the transaction on MetaMask. Your token contract will be deployed to the Calibration testnet once the network confirms the transaction.
13. In Remix, open the **Deployed Contracts** dropdown.
14. In the `mint` method, set:
* `to` to your wallet address.
* `amount` to `1000000000000000000` (1 token with 18 decimals).
15. Click **Transact**.
16. 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:
* [OpenZeppelin Contracts website](https://www.openzeppelin.com/contracts)
* [Documentation](https://docs.openzeppelin.com/contracts/5.x/)
* [GitHub](https://github.com/OpenZeppelin/openzeppelin-contracts)
## DappSys
The DappSys library provides safe, simple, and flexible Ethereum contract building blocks for common Ethereum and Solidity use cases.
* [Documentation](https://dappsys.readthedocs.io/en/latest/)
* [GitHub](https://github.com/dapphub/dappsys)
## 0x protocol
The 0x protocol library provides a set of secure smart contracts that facilitate peer-to-peer exchange of Ethereum-based assets.
* [Documentation](https://0x.org/docs/introduction/0x-cheat-sheet)
* [GitHub](https://github.com/0xProject)
[Was this page helpful?](https://airtable.com/apppq4inOe4gmSSlk/pagoZHC2i1iqgphgl/form?prefill_Page+URL=https://docs.filecoin.io/build/developing-contracts/solidity-libraries)
# Best practices
This page describes best practices for testing, developing and deploying smart contracts on the Filecoin network.
## Transactions
Best practices for transactions are described below.
### Consistently generating transaction receipts
Since receipts in Filecoin are generated in the next tipset, depending on when a transaction is submitted to the mempool, the receipt may take between 30 and 90 seconds to return. To consistently return transaction receipts when deploying a transaction or awaiting confirmation, change the default transaction receipt timeout (60000 ms or 1 minute for many toolchains) to 90 seconds or more. In a Hardhat script that already defines `upgrades`, `contract`, and `preparedArguments`, the relevant option for an OpenZeppelin upgradeable proxy is:
```js
const deployment = await upgrades.deployProxy(contract, preparedArguments, {
timeout: 180000
});
```
### Unstuck a message from the mempool
When users send messages to the Filecoin network, those messages will first land in the mempool. Once a node receives your message, it will verify the gas fee and signature and then process the transaction. Depending on network traffic and other factors, this process may take some time.
If the Filecoin network still needs to confirm a message, it’s because it has yet to be processed and is sitting in the mempool. Several causes exist, such as network congestion, insufficient gas fees, or an invalid message signature.
We recommend users resubmit the message with a higher gas fee or priority fee so those messages will not block the mempool and potentially impact the block-producing time. Gas fees on the network can fluctuate depending on network demand, so it’s always a good idea to monitor gas prices and adjust your fees accordingly to ensure your transaction is processed promptly.
#### **Metamask**
If you are building your project using MetaMask, it would be easier to educate the users to speed up a transaction by increasing the gas fee directly in MetaMask. Refer to the [official MetaMask documentation](https://support.metamask.io/manage-crypto/transactions/how-to-speed-up-or-cancel-a-pending-transaction/) for more details.
#### **Lotus**
Developers using Lotus can [replace an existing message with an updated gas fee](https://lotus.filecoin.io/kb/update-msg-gas-fee/).
#### **SDKs**
Developers processing messages using SDKs, such as ethers.js or web3.js, must replace the message with higher gas fees by following these steps:
1. Get the original message using its hash.
2. Create a new message with the same `nonce`, `to`, and `value` fields as the original message.
3. Set a higher `gasLimit` and `gasPrice` for this message.
4. Sign and send the new message.
## Futureproofing
Developers should take the time to thoroughly read through the following summary of possible contract future-proofing updates, as failure to properly future proof smart contracts may result in incompatibility with future Filecoin releases.
* **All contracts** must [accept both `DAG_CBOR (0x71)` and `CBOR (0x51)` in inputs and treat them identically, and use `CBOR (0x51)` in outputs](#accept-both-dag_cbor-0x71-and-cbor-0x51-in-inputs-and-treat-them-identically).
* If a contract uses t프로젝트로 돌아가기