bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 52쪽 중 19쪽
if.io) offers public access to The Graph services, simplifying the process of deploying and managing subgraphs.
1. **Connect Your Wallet**
* On the [Protofire (Glif Nodes) platform - SUBGRAPHS](https://api.node.glif.io/graph), connect your [Filecoin-compatible wallet](/networks-and-tools/assets/wallets).
2. **Create an API Key**
* Choose the **API keys** tab.
* Click **Create new key**.
* Generate an API key to authenticate your requests.
3. **Activate Your Free Subscription**
* Go to the **Subscription** tab.
* If you have created a key, you will see one The Graph subscription pending.
* Click **Pay** and proceed with providing your credit card details to activate a free subscription.
{% hint style="warning" %}
Glif Nodes currently offers this service completely **free of charge**. If this ever changes, you will be notified at least one month in advance. It is recommended to provide your contact details on the Glif Nodes website to receive updates. Credit card details are used solely for DDoS protection. No charges will be made without prior notification.
{% endhint %}
4. **Create a Subgraph**
* Switch back to the **Subgraphs** tab.
* Click on **Create a New Subgraph** to set up a new subgraph instance.
5. **Manage Your Subgraphs**
* Select **MY** in the subgraphs switcher.
* Select the subgraph you just created to access deployment instructions and endpoints.
* Should you have any additional inquiries, do not hesitate to contact the Glif Nodes team through the **Contact us** button in the website header.
### Querying Existing Subgraphs
One of the popular subgraphs is a subgraph containing information about all the blocks on the network, essentially providing an alternative to the `eth_getBlock...` subset of commands. Let's see how we can query the `eth_getBlockByNumber` using the Linux command-line interface and the Protofire (Glif Nodes) platform.
* Visit the [Protofire (Glif Nodes) platform](https://api.node.glif.io).
* Navigate to the **SUBGRAPHS** tab.
* Select the relevant subgraph from [Protofire](https://api.node.glif.io/graph).
* In the opened **Playground** tab, click the **Show GraphQL Explorer** button (folder icon, 3rd from the top in the left bar) to verify the subgraph schema.
* Click the elements that you are looking to query and adjust the query if necessary. For the sake of this example, let's query the first block this subgraph supports (#2867000). The resulting query should look like the following:
```graphql
query MyQuery {
blocks(block: {number: 2867000}) {
number
id
timestamp
gasLimit
gasUsed
}
}
```
* Click **Execute query** (alternatively Ctrl+Enter, the icon with white triangle in the red square) and adjust query if needed.
```json
{
"data": {
"blocks": [
{
"number": "2867000",
"id": "0x2df02173a94343c971733e0c94b854dee9100fbd37c70d69956bf35bca7020da",
"timestamp": "1684316400",
"gasLimit": "70000000000",
"gasUsed": "24086592799"
}
]
}
}
```
* Copy **Queries (HTTP)** URL on the top of the Playground as well as resulting query to your code. The subgraph querying is free so far, although it requires an API key.
# Cross-chain bridges
Blockchain networks are often isolated and cannot interact with each other directly, so cross-chain bridges serve as a link between them and bring interoperability between different blockchains.
Cross-chain bridges have many use cases, such as enabling decentralized exchanges to support the trading of assets from multiple blockchain networks or allowing users to access decentralized applications (dApps) on different networks. They are also helpful for interoperability between separate blockchain networks, essential for the growth and adoption of blockchain technology.
## Available bridges
Regarding bridges, security is the top concern. The Filecoin team is focused on integrating with notary-based bridges that have a solid security model. Eventually, trustless light-client-based bridging solutions will be available.
### [Axelar](https://axelar.network/)
Axelar enables both token bridge and general message passing and is well-connected to major EVM chains & Cosmos ecosystem.
Initially, the bridge will support the following assets: wFIL, wETH, wBTC, USDC, and USDT.
#### **Axelar smart contracts**
Currently, Axelar supports Filecoin Mainnet.
| Name | Mainnet |
| ------- | -------------------------------------------- |
| wFIL | `0x60E1773636CF5E4A227d9AC24F20fEca034ee25A` |
| axlUSDC | `0xEB466342C4d449BC9f53A865D5Cb90586f405215` |
| axlUSDT | `0x7f5373AE26c3E8FfC4c77b7255DF7eC1A9aF52a6` |
| axlWBTC | `0x1a35EE4640b0A3B87705B0A4B45D227Ba60Ca2ad` |
| axlWETH | `0xb829b68f57CC546dA7E5806A929e53bE32a4625D` |
| axlDAI | `0x5C7e299CF531eb66f2A1dF637d37AbB78e6200C7` |
#### **Further Axelar resources**
* [Axelar docs for developers](https://docs.axelar.dev/dev/intro)
* [Axelar with Squid Router](https://app.squidrouter.com/)
* [Getting Started with Axelar on FVM Tutorial](https://www.youtube.com/watch?v=L7cw5FhxW4s)
### [Celer](https://cbridge.celer.network/1/314)
Celer is a blockchain interoperability protocol enabling a one-click user experience accessing tokens, DeFi, GameFi, NFTs, governance, and privacy solutions across multiple chains. Celer has been successfully supporting Filecoin on both assets bridging using it’s CBridge and messaging passing through Celer Inter-chain Messaging (Celer IM).
Initially, the bridge will support the following assets: wFIL, wETH, wBTC, USDC, and USDT.
### **Celer smart contracts**
Celar’s CBridge supports both Filecoin Mainnet and Calibration testnet.
| Name | Mainnet | Calibration |
| ---------- | -------------------------------------------- | -------------------------------------------- |
| wFIL | `0x60E1773636CF5E4A227d9AC24F20fEca034ee25A` | |
| ceUSDC | `0x2421db204968A367CC2C866CD057fA754Cb84EdF` | `0xf5C6825015280CdfD0b56903F9F8B5A2233476F5` |
| ceUSDT | `0x422849b355039bc58f2780cc4854919fc9cfaf94` | `0x7d43AABC515C356145049227CeE54B608342c0ad` |
| ceWBTC | `0x592786e04c47844aa3b343b19ef2f50a255a477f` | `0x265B25e22bcd7f10a5bD6E6410F10537Cc7567e8` |
| ceWETH | `0x522b61755b5ff8176b2931da7bf1a5f9414eb710` | `0x5471ea8f739dd37E9B81Be9c5c77754D8AA953E4` |
| MessageBus | `0x6ff2130fbdd2837b0c92d7f56f6c017642d84f66` | `0xd5818D039A702DdccfD11A900A40B3dc6DA03CEc` |
### **Further Celer resources**
* [cBridge docs](https://cbridge-docs.celer.network/)
* [Celer IM Docs](https://im-docs.celer.network/)
[Was this page helpful?](https://airtable.com/apppq4inOe4gmSSlk/pagoZHC2i1iqgphgl/form?prefill_Page+URL=https://docs.filecoin.io/build/advanced/cross-chain-bridges)
# Contract automation
Smart contract automation enables decentralized applications (dapps) to interact with both on-chain and off-chain data in an automated and trustless manner. Automation tools allow developers to build
In the Filecoin network, smart contracts benefit from a secure, deterministic environment. While this ensures reliability, it also limits direct access to external data sources. However, developers can leverage automation services to seamlessly connect off-chain data with on-chain smart contracts. This unlocks advanced capabilities such as price feeds, data verification, and much more, empowering Filecoin dapps with dynamic, real-world functionality by integrating external data into on-chain logic.
## Available automation services
### [Gelato](https://gelato.network/)
Gelato's Web3 Functions is a powerful automation system designed to streamline and enhance Web3 operations. Web3 Functions serve as a comprehensive tool, enabling developers to effortlessly set up, manage, and automate their smart contract tasks.
#### **How Gelato Web3 functions work?**
Web3 Functions can be triggered by various events and allow developers to write both off-chain logic (TypeScript) and on-chain logic (Solidity). Once deployed, they handle automated smart contract interactions, providing real-time monitoring and flexibility.
**Off-chain Data or Computation?** Sometimes, automation tasks require data that isn't readily available on the blockchain, or they might need computations that are better performed off-chain. In such cases, Typescript Functions should be the choice.
**All Checks On-chain?** If all the conditions necessary for your automation task can be directly verified on the blockchain, you have the option to select between Typescript Functions, Solidity Functions & Automated Transactions
## Triggers
1. Time Interval Use this trigger to execute tasks at regular intervals, e.g., every 10 minutes or once every 24 hours. It's like setting a straightforward, recurring alarm.
2. Cron Expressions This offers a more refined control compared to the Time Interval. With cron expressions, you can set tasks to run at specific moments, such as "every Tuesday at 3 PM" or "on the 1st of every month". It gives you precision in task scheduling.
3. On-Chain Event Ideal for those wanting their tasks to respond dynamically to blockchain activities. Whenever a specified event occurs on the blockchain, this trigger springs your task into action. It's like a vigilant watcher, always ready to act.
4. Every Block This function operates with the rhythm of the blockchain itself, executing your chosen function each time a new block is created.
## What to Execute?
### Typescript Functions
Typescript Functions are decentralized cloud functions that work similarly to AWS Lambda or Google Cloud, just for web3. They enable developers to execute on-chain transactions based on arbitrary off-chain data (APIs / subgraphs, etc) & computation. These functions are written in Typescript, stored on IPFS and run by Gelato.
### Solidity Functions
Solidity Functions are crucial for making on-chain tasks automatic and more efficient. They connect set conditions with specific actions in a smart contract, providing a straightforward method to turn user needs into automated processes. Consider them as a set of "if-then" rules: If certain conditions are met on the blockchain, then a specific function gets executed. This level of automation ensures that the decentralized application can operate with minimal manual intervention, providing a seamless user experience.
### Automated Transaction
Automated Transaction ensures that a specific function on the target smart contract gets reliably triggered. When you pre-define the inputs, it means that every time Gelato initiates the function call, it uses consistent, predetermined arguments.
#### **What is dedicatedMsgSender?**
For security reasons, during task creation, you will see an address that acts as the msg.sender for your task executions. This address is a proxy contract deployed by Gelato. It ensures that every task execution on behalf of your contract uses this dedicated msg.sender address, which is essential for validating the origin of the task.
## Quick Start
### Writing and deploying TypeScript functions
1. Clone Gelato's maintained Web3 Functions template:
```bash
git clone https://github.com/gelatodigital/web3-functions-template.git
```
2. Change into the template directory and install dependencies:
```bash
cd web3-functions-template && yarn install
```
3. Update `index.ts` in one of the examples.
The following TypeScript block is a skeleton only. It shows the shape of a Gelato Web3 Function that checks whether an oracle should be updated, then returns encoded call data. Replace the oracle ABI, input arguments, and off-chain data lookup with your application's logic. For maintained end-to-end examples, use the [Gelato Web3 Functions template](https://github.com/gelatodigital/web3-functions-template) and the [Gelato TypeScript Functions guide](https://docs.gelato.cloud/web3-functions/how-to-guides/write-typescript-functions/getting-started).
```typescript
import { Web3Function, Web3FunctionContext } from "@gelatonetwork/web3-functions-sdk";
import { Contract } from "@ethersproject/contracts";
const ORACLE_ABI = [
"function lastUpdated() external view returns (uint256)",
"function updatePrice(uint256)",
];
Web3Function.onRun(async (context: Web3FunctionContext) => {
const { userArgs, multiChainProvider } = context;
const provider = multiChainProvider.default();
const oracleAddress =
(userArgs.oracle as string) ?? "0x71B9B0F6C999CBbB0FeF9c92B80D54e4973214da";
const oracle = new Contract(oracleAddress, ORACLE_ABI, provider);
const lastUpdated = Number(await oracle.lastUpdated());
const latestBlock = await provider.getBlock("latest");
const nextUpdateTime = lastUpdated + 300;
if (!latestBlock || latestBlock.timestamp < nextUpdateTime) {
return { canExec: false, message: "Time not elapsed" };
}
const price = Number(userArgs.price ?? 0);
if (!Number.isFinite(price) || price <= 0) {
return { canExec: false, message: "No valid price supplied" };
}
return {
canExec: true,
callData: [
{
to: oracleAddress,
data: oracle.interface.encodeFunctionData("updatePrice", [price]),
},
],
};
});
```
4. Test and deploy the Web3 Function to IPFS:
```bash
npx w3f test web3-functions/YOUR-FUNCTION/index.ts --logs
npx w3f deploy web3-functions/YOUR-FUNCTION/index.ts
```
Example output:
```
✓ Web3Function deployed to IPFS.
✓ CID: <ipfs-cid>
```
Finally, go to the [Gelato App](https://app.gelato.cloud), create a new task, decide on the trigger, and input the CID.
For a detailed guide on creating and deploying Web3 Functions, including setting up your development environment, triggers, and security configurations, see the [Gelato Web3 Functions docs](https://docs.gelato.cloud/web3-functions/how-to-guides/write-typescript-functions/getting-started).
#### **Further Resources**
* [Gelato Web3 Functions Docs](https://docs.gelato.cloud/web3-functions/how-to-guides/write-typescript-functions/getting-started)
* [Gelato Web3 Functions template](https://github.com/gelatodigital/web3-functions-template)
* [Gelato Web3 Functions examples](https://github.com/gelatodigital/how-tos-3-w3f-triggers)
# Relay
Relay is a service that allows users to interact with the Filecoin network using meta transactions. Users can submit transactions to the network without having to pay gas fees. Instead, a relayer pays
## Meta Transactions
Meta transactions are a type of transaction that allows users to interact with the Filecoin network without having to pay for gas fees. Instead, a third party, known as a relayer, pays the gas fees on behalf of the user. This enables users to interact with the network without having to hold FIL tokens or manage their own wallets.
## Available relayers
Relayer support and contract addresses change over time. Before deploying a Filecoin Mainnet or Calibration integration, verify that your target network is listed in the relayer's current supported-network documentation and use the current trusted forwarder or relay contract address for that network.
### [Gelato](https://gelato.network/)
Relay services, like Gelato Relay, act as intermediaries that handle the submission of meta-transactions to the blockchain. By integrating relay contracts (such as GelatoRelayContext or ERC2771Context) into a smart contract, developers can enable gasless transactions. This allows users to interact with decentralized applications without holding native tokens, while maintaining security through features like EIP-712 signature validation.
The relayer ensures the transaction is executed securely and promptly, handling the gas fee payment either off-chain (via a sponsor) or on-chain (with the user’s funds). This system simplifies blockchain interactions, broadening accessibility and reducing friction for dapp users.
### Use cases
* Highlight.xyz: Allows users to mint NFTs without incurring gas fees.
* ZED RUN: Automates breeding processes for digital racehorses.
* Reya: Enable gasless trading on the platform
#### Off-chain and on-chain payments
Transactions can be paid for in two primary ways: off-chain payments and on-chain payments. Each method offers flexibility depending on how developers wish to handle transaction fees for their users.
**Off-chain payments**
* **SponsoredCallERC2771**: In this method, Gelato uses the ERC-2771 meta-transaction standard to allow gasless transactions. The user signs a message, and the relay service covers the gas fees. ERC-2771Context ensures that the user’s identity is verified off-chain, by encoding the user’s address in the last 20 bytes of the transaction. This provides a secure, gasless experience where Gelato, using its 1Balance, sponsors the transaction fee.
* **SponsoredCall**: When there is no need for ERC-2771's off-chain signature verification, this more flexible method can be used. The transaction fees are still covered by the sponsor using 1balance, but the responsibility for managing security measures such as signature validation and replay protection lies with the project. This option is ideal for use cases that already have built-in security mechanisms.
**On-chain payments**
* **callWithSyncFeeERC2771**: This method combines ERC-2771 meta-transaction functionality with Gelato’s SyncFee model. The user’s gas fee is calculated and paid directly from the smart contract during the transaction execution. Gelato’s Fee Oracle estimates the fee in real-time, and the GelatoRelayContext contract automatically handles the fee transfer. This is ideal for developers who want to maintain user signature verification while ensuring users cover their transaction costs.
* **callWithSyncFee**: This method is similar to callWithSyncFeeERC2771 but without the need for ERC-2771’s off-chain signature verification. The user’s gas fee is calculated and paid directly from the target smart contract during the transaction execution. This approach is useful for applications where users are expected to pay for their own gas without requiring meta-transaction features.
### Implementation
We will require three simple steps to implement Gelato Relay. Here, we are going to showcase the three steps required to implement the method `sponsoredCallERC2771`, which is the most used one.
#### Step 1: Inherit Context Contract
Depending on the method, you must inherit different contracts as they will provide other methods. In this case, we will have to inherit the `ERC2771Context`. The `ERC2771Context` provides us with the methods `_msgSender()` and `_msgData()` that will allow us to recover the original user sending the transaction.
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import {
ERC2771Context
} from "@gelatonetwork/relay-context/contracts/vendor/ERC2771Context.sol";
contract CounterERC2771 is ERC2771Context {
mapping(address => uint256) public contextCounter;
event IncrementContextCounter(address indexed account, uint256 value);
// ERC2771Context: setting the immutable trustedForwarder variable
constructor(address trustedForwarder) ERC2771Context(trustedForwarder) {}
function incrementContext() external {
address sender = _msgSender();
uint256 nextValue = contextCounter[sender] + 1;
// Incrementing the counter mapped to the _msgSender!
contextCounter[sender] = nextValue;
// Emitting an event for testing purposes
emit IncrementContextCounter(sender, nextValue);
}
}
```
#### Step 2: Import the relay SDK
In your frontend or backend, import and instantiate the relay class. For ERC-2771 calls, deploy your contract with the trusted forwarder for the relay method and network you are targeting. Check Gelato's [supported networks](https://docs.gelato.cloud/relay/additional-resources/supported-networks) page before deploying.
```typescript
import {
GelatoRelay,
type CallWithERC2771Request,
} from "@gelatonetwork/relay-sdk";
const relay = new GelatoRelay();
```
#### Step 3: Send the payload to Gelato
This is a TypeScript skeleton for sending a `sponsoredCallERC2771` request. Replace the counter address, trusted forwarder, and API key with values for your deployed contract and supported target netwo프로젝트로 돌아가기