Filecoin 백서

Filecoin

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 52쪽 중 14쪽

notice that our MetaMask window shows `0 tFIL`. Test-filecoin (`tFIL`) is `FIL` that has no value in the *real world*, and developers use it for testing. We’ll grab some `tFIL` next. ### Get some funds 1. In your browser, open MetaMask and copy your address to your clipboard: ![Copy your address to your clipboard.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-3eef138c98b41c9a6cfe268ec5bd057f06c16bd6%2Fsmart-contracts-fundamentals-erc-20-quickstart-faucet-get-address.webp?alt=media) 2. Go to [faucet.calibnet.chainsafe-fil.io](https://faucet.calibnet.chainsafe-fil.io) and click **Send Funds.** 3. Paste your address into the address field, and click **Send Funds**. 4. The faucet will show a transaction ID. You can copy this ID into a Calibration testnet [block explorer](/networks-and-tools/networks/calibration/explorers) to view your transaction. After a couple of minutes, you should see some `tFIL` transferred to your address. That’s all there is to it! Getting `tFIL` is easy! ## Contract creation The development environment we’re going to be using is called Remix, viewable at [remix.ethereum.org](https://remix.ethereum.org/). Remix is an incredibly sophisticated tool, and there’s a lot you can play around with! In this tutorial however, we’re going to stick to the very basics. If you want to learn more, check out [the Remix documentation](https://remix-ide.readthedocs.io/en/latest/). ### Create a workspace In Remix, workspaces are where you can create a contract, or group of contracts, for each project. Let’s create a new workspace to create our new ERC-20 token. 1. Open [remix.ethereum.org](https://remix.ethereum.org). 2. Open the dropdown menu and click **create a new workspace**. ![Create a new workspace.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-fa3238ebaecf6f080a0319af0393791f390c7fcb%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-dropdown.webp?alt=media\&token=f18e9631-11e3-4158-8eae-eac5f9e7cc30) 3. In the **Choose a template** dropdown, select **ERC20**. 4. Under **Customize template** > **Features**, check the **Mintable** box. 5. Enter a fun name for your token in the **Workspace name** field. Something like `CorgiCoin` works fine. 6. Click **OK** to create your new workspace. ![Set workspace details.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-d6636e9e34352ba45bf2a857d2b3458119f628f9%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-details.webp?alt=media) ### Customize the contract The contract template we’re using is pretty simple. We just need to modify a couple of variables. 1. Click the compiler icon to open the compiler panel. Update the compiler version by selecting `0.8.20` from the compiler dropdown. ![Update the compiler version](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-58ae7ae21203b3d640fab2dc589eb7d1d24be95e%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-compiler.webp?alt=media\&token=bd3d8d69-c4a8-4b09-9a93-1b0dc2231ffc) 2. Under the **contract** directory, click **MyToken.sol**. ![Open the MyToken contract.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-95c53aafcac6d72b7bf72d4080594f4cf57604ea%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-customize.webp?alt=media) 3. In the editor panel, replace `MyToken` with whatever you’d like to name your token. In this example, we’ll use `CorgiCoin`. ![Change token name.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-c999aa30bfa4512c9e631695d95486f4d5959343%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-token-name.webp?alt=media\&token=db85f788-a469-43a9-8f35-74dea401a839) 4. On the same line, replace the second string with whatever you want the symbol of your token to be. In this example, we’ll use `CRG`. ![Change token ticket.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-96a974040e0c792a4398e1bd9784b6a6aee91ebc%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-ticker.webp?alt=media\&token=d359f667-9f3e-453c-a09a-5d3a17d38272) That’s all we need to change within this contract. You can see on line 4 that this contract is importing another contract from `@openzeppelin` for us, meaning that we can keep our custom token contract simple. ### Compile 1. Click the green play symbol at the top of the workspace to compile your contract. You can also press `CMD` + `s` on MacOS or `CTRL` + `s` on Linux and Windows. ![Compile the contract.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-2268fdc9284837d03efbcd3cbdad3493884a0344%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-play.webp?alt=media\&token=dce89a81-95d3-46c3-9f3b-a73e0375e5ea) 2. Remix automatically fetches the three `import` contracts from the top of our `.sol` contract. You can see these imported contracts under the `.deps` directory. You can browse the contracts there, but Remix will not save any changes you make. ![Compile and get the dependencies](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-fc60f8353987b00c16c208267899cdbc21086b06%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-expand.webp?alt=media\&token=b74cd840-e0d5-49d6-af61-1f5260069c4e) ### Deploy Now that we’ve successfully compiled our contract, we need to deploy it somewhere! This is where our previous MetaMask setup comes into play. 1. Click the **Deploy** tab from the left. ![Select the deploy tab.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-119a3a46d7e676b763c65f153f24fd1df0b1a81b%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-compile-button.webp?alt=media\&token=aa663cd4-8c6a-4c2b-ac3d-8162c8c9170f) 2. Under the **Environment** dropdown, select **Injected Provider - MetaMask**. ![Select MetaMask within Remix.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-ea4df9832a35e6c08c47dcb5a7882b4b4d2a6223%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-inject-meta.webp?alt=media\&token=229dc195-86f6-4328-b7f7-ed75a4ad6c86) 3. MetaMask will open a new window confirming that you want to connect your account to Remix. 4. Click **Next**: ![Click next in MetaMask.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-a36106282994c9f3594a5b7584ed7f09b2dcc0b0%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-mm-next.webp?alt=media) 5. Click **Connect** to connect your `tFIL` account to Remix. ![Click Connect in MetaMask.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-3477b9aca46a423694abf5854db660d90bc7ec0d%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-mm-connect.webp?alt=media) 6. Back in Remix, under the **Account** field, you’ll see that it says something like `0x11F... (5 ether)`. This value is 5 `tFIL`, but Remix doesn’t support the Filecoin network so doesn’t understand what `tFIL` is. This isn’t a problem, it’s just a little quirk of using Remix. ![Remix and MetaMask linked.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-7fc3b92dc6fdede0cdeb65830ad58492dab887f3%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-accountid.webp?alt=media\&token=a34ed724-e48e-4a17-a137-dcf0d9f6fcec) 7. Under the **Contract** dropdown, ensure the contract you created is selected. ![Select contract in Remix.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-a51101dcc7d65618950b7f1f0c27c96013561087%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-deploy-select.webp?alt=media) 8. Gather your MetaMask account address and populate the deploy field in Remix. ![Copy the address in MetaMask](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-5a00a6346d20c3a81eb5e156d42db6350acb56d5%2Fsmart-contract-fundamentals-erc-20-quickstart-mm-account.webp?alt=media\&token=a1bd559b-c18d-4e6f-bdcb-a17113de55a0) ![Populate the deploy address](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-5cc03cd4ac87136e4a938d13b385ed575f47c117%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-deploy-address.webp?alt=media\&token=eeef5d2a-d28b-4e42-a5f1-3a0a89db4d47) 9. Click **Deploy**. ![Click Deploy in Remix.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-1fa8e61824f868132313a21d6b7aa01fd18f5afd%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-click-deploy.webp?alt=media) 10. MetaMask will open a window and as you to confirm the transaction. Scroll down and click **Confirm** to have MetaMask deploy the contract. 11. Back in Remix, a message at the bottom of the screen shows that the creation of your token is pending. ![Deployment confirmation in Remix.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-8d65091f987a22b6ffe60986ac2ea978a6f0f92a%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-confirmation.webp?alt=media) 12. Wait around 90 seconds for the deployment to complete. ![Deployment complete.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-632688ccc909d8b20c9b2aa9bb4f4d34becad529%2Fsmart-contracts-fundamentals-erc-20-quickstart-remix-complete.webp?alt=media) On the Filecoin network, a new set of blocks, also called a tipset, is created every thirty seconds. When deploying a contract, the transaction needs to be received by the network, and then the network needs to confirm the contract. This process takes around one to two tipsets to process – or around 60 to 90 seconds. ## Use your contract Now that we’ve compiled and deployed the contract, it’s time to actually interact with it! ### Mint your tokens Let’s call a method within the deployed contract to mint some tokens. 1. Back in Remix, open the **Deployed Contracts** dropdown, within the **Deploy** sidebar tab. ![Deploy the contracts.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-d0c67a60e2982e198293ad4e6bf4dcfcac1bbe59%2Fsmart-contracts-fundamentals-erc-20-quickstart-use-mint.webp?alt=media) 2. Expand the `mint` method. You must fill in two fields here: `to` and `amount`. ![Open the mint method.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-867c585d2fd65babddc495609b99a38cac40f0e5%2Fsmart-contracts-fundamentals-erc-20-quickstart-open-mint.webp?alt=media) 3. The `to` field specifies where address you want these initial tokens sent to. Open MetaMask, copy your address, and paste it into this field. ![Enter your address.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-a80ae71c2839a21670d737352278080ff19a98c3%2Fsmart-contracts-fundamentals-erc-20-quickstart-enter-address.webp?alt=media) 4. This field expects an `attoFil` value. 1 `FIL` is equal to 1,000,000,000,000,000,000 `attoFil`. So if you wanted to mint 100 `FIL`, you would enter `100` followed by 18 zeros: `100000000000000000000`. 5. Click **Transact**. ![Click transact.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-e93f272711f01589bd3d072cdb39344839eda109%2Fsmart-contracts-fundamentals-erc-20-quickstart-transact.webp?alt=media) 6. MetaMask will open a window and ask you to confirm the transaction: ![Confirm message in MetaMask.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-ce070602c96cc98624ce82c011c70c7d6662bfde%2Fsmart-contracts-fundamentals-erc-20-quickstart-mm-confirm.webp?alt=media) Again, you must wait for the network to process the transaction, which should take about 90 seconds. You can move on to the next section while you’re waiting. ### Add to MetaMask Currently, MetaMask has no idea what our token is or what it even does. We can fix this by explicitly telling MetaMask the address of our contract. 1. Go back to Remix and open the **Deploy** sidebar tab. 2. Under **Deployed Contracts**, you should see your contract address at the top. Click the copy icon to copy the address to your clipboard: ![Copy your contract address.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-931cc43ebe6d7450cc50cb3780d95958031a0107%2Fsmart-contracts-fundamentals-erc-20-quickstart-use-mint-copy.webp?alt=media) 3. Open MetaMask, select **Assets**, and click **Import your tokens**: ![Import your address details.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-85c33384a75557c9e13c1156289fd5e677b1de26%2Fsmart-contracts-fundamentals-erc-20-quickstart-use-mint-add-asset.webp?alt=media) 4. In the **Token contract address** field, paste the contract address you just copied from Remix and then click **Add custom token**. MetaMask should autofill the rest of the information based on what it can find from the Filecoin network. ![Complete your asset details.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-ccf97d094237bcfd601e41e99d166f0e5769695e%2Fsmart-contracts-fundamentals-erc-20-quickstart-use-mint-import.webp?alt=media) 5. Click **Import token**: 6. You should now be able to see that you have 100 of your tokens within your MetaMask wallet! ![MetaMask showing a new token.](https://3376433986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxNWFG7bQkjLkl5BBGjbD%2Fuploads%2Fgit-blob-76823312afbfa016ed591b801de52771ab190d58%2Fsmart-contracts-fundamentals-erc-20-quickstart-use-mint-complete.webp?alt=media) ### Share your tokens Having a bunch of tokens in your personal MetaMask is nice, but why not send some tokens to a friend? Your friend needs to create a wallet in MetaMask as we did in the [Create a wallet](#create-a-wallet) and [Switch networks](#switch-networks) sections. They will also need to import your contract deployment address like you did in the [Add your tokens to MetaMask](/networks-and-tools/assets/metamask-setup) section. Remember, you need to pay gas for every transaction that you make! If your friend tries to send some of your tokens to someone else but can’t, it might be because they don’t have any `tFIL`. [Was this page helpful?](https://airtable.com/apppq4inOe4gmSSlk/pagoZHC2i1iqgphgl/form?prefill_Page+URL=https://docs.filecoin.io/build/developing-contracts/erc-20-quickstart) # Call built-in actors Filecoin built-in actors can be invoked in a smart contract using either the Protocol API or the Filecoin.sol library. This page provides instructions on how to use each method. {% hint style="info" %} For conceptual information on built-in actors, including their purposes, how they work and available types, see the [conceptual guide](/reference/built-in-actors) {% endhint %} Built-in actors can be invoked using the Protocol *JSON-RPC* API or the 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](https://filecoin-shipyard.github.io/filecoin.js/). The Filecoin.sol API: * Supports [*some but not all* of the built-in actors and their methods](#available-actors-and-methods). ## Protocol API Applications and off-chain services can access built-in actors and methods using the Filecoin JSON-RPC API exposed by nodes such as Lotus. Smart contracts should use Filecoin.sol or the actor precompiles instead. Links to the reference guides for each of the available actor methods are listed below: * [Account actor](#account) * [Datacap](#datacap) * [Miner](#miner) * [Multisig](#multisig) * [Storage market actor](#storage-market) * [Storage power actor](#storage-power) * [Verified registry actor](#verified-registry) ## 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 call methods of Filecoin built-in actors. The maintained npm package is `filecoin-solidity-api`, and its current import paths use `contracts/v0.8`. This section contains information on the actors and methods available from `filecoin.sol`, along with installation instructions and references for examples of smart contracts that call built-in actor methods. To invoke built-in actor methods using `filecoin.sol`, follow these steps: 1. Review the [available actors and methods](#available-actors-and-methods). 2. [Import `filecoin.sol`](#import-filecoinsol). 3. [Call a built-in actor](#call-a-built-in-actor). ### 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** | Method | Supported? | | --------------------- | ---------- | | AuthenticateMessage | ✔️ | | Constructor | ✖️ | | PubkeyAddress | ✖️ | | UniversalReceiverHook | ✔️ | #### **DataCap** | Method | Supported? | | ----------------- | ---------- | | Allowance | ✔️ | | BalanceOf | ✔️ | | Burn | ✔️ | | BurnFrom | ✔️ | | Constructor | ✖️ | | DecreaseAllowance | ✔️ | | Destroy | ✖️ | | IncreaseAllowance | ✔️ | | Mint | ✖️ | | Name | ✔️ | | RevokeAllowance | ✔️ | | Symbol | ✔️ | | TotalSupply | ✔️ | | Transfer | ✔️ | | TransferFrom | ✔️ | #### **Miner** | Method | Supported? | | ------------------------- | ---------- | | ApplyRewards | ✖️ | | ChangeBeneficiary | ✔️ | | ChangeMultiaddrs | ✔️ | | ChangeOwnerAddress | ✔️ | | ChangePeerID | ✔️ | | ChangeWorkerAddress | ✔️ | | CheckSectorProven | ✖️ | | CompactPartitions | ✖️ | | CompactSectorNumbers | ✖️ | | ConfirmSectorProofsValid | ✖️ | | ConfirmUpdateWorkerKey | ✖️ | | Constructor | ✖️ | | ControlAddresses | ✖️ | | DeclareFaults | ✖️ | | DeclareFaultsRecovered | ✖️ | | DisputeWindowedPoSt | ✖️ | | ExtendSectorExpiration | ✖️ | | ExtendSectorExpiration2 | ✖️ | | GetAvailableBalance | ✔️ | | GetBeneficiary | ✔️ | | GetOwner | ✔️ | | GetSectorSize | ✔️ | | GetVestingFunds | ✔️ | | IsControllingAddress | ✔️ | | OnDeferredCronEvent | ✖️ | | PreCommitS
프로젝트로 돌아가기