bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 52쪽 중 18쪽
ct.
The steps above differ slightly for integrations using smart contracts, where steps 2 and 3 are replaced with:
2. Import the Multicall3 interface in your smart contract.
3. Create a function that interacts with the Multicall3 contract using the imported interface.
Many libraries and tools such as [ethers-rs](https://docs.rs/ethers/latest/ethers/), [viem](https://viem.sh/), and [ape](https://apeworx.io/) have native Multicall3 integration which can be used in your projects directly. To learn how to use Multicall3 with these tools, check out [Multicall3 examples folder](https://github.com/mds1/multicall/blob/main/examples)
#### Batching Contract Reads
Batching contract reads, one of the most common use cases, allows a single `eth_call` JSON RPC request to return the results of multiple contract function calls. It has many benefits:
1. **Reduced JSON RPC Requests**: Multicall reduces the number of separate JSON RPC requests that need to be sent. This is particularly useful when using remote nodes, such as GLIF. By aggregating multiple contract reads into a single JSON-RPC request, Multicall (1) reduces RPC usage and therefore costs, and (2) reduces the number of round trips between the client and the node, which can significantly improve performance
2. **Consistent Data from the Same Block**: Multicall guarantees that all values returned are from the same block. This ensures data consistency and reliability, as all the read operations are performed on the same state of the blockchain.
3. **Detection of Stale Data**: Multicall enables the block number or timestamp to be returned with the read data. This feature helps in detecting stale data, as developers can compare the block number or timestamp with the current state of the blockchain to ensure the data is up-to-date.
When directly interacting with the Multicall3 contract to batch calls, you'll typically use the `aggregate3` method. This method allows you to execute multiple contract calls in a single transaction. Here's an explanation of how it works, along with examples:
1. Solidity Implementation: The `aggregate3` method is implemented in the Multicall3 contract like this:
```solidity
function aggregate3(Call3[] calldata calls) public payable returns (Result[] memory returnData) {
uint256 length = calls.length;
returnData = new Result[](length);
for (uint256 i = 0; i < length;) {
(bool success, bytes memory ret) = calls[i].target.call(calls[i].callData);
if (calls[i].allowFailure) {
returnData[i] = Result(success, ret);
} else {
require(success, "Multicall3: call failed");
returnData[i] = Result(true, ret);
}
unchecked { ++i; }
}
}
```
2. Example of sending multicalls to this smart contract: Here's an example using ethers.js to interact with the Multicall3 contract:
```javascript
const { ethers } = require("ethers");
const provider = new ethers.providers.JsonRpcProvider("https://api.node.glif.io/rpc/v1");
const multicallAddress = "0xcA11bde05977b3631167028862bE2a173976CA11";
const multicallAbi = [/* Multicall3 ABI */];
const multicall = new ethers.Contract(multicallAddress, multicallAbi, provider);
// Example: Batch balance checks for multiple addresses
async function batchBalanceChecks(addresses) {
const calls = addresses.map(address => ({
target: "0x...", // ERC20 token address
allowFailure: false,
callData: ethers.utils.id("balanceOf(address)").slice(0, 10) +
ethers.utils.defaultAbiCoder.encode(["address"], [address]).slice(2)
}));
const results = await multicall.aggregate3(calls);
return results.map(result => ethers.utils.defaultAbiCoder.decode(["uint256"], result.returnData)[0]);
}
batchBalanceChecks(["0x123...", "0x456...", "0x789..."]).then(console.log);
```
This example demonstrates how to use Multicall3 to batch multiple `balanceOf` calls for an ERC20 token in a single transaction, significantly reducing the number of separate RPC calls needed.
#### Batch Contract Writes
> :warning: Multicall3, while unaudited, can be safely used for batching on-chain writes when used correctly. As a stateless contract, it should never hold funds after a transaction ends, and users should never approve it to spend tokens.
When using Multicall3, it's crucial to understand two key aspects: the behavior of `msg.sender` in calls versus delegatecalls, and the risks associated with `msg.value` in multicalls.
In FVM, there are two types of accounts: Externally Owned Accounts (EOAs) controlled by private keys, and Contract Accounts controlled by code. The `msg.sender` value during contract execution depends on whether a CALL or DELEGATECALL opcode is used. CALL changes the execution context, while DELEGATECALL preserves it.
For EOAs, which can only use CALL, Multicall3's address becomes the `msg.sender` for subsequent calls. This limits its usefulness from EOAs to scenarios where **`msg.sender` is irrelevant**. However, contract wallets or other contracts can use either CALL or DELEGATECALL, with the latter preserving the original `msg.sender`.
The handling of `msg.value` in multicalls requires caution. Since `msg.value` doesn't change with delegatecalls, relying on it within a multicall can lead to security vulnerabilities. To learn more about this, see [here](https://github.com/runtimeverification/verified-smart-contracts/wiki/List-of-Security-Vulnerabilities#payable-multicall) and [here](https://samczsun.com/two-rights-might-make-a-wrong/).
## Hints
Lotus FEVM RPC supports Ethereum batch transactions. The key difference between `multicall` and batch transactions is that `multicall` aggregates multiple RPC requests into a single call, while batch transactions are simply an array of transactions executed sequentially but sent in one request. For more details, please refer to the [Ethereum documentation](https://geth.ethereum.org/docs/interacting-with-geth/rpc/batch).
[Was this page helpful?](https://airtable.com/apppq4inOe4gmSSlk/pagoZHC2i1iqgphgl/form?prefill_Page+URL=https://docs.filecoin.io/build/advanced/multicall)
# Multisig
Multisig wallets enhance security and decentralization by requiring multiple signatures for transactions, distributing control among multiple participants.
In the Filecoin network, multisig wallets allow multiple parties to jointly manage a wallet by requiring a predefined number of signatures (approvals) for a transaction to be executed. This enhances security and decentralization by distributing control among multiple participants.
Multisig wallets are an essential component of many blockchain applications, as they enable collaborative management of funds and application state. Users initiate a transaction to be signed by fellow collaborators. Once the required number of approvals is met, the transaction is executed.
Multisig wallets enable builders to integrate the following features into their projects:
* **Decentralized Governance**: Parties asynchronously approve transactions initiated by its members.
* **Security**: Distributing control among multiple participants ensures that no single party has full control over the wallet.
* **Collaborative fund management**: Multiple parties can jointly manage a wallet by requiring a predefined number of signatures (approvals) for a transaction to be executed.
## Available multisig wallet implementations
There are several multisig wallet implementations on Filecoin. Builders can integrate these multisig wallets into their applications today.
### Filecoin Native Multisig
The Filecoin Native [MultisigActor](/core-concepts/filecoin-virtual-machine/actors#multisigactor) is a built-in actor that does not interact directly with the Filecoin EVM. Like other Filecoin actors, native multisig addresses begin with `f2` and represent a group of transaction signers with a maximum of 256 signers. Signers may be external users or the MultisigActor itself and can include `f1` and `f3` [addresses](/core-concepts/filecoin-virtual-machine/addresses).
#### Filecoin Native Multisig UIs
* [Glif Multisig](https://www.glif.io/en/multisig/) is a non-custodial web UI for the Filecoin Native Multisig wallet
* [MultisigActor CLI](https://lotus.filecoin.io/lotus/manage/multisig/) can also be used and is available from the Lotus CLI
### Safe multisig
[Safe](https://safe.global/) is a popular smart EVM multisig account infrastructure provider that allows users to manage their digital assets securely and can be used with many popular EVM wallets. It is non-custodial, formally verified, secures over $100B in assets, and is used by more than 200 projects. Safe has been deployed to the Filecoin EVM.
#### Safe UI
A web UI for the Safe multisig on Filecoin is available at:
* <https://safe.filecoin.io> - the default network is set to [Filecoin Mainnet](/networks-and-tools/networks/mainnet)

#### Safe Troubleshooting
* **Signing a transaction** from an account with no previous activity on the Filecoin blockchain will fail. You can send a transaction to this account with zero funds to initiate its on-chain activity to work around this issue.
* **Executing a transaction** can produce gas estimation issues for accounts that have a very small amount of funds (that would not or would barely cover the transaction).
* **Transaction confirmation times** may lead to prolonged "processing" status in the UI.
* **Safe addresses from other networks** can sometimes be used but require additional technical steps.
* In some cases the same Safe address and owner structure is not possible.
* Confirm complete creation (not just as a Placeholder) of the Safe multisig as an EVM contract on Filecoin prior to sending major funds.
* Instructions for deploying a Safe at the same address on another chain are available in [this video](https://share.zight.com/z8uBKZYr). Note that a compatible version of the Safe Proxy on the original chain must exist on Filecoin. Contact Safe-related support for help.
* If the previous address and chain use the L1 implementation of Safe Proxy, more complex technical migration steps will be required to map to the L2 version on Filecoin. Contact Safe-related support for more info.
* **Safe-related support** can be found in the "Need Help?" section of the Safe web UI.
#### Safe Transaction Service
The [Safe transaction service](https://docs.safe.global/core-api/api-safe-transaction-service) on Filecoin is available at:
* <https://transaction.safe.filecoin.io> on [Filecoin Mainnet](/networks-and-tools/networks/mainnet)
* <https://transaction-testnet.safe.filecoin.io> on [Filecoin Calibration testnet](/networks-and-tools/networks/calibration)
* Note:
* Faster finality is coming to Filecoin soon. For now, the Filecoin Safe transaction service sets `ETH_REORG_BLOCKS` to 60 blocks (i.e. Filecoin epochs) (30min) based on [FRC-0089](https://github.com/filecoin-project/FIPs/blob/master/FRCs/frc-0089.md) but users may want to wait 900 epochs (\~7.5h) for full finality.
#### Safe Smart Contracts
Safe’s multisig smart contracts are live on the Filecoin Mainnet and Calibration testnet.
| Name | Address | Mainnet | Calibration |
| ------------------------------------------------------------------------------------------------------------------ | -------------------------------------------- | ------- | ----------- |
| [SimulateTxAccessor](https://filecoin.blockscout.com/address/0x3d4BA2E0884aa488718476ca2FB8Efc291A46199) | `0x3d4BA2E0884aa488718476ca2FB8Efc291A46199` | ✔️ | ✔️ |
| [SafeProxyFactory](https://filecoin.blockscout.com/address/0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67) | `0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67` | ✔️ | ✔️ |
| [TokenCallbackHandler](https://filecoin.blockscout.com/address/0xeDCF620325E82e3B9836eaaeFdc4283E99Dd7562) | `0xeDCF620325E82e3B9836eaaeFdc4283E99Dd7562` | ✔️ | ✔️ |
| [CompatibilityFallbackHandler](https://filecoin.blockscout.com/address/0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99) | `0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99` | ✔️ | ✔️ |
| [CreateCall](https://filecoin.blockscout.com/address/0x9b35Af71d77eaf8d7e40252370304687390A1A52) | `0x9b35Af71d77eaf8d7e40252370304687390A1A52` | ✔️ | ✔️ |
| [MultiSend](https://filecoin.blockscout.com/address/0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526) | `0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526` | ✔️ | ✔️ |
| [MultiSendCallOnly](https://filecoin.blockscout.com/address/0x9641d764fc13c8B624c04430C7356C1C7C8102e2) | `0x9641d764fc13c8B624c04430C7356C1C7C8102e2` | ✔️ | ✔️ |
| [SignMessageLib](https://filecoin.blockscout.com/address/0xd53cd0aB83D845Ac265BE939c57F53AD838012c9) | `0xd53cd0aB83D845Ac265BE939c57F53AD838012c9` | ✔️ | ✔️ |
| [SafeL2](https://filecoin.blockscout.com/address/0x29fcB43b46531BcA003ddC8FCB67FFE91900C762) | `0x29fcB43b46531BcA003ddC8FCB67FFE91900C762` | ✔️ | ✔️ |
| [Safe](https://filecoin.blockscout.com/address/0x41675C099F32341bf84BFc5382aF534df5C7461a) | `0x41675C099F32341bf84BFc5382aF534df5C7461a` | ✔️ | ✔️ |
#### **Further Safe resources**
* [Safe Docs](https://docs.safe.global/home/what-is-safe)
[Was this page helpful?](https://airtable.com/apppq4inOe4gmSSlk/pagoZHC2i1iqgphgl/form?prefill_Page+URL=https://docs.filecoin.io/build/advanced/multisig)
# FEVM Indexers
FEVM Indexers allow users and developers to query Filecoin chain data in an extremely quick manner. Learn what FEVM indexers are available on Filecoin and how to use them through existing data provide
> *Not to be confused with* [*IPNI Indexer*](/provide-storage/architecture/network-indexer)
Blockchain indexers are used for accessing blockchain data efficiently. They process and organize storage-optimized raw blockchain data into retrieve-optimized and well-queryable formats. This benefits developers and users looking to retrieve specific information because they don't need to:
1. Run their own [archival node](/networks-and-tools/networks/mainnet/rpcs).
2. Parse entire blockchain histories to crawl for events that might not exist for thousands of [tipsets](/core-concepts/filecoin-virtual-machine/blocks-and-tipsets#tipsets).
3. Spend significant time required to retrieve data from the blockchain node.
4. Determine complex interconnections between smart contracts.
5. Spend substantial compute power to calculate advanced queries.
Additionally, blockchain indexers provide a better developer experience by leveraging well-known API standards and query languages like GraphQL.
## Goldsky
[Goldsky](https://goldsky.com/) offers high-performance subgraph hosting and real-time data indexing for blockchain data. These are GraphQL-based APIs built on top of smart contracts. With Goldsky, developers can access structured blockchain data quickly and efficiently without needing to run their own nodes or build custom indexing backends.
Goldsky officially supports the Filecoin, allowing developers to create subgraphs that index smart contract data from the Filecoin mainnet & testnet.
**Ways to Deploy a Subgraph with Goldsky**
**1. Goldsky Web App (No-Code)** A visual interface that guides you step-by-step to configure and deploy a subgraph. Ideal for quick prototyping or less technical users.
**2. Goldsky CLI (Developer Tooling)** A command-line interface for creating, editing, and deploying subgraphs programmatically.
* From Subgraph source code
* Migrating from The Graph or any other subgraph host
* Via instant, no-code subgraphs
In this tutorial, we will use no-code Goldsky’s deploy wizard to create a subgraph for the wFIl ERC-20 token on the Filecoin testnet.
### Prerequisites
Make sure you have the following tools and setup ready:
* Node.js
* Create a Goldsky account and generate a Goldsky API key
* Goldsky CLI installed
```shell
curl https://goldsky.com | sh
```
* Authenticate Goldsky CLI with your API key
```shell
goldsky login
```
* wFIl Contract information
* contract address: `0xaC26a4Ab9cF2A8c5DBaB6fb4351ec0F4b07356c4`
* [contract ABI](https://beryx.io/fil/calibration/address/0xaC26a4Ab9cF2A8c5DBaB6fb4351ec0F4b07356c4?tab=contract): saved it as `wfil_abi.json` locally.
### Deploy a subgraph
Goldsky’s Deploy Wizard simplifies the creation of subgraphs using a CLI-guided flow.
Run:
```shell
goldsky subgraph init
```
Follow the prompts from the Goldsky subgraph configuration wizard:
* *Subgraph name*: wfil-subgraph
* *Subgraph version*: 1.0.0
* *Subgraph target path*: Choose default or specify your own
* *Contract ABI source*: path/to/wfil\_abi.json
* *Contract Address*: `0xaC26a4Ab9cF2A8c5DBaB6fb4351ec0F4b07356c4`
* *Contract network*: filecoin-testnet
* *Start block*: Which block is the wfil created, can be 0.
* *Contract name*: wfil
* *Enable subgraph call handlers?*: no
Once you complete the above information following the prompt, the Goldsky wizard will guide you through building and deploying your subgraph. Once the subgraph is successfully deployed, Goldsky will output a deployment URL (GraphQL endpoint).
Indexing all the data for your smart contract will take time after the subgraph is deployed. You can also check the indexing status of your subgraph from the [Goldsky dashboard](https://app.goldsky.com/).
### Query the Subgraph
You can use the provided GraphQL endpoint to query the subgraph.
For example:
```graphql
{
transfers(
where: {from: "0xf49d33f54ce41354dcd7e698aa54256781a6dd30"}
orderBy: timestamp_
orderDirection: desc
first: 10
) {
id
from
to
amount
timestamp_
}
}
```
Use the Goldsky Playground or integrate it into your app to consume indexed data.
## The Graph
[The Graph](https://thegraph.com) is a decentralized protocol for indexing blockchain data. It enables developers to build and publish custom open APIs, known as subgraphs, that applications can query to retrieve blockchain data using GraphQL in a time-efficient manner.
#### Glossary
* **Subgraphs**: Customizable schemas that define how to index data from specific blockchain smart contracts and events.
* **GraphQL**: A query language that allows clients to request exactly the data they need, making data fetching more efficient.
#### Querying Subgraphs on Filecoin FEVM
There are many ways to query existing subgraphs, including numerous well-known libraries for [JavaScript](https://thegraph.com/docs/en/querying/querying-from-an-application/) and [Python](https://thegraph.com/docs/en/querying/querying-with-python/). But even without any third-party tooling, querying a subgraph is no more complicated than querying [RPC nodes](/reference/json-rpc). The only complexity is that you have to know the schema of the subgraph beforehand, similar to knowing SQL database tables and columns before being able to query them. Luckily, The Graph provides several ways to discover the subgraph schema. The most convenient one is called the ["Playground"](https://graphql.org/blog/2020-04-03-graphiql-graphql-playground/), and it is available upon a GET request to the subgraph query URL. Alternatively, you may use the discovery method that exists on every subgraph, called the [Introspection Query](https://graphql.org/learn/introspection/).
#### Developing Subgraphs on Filecoin FEVM
Developing a subgraph requires specialized knowledge that can be obtained through [The Graph Academy](https://thegraph.academy).
### Deploying Subgraphs
Just as with database data queried through SQL, subgraphs have to be stored somewhere. You may run a self-hosted instance as described in [The Graph Academy examples](https://thegraph.academy/developers/local-development/) and deploy a subgraph there. However, as with RPC nodes and databases, running subgraphs locally in production is not recommended from an uptime standpoint. For hosting the subgraph, it is reasonable to use online web services such as AWS or refer to professional subgraph providers such as [Protofire (aka Glif Nodes)](https://api.node.glif.io/graph).
#### Example: Deploying a Subgraph with Glif Nodes (Protofire)
[Protofire (aka Glif Nodes)](https://api.node.gl프로젝트로 돌아가기