Plasma 백서

Plasma

원문

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

f code. ## Supported Networks Bridge Kit supports bridging between Plasma and other [CCTP v2 chains](https://developers.circle.com/cctp/concepts/supported-chains-and-domains). ## Prerequisites Before you begin, you must have: * Node.js 20+ * A funded wallet with: * Native USDC on the source chain (use the [Circle Faucet](https://faucet.circle.com/) for testnet) * Gas on the source chain (for example, ETH on Ethereum Sepolia) * `XPL` on Plasma for destination gas when your wallet signs the mint step ([get testnet XPL](/docs/guides/testing-and-resources/get-test-tokens)) * Plasma added to your wallet. See [Browser Wallet Setup](/docs/guides/asset-management/browser-wallet-setup). ## Get Started <Steps> <Step title="Install Bridge Kit"> Install Bridge Kit and the Viem adapter for EVM chains, including Plasma: <CodeGroup> ```bash npm theme={null} npm install @circle-fin/bridge-kit @circle-fin/adapter-viem-v2 viem ``` ```bash yarn theme={null} yarn add @circle-fin/bridge-kit @circle-fin/adapter-viem-v2 viem ``` ```bash pnpm theme={null} pnpm add @circle-fin/bridge-kit @circle-fin/adapter-viem-v2 viem ``` </CodeGroup> </Step> <Step title="Create an adapter"> Create one Viem adapter from a private key. The same adapter works across EVM chains, including Plasma: ```typescript theme={null} import { BridgeKit } from "@circle-fin/bridge-kit"; import { createViemAdapterFromPrivateKey } from "@circle-fin/adapter-viem-v2"; const kit = new BridgeKit(); const adapter = createViemAdapterFromPrivateKey({ privateKey: process.env.PRIVATE_KEY as `0x${string}`, }); ``` <Tip> For browser wallets such as MetaMask, Rabby, or Trust Wallet, use `createViemAdapterFromProvider` with your EIP-1193 provider instead of a private key. See the [Bridge Kit documentation](https://developers.circle.com/bridge-kit). </Tip> <Tip> Bridging to or from Solana? Install `@circle-fin/adapter-solana-kit` and create a Solana adapter for that side of the transfer. Keep the Viem adapter for Plasma and other EVM chains. Pass both adapters into `kit.bridge()`, for example `from: { adapter: solanaAdapter, chain: "Solana" }` and `to: { adapter, chain: "Plasma" }`. </Tip> </Step> <Step title="Bridge USDC to Plasma"> Estimate fees, then bridge. This example moves 1 USDC from Ethereum Sepolia to Plasma Testnet: ```typescript theme={null} // Optional: preview gas and protocol fees const estimate = await kit.estimate({ from: { adapter, chain: "Ethereum_Sepolia" }, to: { adapter, chain: "Plasma_Testnet" }, amount: "1.00", }); console.dir(estimate, { depth: null }); // Transfer 1.00 USDC to Plasma Testnet const result = await kit.bridge({ from: { adapter, chain: "Ethereum_Sepolia" }, to: { adapter, chain: "Plasma_Testnet" }, amount: "1.00", }); console.dir(result, { depth: null }); ``` For mainnet, swap the chain identifiers: ```typescript theme={null} const result = await kit.bridge({ from: { adapter, chain: "Ethereum" }, to: { adapter, chain: "Plasma" }, amount: "10.00", }); ``` </Step> <Step title="Monitor the transfer"> Subscribe to lifecycle events to track approval, burn, attestation, and mint: ```typescript theme={null} kit.on("*", (event) => { console.log(`[${event.method}]`, event.values); }); ``` After `kit.bridge()` resolves, inspect `result.steps` for transaction hashes and explorer URLs for each completed step. </Step> <Step title="Verify on Plasma"> 1. Open the mint step's `explorerUrl`, or search the destination transaction hash on [Plasma Explorer](https://plasmascan.to/) or [Plasma Testnet Explorer](https://testnet.plasmascan.to/). 2. Confirm native USDC arrived at your wallet on Plasma. 3. Confirm `result.state` is `success`. </Step> </Steps> ## Bridge from Plasma The same kit call works in reverse. Burn USDC on Plasma and mint it on another CCTP chain: ```typescript theme={null} const result = await kit.bridge({ from: { adapter, chain: "Plasma" }, to: { adapter, chain: "Base" }, amount: "10.00", }); ``` ## Troubleshooting ### Route Not Supported Confirm both chains are available in Bridge Kit and that you are using the correct chain identifiers (`Plasma`, `Plasma_Testnet`). Check [supported chains and domains](https://developers.circle.com/cctp/concepts/supported-chains-and-domains). ### Insufficient Balance or Gas * The source chain needs enough native USDC for the transfer amount, plus any Fast Transfer fee. * The source chain needs native gas, such as ETH, for the approval and burn transactions. * The destination Plasma wallet needs `XPL` when your adapter signs the mint transaction. ### Transaction Stuck or Failed * Confirm RPC connectivity for both chains. Prefer a private Plasma RPC from an [RPC provider](/docs/plasma-chain/tools/rpc-providers) in production. * Inspect `result.steps` to see which stage failed. Resume actionable failures with `kit.retry(result, { from: adapter, to: adapter })`. * Check network status on the [Plasma status page](https://statuspage.incident.io/plasmanetwork). # Browser Wallet Setup Source: https://docs.plasma.org/docs/guides/asset-management/browser-wallet-setup Connect a browser wallet to the Plasma Network This guide outlines how to configure browser wallets for use with the Plasma network. ## Prerequisites * MetaMask, Trust Wallet, or Rabby browser extension installed and set up. * Familiarity with browser wallet interfaces. Plasma is available across all three wallets—pick the section below that matches what you use. <Tip> Check the [Ecosystem Directory](https://app.plasma.to/ecosystem?filter=wallets) for the latest wallet integrations and connection guides. </Tip> ## Network Configuration Use the following settings when adding the Plasma Mainnet: | Parameter | Value | | ------------------ | ------------------------ | | Network name | Plasma Mainnet Beta | | New RPC URL | `https://rpc.plasma.to` | | Chain ID | `9745` | | Currency symbol | `XPL` | | Block explorer URL | `https://plasmascan.to/` | Use the following settings when adding the Plasma Testnet: | Parameter | Value | | ------------------ | ------------------------------- | | Network name | Plasma Testnet | | New RPC URL | `https://testnet-rpc.plasma.to` | | Chain ID | `9746` | | Currency symbol | `XPL` | | Block explorer URL | `https://testnet.plasmascan.to` | <Tip> You can use the public RPC endpoint or get a private endpoint through one of our [RPC providers](../../plasma-chain/tools/rpc-providers). </Tip> ## Add Plasma to Your Browser Wallet 1. Open your wallet extension (MetaMask, Trust Wallet, or Rabby). 2. Open the network selector (usually labelled **Add network**, **Custom network**, or **Manage networks**). 3. Choose the option to add a custom EVM network. 4. Enter the Plasma Mainnet or Testnet parameters from the tables above. 5. Save the network and switch to it when you are ready to interact with Plasma. ### Wallet-specific notes * **MetaMask**: Select Add network → Add a network manually * **Trust Wallet**: Use Manage Networks → Add Custom Network * **Rabby**: Select Add chain → Add manually Confirm the selected network shows **Plasma Mainnet/Testnet** after saving. ### Verify Connection * Plasma Mainnet/Testnet appears in the network selector * Your balance shows `0 XPL` if no tokens received * Block explorer link opens [Plasma Explorer](https://plasmascan.to/) ## Troubleshooting ### Connection Issues * Confirm RPC URL is correct * If using QuickNode or another provider, verify endpoint status * Restart browser and wallet extensions if needed ### Transaction Failures * Ensure sufficient `XPL` for gas fees * Confirm Chain ID is correct * Use [Status Page](https://statuspage.incident.io/plasmanetwork) to verify network activity # Quickstart Source: https://docs.plasma.org/docs/guides/development/quickstart Set up your environment and deploy a contract to Plasma Testnet with Hardhat or Foundry. This guide covers environment setup, contract deployment, and interaction with Plasma’s EVM compatible testnet using Hardhat. It assumes basic familiarity with Ethereum tooling and smart contract development. ## Prerequisites * Node.js 20+ * Basic knowledge of Ethereum development * Browser wallet ## Environment Setup Use Hardhat to build and deploy contracts. ### Hardhat Setup 1. Create a new project directory and initialize: ```shell theme={null} mkdir my-plasma-project cd my-plasma-project npm init -y npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox npm install dotenv npx hardhat init ``` 2. Follow the steps to create a JavaScript project. Save the project wherever you want. You likely don't need a `.gitignore` file for this quickstart. 3. Configure `hardhat.config.js` for Plasma testnet: ```javascript theme={null} require("@nomicfoundation/hardhat-toolbox"); require("dotenv").config(); /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { solidity: "0.8.28", networks: { plasmaTestnet: { url: process.env.RPC_ENDPOINT, chainId: 9746, accounts: [process.env.PRIVATE_KEY] // We'll set this up next. } } }; ``` ## Wallet & Testnet Setup ### Add Plasma Testnet to Your Browser Wallet 1. Open your browser wallet (MetaMask, Trust Wallet, or Rabby) and click the network selector. 2. Select the option to add a custom network (for example, **Add Network**, **Add manually**, or **Add custom network**). 3. Enter these details: * **Network Name**: Plasma Testnet * **New RPC URL**: `https://testnet-rpc.plasma.to` * **Chain ID**: `9746` * **Currency Symbol**: `XPL` * **Block Explorer URL**: `https://testnet.plasmascan.to` 4. Save the network and switch to the Plasma Testnet in your wallet. ### Get Testnet Tokens 1. Copy your wallet address from your browser wallet. 2. Visit [openfaucet.org](https://openfaucet.org/). 3. Enter your address and request testnet tokens. 4. Wait for the transaction to complete (it should appear in your wallet within a few seconds). ### Set Up Environment Variables 1. Export your account's private key using your browser wallet's account settings. 2. Create a `.env` file in your project root: ```shell theme={null} PRIVATE_KEY=your_private_key_here RPC_ENDPOINT=https://testnet-rpc.plasma.to ``` <Warning> Never commit your private key or mnemonic to version control. Add `.env` to your `.gitignore` file. </Warning> ## Write a Simple Smart Contract 1. Create a basic storage contract `contracts/SimpleStorage.sol`: ```solidity theme={null} // SPDX-License-Identifier: MIT pragma solidity ^0.8.28; contract SimpleStorage { string private storedData; event DataStored(string data); constructor() { storedData = "Hello, Plasma!"; } function setData(string memory data) public { storedData = data; emit DataStored(data); } function getData() public view returns (string memory) { return storedData; } } ``` 2. Compile the contract: ```shell theme={null} npx hardhat compile ``` This should output something like: ```plaintext theme={null} Downloading compiler 0.8.28 Downloading compiler 0.8.28 Compiled 2 Solidity files successfully (evm target: paris). ``` ## Testing 1. Create a test script `test/SimpleStorage.js`: ```javascript theme={null} const { expect } = require("chai"); describe("SimpleStorage", function () { let simpleStorage; beforeEach(async function () { const SimpleStorage = await ethers.getContractFactory("SimpleStorage"); simpleStorage = await SimpleStorage.deploy(); await simpleStorage.waitForDeployment(); }); it("Should return the initial greeting", async function () { expect(await simpleStorage.getData()).to.equal("Hello, Plasma!"); }); it("Should update the stored data", async function () { await simpleStorage.setData("Updated data"); expect(await simpleStorage.getData()).to.equal("Updated data"); }); }); ``` 2. Run the tests: ```shell theme={null} npx hardhat test ``` This should output something like: ```plaintext theme={null} Lock Deployment ✔ Should set the right unlockTime (454ms) ✔ Should set the right owner ✔ Should receive and store the funds to lock ✔ Should fail if the unlockTime is not in the future Withdrawals Validations ✔ Should revert with the right error if called too soon ✔ Should revert with the right error if called from another account ✔ Shouldn't fail if the unlockTime has arrived and the owner calls it Events ✔ Should emit an event on withdrawals Transfers ✔ Should transfer the funds to the owner SimpleStorage ✔ Should return the initial greeting ✔ Should update the stored data 11 passing (541ms) ``` ### Deploy to Plasma Testnet 1. First, make a `scripts` directory: ```shell theme={null} mkdir scripts ``` 2. Next, create a script to deploy the contract `scripts/deploy.js`: ```javascript theme={null} async function main() { const SimpleStorage = await ethers.getContractFactory("SimpleStorage"); console.log("Deploying SimpleStorage..."); const simpleStorage = await SimpleStorage.deploy(); await simpleStorage.waitForDeployment(); const address = await simpleStorage.getAddress(); console.log("SimpleStorage deployed to:", address); } main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1); }); ``` 3. Deploy the contract: ```shell theme={null} npx hardhat run scripts/deploy.js --network plasmaTestnet ``` This should output something like: ```plaintext theme={null} Deploying SimpleStorage... SimpleStorage deployed to: 0xaa4FB2A8eD6953A4e57b8097BAf048d7919e6262 ``` 4. Make a note of the `deployed to:` address. This is the address of your contract on the Plasma testnet. ## Verify Deployment 1. Copy the contract address. 2. Visit the [Plasma testnet explorer](https://testnet.plasmascan.to/). 3. Search for your contract address to view the deployment transaction. ## Troubleshooting | Issue | Resolution | | :------------------------ | :----------------------------------------------------------------- | | Gas estimation errors | Ensure wallet has sufficient XPL | | Network connection errors | Verify RPC URL and testnet availability | | Private key errors | Ensure `.env` is configured correctly (no `0x` prefix if required) | | Explorer delay | Wait a few minutes; explorer may be syncing | # Set Up Dev Environment Source: https://docs.plasma.org/docs/guides/development/set-up-a-dev-environment Configure your tools and connect to Plasma for smart contract development. Plasma is fully EVM compatible, allowing you to use standard Ethereum tooling while benefiting from features optimized for stablecoin-native applications. To learn more about Plasma's architecture details, see the [Architecture Overview](../../plasma-chain/architecture/system-overview.mdx) section. ## Verify RPC Connectivity Public RPC endpoints are available for both Plasma networks: ```shell theme={null} # Mainnet (recommended) curl --location https://rpc.plasma.to --header 'Content-Type: application/json' --data '{"method":"eth_blockNumber","params":[],"id":1,"jsonrpc":"2.0"}' # Testnet (optional) curl --location https://testnet-rpc.plasma.to --header 'Content-Type: application/json' --data '{"method":"eth_blockNumber","params":[],"id":1,"jsonrpc":"2.0"}' ``` Mainnet responses will look similar to: ```output theme={null} {"jsonrpc":"2.0","id":1,"result":"0x11180f"} ``` <Tip> Public endpoints are rate-limited. For production use or high-frequency requests, consider using a [partner RPC provider](../../plasma-chain/tools/rpc-providers). </Tip> ## Configuring Development Tools Below are examples for [Hardhat](#hardhat) and [Truffle](#truffle-configuration): ### Hardhat Create or modify your `hardhat.config.js` file to include both Plasma networks: ```javascript theme={null} require("dotenv").config(); module.exports = { networks: { plasmaMainnet: { url: process.env.MAINNET_RPC_ENDPOINT || "https://rpc.plasma.to", chainId: 9745, accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [] }, // Optional: enable the testnet for staging. plasmaTestnet: { url: process.env.TESTNET_RPC_ENDPOINT || "https://testnet-rpc.plasma.to", chainId: 9746, accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [] } }, solidity: { version: "0.8.28", settings: { optimizer: { enabled: true, runs: 200 } } } }; ``` ### Truffle Configuration If you're using Truffle, update your `truffle-config.js`: ```javascript theme={null} const HDWalletProvider = require('@truffle/hdwallet-provider'); module.exports = { networks: { plasmaMainnet: { provider: () => new HDWalletProvider( "<YOUR_MNEMONIC_HERE>", process.env.MAINNET_RPC_ENDPOINT || "https://rpc.plasma.to", ), network_id: 9745, gas: 5500000, }, plasmaTestnet: { provider: () => new HDWalletProvider( "<YOUR_MNEMONIC_HERE>", process.env.TESTNET_RPC_ENDPOINT || "https://testnet-rpc.plasma.to", ), network_id: 9746, gas: 5500000, } }, compilers: { solc: { version: "0.8.28", settings: { optimizer: { enabled: true, runs: 200 } } } } }; ``` ## Wallet Integration ### Web3.js Integration ```javascript theme={null} const Web3 = require('web3'); const web3 = new Web3(process.env.MAINNET_RPC_ENDPOINT || 'https://rpc.plasma.to'); // Check connection web3.eth.getBlockNumber() .then(blockNumber => console.log('Connected to Plasma node. Current block:', blockNumber)) .catch(error => console.error('Connection error:', error)); ``` ### Ethers.js Integration ```javascript theme={null} const { ethers } = require('ethers'); const provider = new ethers.JsonRpcProvider('https://testnet-rpc.plasma.to'); // Check connection provider.getBlockNumber() .then(blockNumber => console.log('Connected to Plasma node. Current block:', blockNumber)) .catch(error => console.error('Connection error:', error)); ``` ## Validate Setup Create a simple script to verify your development environment is correctly set up: ```javascript theme={null} const { ethers } = require('ethers'); require('dotenv').config(); async function testSetup() { // Connect to the Plasma node. const provider = new ethers.JsonRpcProvider('https://testnet-rpc.plasma.to'); // Get network information. const network = await provider.getNetwork(); console.log('Connected to network:', network); // Get current block number. const blockNumber = await provider.getBlockNumber(); console.log('Current block number:', blockNumber); // Optionally, print address and balance if PRIVATE_KEY is set. if (process.env.PRIVATE_KEY) { const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider); const balance = await provider.getBalance(wallet.address); console.log('Account address:', wallet.address); console.log('Balance:', ethers.formatEther(balance), 'XPL'); } else { console.log('Set PRIVATE_KEY to also print address and balance.'); } } testSetup() .then(() => console.log('Setup test completed successfully')) .catch(error => console.error('Setup test failed:', error)); ``` ## Troubleshooting | Issue | Action | | :------------------------- | :---------------------------------------------------------- | | **Connection refused** | Confirm RPC endpoint is correct and accessible | | **Gas estimation failed** | Ensure wallet has sufficient XPL | | **Solidity version error** | Update config to match compiler version supported by Plasma | | **Transaction fails** | Verify RPC URL and correct chain ID | # Mainnet Details Source: https://docs.plasma.org/docs/guides/network-configuration/mainnet-details Configuration reference for connecting to the Plasma Mainnet. ## Network Parameters | Parameter | Value | Description | | ----------------- | --------------------------------- | ---------------------------------------------- | | Network Name | `Plasma Mainnet Beta` | Public mainnet beta environment for Plasma. | | Public RPC | `https://rpc.plasma.to` | Public, rate-limited RPC endpoint. | | Chain ID | `9745` | Unique identi
프로젝트로 돌아가기