Mantle 백서

Mantle

원문

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

nect.com/appkit/next/core/hooks) that AppKit provides. Open the app/page.tsx file and remove the existing boilerplate code, and then replace it with the code snippet given below. ```typescript "use client"; import { useAccount } from "wagmi"; export default function Home() { const { isConnected } = useAccount(); return ( <main className="min-h-screen px-8 py-0 pb-12 flex-1 flex flex-col items-center"> <header className="w-full py-4 flex justify-between items-center"> <div className="flex items-center"> <img src="/walletconnect.png" alt="logo" className="w-10 h-10 mr-2" /> <div className="hidden sm:inline text-xl font-bold">Reown - AppKit + Mantle</div> </div> </header> <h2 className="my-8 text-2xl font-bold leading-snug text-center">Examples</h2> <div className="max-w-4xl"> <div className="grid bg-white border border-gray-200 rounded-lg overflow-hidden shadow-sm"> <h3 className="text-sm font-semibold bg-gray-100 p-2 text-center">Connect your wallet</h3> <div className="flex justify-center items-center p-4"> <w3m-button /> </div> </div> <br></br> {isConnected && ( <div className="grid bg-white border border-gray-200 rounded-lg overflow-hidden shadow-sm"> <h3 className="text-sm font-semibold bg-gray-100 p-2 text-center">Network selection button</h3> <div className="flex justify-center items-center p-4"> <w3m-network-button /> </div> </div> )} </div> </main> ); } ``` The code above uses the AppKit configuration to provide two buttons: one for users to connect their wallet to the app, and another to allow users to switch networks. You can now run the app and test it out. In order to do so, run the command given below. ```bash npm run dev ``` ### Conclusion And that’s it! You have now learned how to create a simple app using AppKit that allows users to connect their wallet and interact with the Mantle network. **Reown AppKit** is a powerful solution for developers looking to integrate wallet connections and other Web3 functionalities into their apps on any EVM chain.\ In just a few simple steps, you can provide your users with seamless wallet access, one-click authentication, social logins, and notifications—streamlining their experience while enabling advanced features like on-ramp functionality and smart accounts.\ By following this guide, you'll quickly get up and running with Reown’s AppKit, enhancing your app’s user experience and interaction with blockchain technology. You can view the complete code repository [here](https://github.com/rohit-710/reown-appkit-evm). # Multisig Wallet ## Safe{Wallet}[​](https://docs-v2.mantle.xyz/devs/dev-guides/tools/wallet/multisig#safewallet) <a href="#safewallet" id="safewallet"></a> [Safe{Wallet}](https://multisig.mantle.xyz/) is the most trusted decentralized custody protocol and collective asset management platform. <details> <summary><code>What's new</code></summary> Mantle use several Safe services to support the multisig wallet, this is the changelog for these services: * **Safe UI \[1.36.4]** * changelogs * Critical Updates * Improved handling of pending transactions. * Disabled execute button. * Added speed-up options. * Redesigned approval editor. * Added ENS resolution for Safe addresses in the sidebar. * New Features and Functionalities * Display balances in Safe list. * Added activity app banner on dashboard. * Introduced speed-up pending transactions feature toggle. * Displayed deprecation banner for social logins on all pages. * Enabled transaction deletion with UI updates. * Automatic approval for verified WalletConnect sessions. * Apps * Added Token Approval Manager, which allows you to keep track of safe ERC20 token approvals and control them (edit/revoke) in batched transactions. * Fixes and Improvements * Always fetch message information when signing. * Corrected fee tooltip text. * Set default owner and improved counterfactual transactions when creating a Safe. * Various UI fixes: dark mode, button overlaps, transaction status indicators. * **Safe transaction service \[v5.0.0]** * **changlogs** * Critical Updates: * Removed deprecated endpoints (e.g., balances/usd). * Enhanced UserOperation: * Removed POST method. * Added safeOperation model. * New endpoint for UserOperations with indexing for failed/reverted ones. * Validations for init\_code, nonce, valid\_after, and valid\_until. * Improved decoding error handling and transaction hash logging. * New Features and Functionalities: * Integrated Swagger tags for better API documentation. * Added endpoint for safe deployments. * Refactored delegate endpoint signatures to use EIP712. * Processed ENS names in token list address fields. * Minor Updates and Dependency Changes * **Safe Config Service \[v2.80.0]** * **changlogs** * Critical Updates: * Renamed SafeApp visible field to listed. * Added prices provider configuration. * New Features and Functionalities: * Introduced optional "onlyListed" query param for SafeApps filtering. * Minor Updates and Dependency Updates * **Safe Event Service \[v0.12.0]** * **changlogs** * Critical Updates: * Updated to Node.js v20. * Rolled back TypeORM to v0.3.19. * New Features and Functionalities: * Added JSON format for event logs. * Introduced asynchronous datasource creation. * Minor Updates and Dependency Updates </details> <br> # How-to Guides # How to Deploy Smart Contracts # Use Remix to Deploy Smart Contracts [Remix's web-based IDE](https://remix.ethereum.org/) supports writing, testing, debugging, and deploying smart contracts written in Solidity, Yul, and other popular contract development languages. ## Prerequisite[​](https://docs-v2.mantle.xyz/devs/dev-guides/how-to/deploy/remix#prerequisite) <a href="#prerequisite" id="prerequisite"></a> * Wallet with sufficient balance * The [right information](/network/for-developers/quick-access#network-details) on the network {% hint style="info" %} If you want to get some testnet tokens, please refer to the [Faucet page](/network/for-users/how-to-guides/fetching-test-tokens) {% endhint %} ## Deploy your contract[​](https://docs-v2.mantle.xyz/devs/dev-guides/how-to/deploy/remix#deploy-your-contract) <a href="#deploy-your-contract" id="deploy-your-contract"></a> {% stepper %} {% step %} ### Start by opening Remix in your browser. Create a new `.sol` file under the **"Contracts"** folder and start writing your code. This tutorial will use the initial example contract `Storage.sol`. {% endstep %} {% step %} ### Once ready, you can proceed with compiling the contract by either clicking the **Compile** button on the top, or clicking on the blue button that says **"Compile \<file\_name>"**, which you can access by navigating to the **"Solidity Compiler"** tab by clicking on the left. <img src="https://3885809119-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQliZlRNwHhmzesDU1Ksq%2Fuploads%2FOmnGd1wlX6XOvi7GCPQE%2Fimage.png?alt=media&amp;token=b42de9e2-e010-4f95-bbd4-cdb2e88b5956" alt="" data-size="original"> {% endstep %} {% step %} ### If the compilation was successful (A green checkmark will appear on the left side), you'll be able to deploy the contract from the **"Deploy & run transactions"** tab, which can be accessed by clicking on the left. ![](https://docs-v2.mantle.xyz/assets/images/remix-2-f6db30a606a1a715ab07e0e3f18bedb8.png) {% endstep %} {% step %} ### Switch to Mantle Network in your MetaMask wallet and select **"Injected Provider - MetaMask"** from the **"Environment"** dropdown list and select a wallet account that will be used to pay the gas fees. Remix will automatically connect to the network that the wallet is currently connected to. Click on the **Deploy** button to send the deploy transaction. ![](https://docs-v2.mantle.xyz/assets/images/remix-3-1206181ef7742e278ee23c494c3e69a6.png) {% endstep %} {% step %} ### Upon successful deployment, you'll be able to see the transaction and contract info in the terminal at the bottom, like so: ![](https://docs-v2.mantle.xyz/assets/images/remix-4-04e1ed4b15f163c32d2853c9fe5f2219.png) {% endstep %} {% endstepper %} Now you can head over to [Mantle blockchain explorer](https://mantlescan.xyz/) to check the contract details. # Use Hardhat to Deploy Smart Contracts [Hardhat](https://hardhat.org/hardhat-runner/docs/getting-started#overview) is a smart contract development environment that comes with tools that can be used to compile, debug, and deploy Solidity smart contracts and dApps on Ethereum and other EVM-compatible chains like Mantle Network. ## Prerequisite[​](https://docs-v2.mantle.xyz/devs/dev-guides/how-to/deploy/hardhat#prerequisite) <a href="#prerequisite" id="prerequisite"></a> * Wallet with sufficient balance * The [right information](/network/for-developers/quick-access#network-details) on the network {% hint style="info" %} If you want to get some testnet tokens, please refer to the [Faucet page](/network/for-users/how-to-guides/fetching-test-tokens) {% endhint %} ## Create a project and configure[​](https://docs-v2.mantle.xyz/devs/dev-guides/how-to/deploy/hardhat#create-a-project-and-configure) <a href="#create-a-project-and-configure" id="create-a-project-and-configure"></a> 1. Begin by [creating a new Hardhat project](https://hardhat.org/hardhat-runner/docs/guides/project-setup) and installing the necessary dependencies. In this tutorial, we will use the `dotenv` library to set up your wallet private key. ```sh npm install dotenv --save-dev ``` 2. Create a `.env` file and set your wallet private key inside it. ```sh touch .env echo "ACCOUNT_PRIVATE_KEY=<your-wallet-private-key>" >> .env ``` 3. Once the wallet private key is ready, configure the `hardhat.config.ts` file to include Mantle Network's settings. ```javascript import { HardhatUserConfig } from "hardhat/config"; import '@nomicfoundation/hardhat-toolbox'; import * as dotenv from 'dotenv'; dotenv.config(); const config: HardhatUserConfig = { solidity: "0.8.19", // solidity version defaultNetwork: "mantleSepolia", // chosen by default when network isn't specified while running Hardhat networks: { mantle: { url: "https://rpc.mantle.xyz", //mainnet accounts: [process.env.ACCOUNT_PRIVATE_KEY ?? ""], }, mantleSepolia: { url: "https://rpc.sepolia.mantle.xyz", // Sepolia Testnet accounts: [process.env.ACCOUNT_PRIVATE_KEY ?? ""], }, }, }; export default config; ``` In this configuration file, three networks are set up for deployment: **Mantle Mainnet**, and **Mantle Sepolia Testnet** (as default). ## Compile and Deploy[​](https://docs-v2.mantle.xyz/devs/dev-guides/how-to/deploy/hardhat#compile-and-deploy) <a href="#compile-and-deploy" id="compile-and-deploy"></a> {% hint style="info" %} If you need to verify your contracts, we strongly recommend that you skip directly to the [‘Use Hardhat to Verify Smart Contracts’](/network/for-developers/how-to-guides/how-to-verify-smart-contracts/use-hardhat-to-verify-smart-contracts) section to avoid double deploying contracts when verifying them! {% endhint %} 1. With your contracts prepared in the **"Contracts"** directory within your Hardhat project, compile them using the following command. ```sh npx hardhat compile ``` **Sample Outputs** ```sh Generating typings for: 1 artifacts in dir: typechain-types for target: ethers-v6 Successfully generated 6 typings! Compiled 1 Solidity file successfully (evm target: paris). ``` 2. Deploy your contracts to a chosen network using the following command. You can omit the `--network` field to deploy on the default network specified in `hardhat.config.ts` (Mantle Sepolia Testnet in this tutorial). ```sh npx hardhat ignition deploy ./ignition/modules/<Your-Contract>.ts --network mantleSepolia ``` You will receive a response confirming successful contract deployment, and the address (e.g., `0xDe33e86f2Da37E01e0eCb870bd1CE91a71bB6bF4`) is the deployed contract's address. Now you can head over to [Mantle blockchain explorer](https://mantlescan.xyz/) to check the contract details. # Use Foundry to Deploy Smart Contracts [Foundry](https://github.com/foundry-rs/foundry#readme) is a fast, portable, and modular toolkit for EVM application development written in Rust. The two main components that you'll generally be using for smart contract development are: * [Forge](https://github.com/foundry-rs/foundry/tree/master/crates/forge#readme): used to compile, test, and deploy contracts * [Cast](https://github.com/foundry-rs/foundry/tree/master/crates/cast#readme): used to make RPC calls to interact with a network ### Prerequisite[​](https://docs-v2.mantle.xyz/devs/dev-guides/how-to/deploy/foundry#prerequisite) <a href="#prerequisite" id="prerequisite"></a> * Wallet with sufficient balance * The [right information](/network/for-developers/quick-access#network-details) on the network {% hint style="info" %} If you want to get some testnet tokens, please refer to the [Faucet page](/network/for-users/how-to-guides/fetching-test-tokens) {% endhint %} ## Install Foundry[​](https://docs-v2.mantle.xyz/devs/dev-guides/how-to/deploy/foundry#install-foundry) <a href="#install-foundry" id="install-foundry"></a> Foundryup is the Foundry toolchain installer. Open your terminal and run the following command: ```javascript curl -L https://foundry.paradigm.xyz | bash ``` For more installation instructions, check [here](https://book.getfoundry.sh/getting-started/installation#installation). ## Create a project[​](https://docs-v2.mantle.xyz/devs/dev-guides/how-to/deploy/foundry#create-a-project) <a href="#create-a-project" id="create-a-project"></a> 1. Create a new Foundry project and install the necessary dependencies. ```sh forge init hello_mantle ``` 2. Please put your contract in the **src** folder. For this tutorial, we will use the existing example contract `Counter.sol`. Then use the following command to compile a smart contract. ```sh forge build ``` **Sample Outputs** ```sh [⠒] Compiling... [⠒] Compiling 24 files with 0.8.15 [⠢] Solc 0.8.15 finished in 2.52sCompiler run successful! [⠆] Solc 0.8.15 finished in 2.52s ``` ## Deploy your contract[​](https://docs-v2.mantle.xyz/devs/dev-guides/how-to/deploy/foundry#deploy-your-contract) <a href="#deploy-your-contract" id="deploy-your-contract"></a> Upon successful compilation, use the following command to deploy a smart contract (replace \<your-private-key> on the command line with your wallet private key). ```sh forge create --rpc-url <mantle_rpc_url> --private-key <your-private-key> src/Counter.sol:Counter --legacy ``` ### **Sample Outputs** ```sh [⠢] Compiling...No files changed, compilation skipped [⠆] Compiling... Deployer: 0xE1F10AfE71FF3397A85aAce99D42Db6661E02bB9 Deployed to: 0x38fa66D97b98607636F88C98aE59e08C04D2FEB6 Transaction hash: 0x308fb9f1824ca85e34ed9d1df94aa3f1d9dbcc02b3d01a130ac4b7cf1e1a77fb ``` Here `0x38fa66D97b98607636F88C98aE59e08C04D2FEB6` is the address of the deployed contract, which you can view via the [Mantle blockchain explorer](https://mantlescan.xyz/). # Use Thirdweb to Deploy Smart Contracts [Thirdweb](https://portal.thirdweb.com/) is a complete web3 development framework that provides everything you need to connect your apps and games to decentralized networks like Mantle Network. ## Prerequisite[​](https://docs-v2.mantle.xyz/devs/dev-guides/how-to/deploy/thirdweb#prerequisite) <a href="#prerequisite" id="prerequisite"></a> * Wallet with sufficient balance * The [right information](/network/for-developers/quick-access#network-details) on the network {% hint style="info" %} If you want to get some testnet tokens, please refer to the [Faucet page](/network/for-users/how-to-guides/fetching-test-tokens) {% endhint %} ## Install Thirdweb CLI[​](https://docs-v2.mantle.xyz/devs/dev-guides/how-to/deploy/thirdweb#install-thirdweb-cli) <a href="#install-thirdweb-cli" id="install-thirdweb-cli"></a> You can install the Thirdweb CLI globally on your machine using npm by running the following command. ```sh npm i -g @thirdweb-dev/cli ``` ## Create a project[​](https://docs-v2.mantle.xyz/devs/dev-guides/how-to/deploy/thirdweb#create-a-project) <a href="#create-a-project" id="create-a-project"></a> 1. Start by creating a new project by running: ```sh npx thirdweb create contract ``` 2. Input your preferences for the command line prompts, such like: ```sh ✔ What is your project named? … mantle-test ✔ What framework do you want to use? › Hardhat ✔ What will be the name of your new smart contract? … MyContract ✔ What type of contract do you want to start from? › Empty Contract ``` Here we have chosen to use the hardhat framework and generated an empty contract project. 3. Place the contracts you want to deploy in the contracts folder, for example, let's deploy a `Storage` contract. ```solidity // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.8.2 <0.9.0; /** * @title Storage * @dev Store & retrieve value in a variable * @custom:dev-run-script ./scripts/deploy_with_ethers.ts */ contract Storage { uint256 number; /** * @dev Store value in variable * @param num value to store */ function store(uint256 num) public { number = num; } /** * @dev Return value * @return value of 'number' */ function retrieve() public view returns (uint256){ return number; } } ``` ## Deploy your contract[​](https://docs-v2.mantle.xyz/devs/dev-guides/how-to/deploy/thirdweb#deploy-your-contract) <a href="#deploy-your-contract" id="deploy-your-contract"></a> The command `deploy` allows you to deploy a smart contract to Mantle Network without configuring RPC URLs, exposing your private keys, writing scripts, and another additional setup such as verifying your contract. 1. To deploy your smart contract using deploy, navigate to the root directory of your project and run: ```sh npx thirdweb deploy ``` **Sample Outputs** ```sh ✔ Detected project type: hardhat ✔ Compilation successful ✔ Processing contract: "Storage" ✔ Upload successful ✔ Open this link to deploy your contracts: https://thirdweb.com/contracts/deploy/QmPQJLQaEHVRD55hUSvkraSb74ZzBqwCcmFGGCXX5TLmx6 ``` 2. Open the link and connect your wallet, select the network you need to deploy, and click the **Deploy Now** button to complete the deployment! <figure><img src="https://docs-v2.mantle.xyz/assets/images/thirdweb-1-a374d0a39cc9e4863fad2b94c93e9506.png" alt=""><figcaption></figcaption></figure> # How to Verify Smart Contracts # Use Hardhat to Verify Smart Contracts To verify your contracts using Hardhat, you'll need an [Etherscan API key](https://docs.etherscan.io/getting-started/viewing-api-usage-statistics) and custom network configuration in your `hardhat.config.ts` file. ## Configure[​](https://docs-v2.mantle.xyz/devs/dev-guides/how-to/verify/hardhat#configure) <a href="#configure" id="configure"></a> 1. Add your [Mantlescan API key](https://mantlescan.xyz/myapikey) to the `.env` file. ```sh ... API_KEY=xxx ``` 2. Modify the `hardhat.config.ts` configuration to include `customChains` before moving forward. ```javascript import {HardhatUserConfig} from 'hardhat/config'; import '@nomicfoundation/hardhat-toolbox'; import * as dotenv from 'dotenv'; dotenv.config(); const config: HardhatUserConfig = { solidity: '0.8.19', // solidity version defaultNetwork: 'mantleSepolia', // chosen by default when network isn't specified while running Hardhat networks: { mantle: { url: 'https://rpc.mantle.xyz', //mainnet accounts: [process.env.ACCOUNT_PRIVATE_KEY ?? ''], }, mantleSepolia: { url: 'https://rpc.sepolia.mantle.xyz', // Sepolia Testnet accounts: [process.env.ACCOUNT_PRIVATE_KEY ?? ''], gasPrice: 20000000, }, }, etherscan: { apiKey: process.env.API_KEY, customChains: [ { network: 'mantle', chainId: 5000, urls: { apiURL: 'https://api.mantlescan.xyz/api', browserURL: 'https://mantlescan.xyz', }, }, { network: 'm
프로젝트로 돌아가기