Mantle 백서

Mantle

원문

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

ent, there are different settings for different transaction types: * **legacy transactions** If you are using legacy type transactions, you can use the following command for contract deployment, e.g. ``` forge script --legacy script/Deploy.s.sol:DeploySiege --sig "run()" --rpc-url <mantle_rpc_url> --broadcast ``` * **EIP-1559 transactions** If you are using EIP-1559 type transactions, you need to set the [`--with-gas-price`](https://book.getfoundry.sh/reference/forge/forge-script#options) parameter to the network minimum basefee, using the following command to deploy the contract, e.g. ``` forge script script/Deploy.s.sol:DeploySiege --sig "run()" --with-gas-price 20000000 --rpc-url <mantle_rpc_url> --broadcast ``` {% endtab %} {% tab title="Use forge create" %} When you use `forge create` for contract deployment, there are different settings for different transaction types: * **legacy transactions (recommended)** If you are using legacy type transactions, you don't need to do any additional setup, use the following commands for contract deployment, e.g. ```sh forge create --legacy --rpc-url <mantle_rpc_url> ./script/StorageTest.sol:Storage --private-key <private_key> ``` * **EIP-1559 transactions** If using EIP-1559 type transactions, you need to set [`--priority-gas-price`](https://book.getfoundry.sh/reference/forge/forge-script#options) to `0`, [`--gas-price`](https://book.getfoundry.sh/reference/forge/forge-script#options) to `20000000` (current network minimum basefee) [`--gas-limit`](https://book.getfoundry.sh/reference/forge/forge-script#options) is `40000000000` and the contract is deployed using the following command, e.g. ```sh forge create --rpc-url <mantle_rpc_url> ./script/StorageTest.sol:Storage --private-key <private_key> --priority-gas-price 0 --gas-price 20000000 --gas-limit 40000000000 ``` {% endtab %} {% endtabs %} # Common Use Cases # Moving Assets and Data The process of moving assets or data between two blockchains is generally referred to as 'bridging'. Since Mantle network is a separate Layer 2 (L2) blockchain system, apps and wallets moving assets or any another arbitrary form of data between Ethereum and Mantle can use our official bridge to achieve that. ## Sending Assets[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/move-assets#sending-assets) <a href="#sending-assets" id="sending-assets"></a> The [Mantle Bridge](https://bridge.mantle.xyz/) enables all functionality necessary for the most common use case, i.e., moving tokens between Mantle network and Ethereum. It also allows you to easily create L2 representations of existing tokens on Ethereum. ## Sending Data[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/move-assets#sending-data) <a href="#sending-data" id="sending-data"></a> If you need to send arbitrary data between Ethereum & Mantle network, you can do so by having a contract on Ethereum trigger a contract function on Mantle and vice versa. The [Mantle Bridge](https://bridge.mantle.xyz/) has a simple API for triggering a cross-chain function call. ## How does it work?[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/move-assets#how-does-it-work) <a href="#how-does-it-work" id="how-does-it-work"></a> The standard Mantle bridge is essentially a set of smart contracts. The two main contracts that implement the ERC-20 asset bridging mechanism are [`L2StandardBridge`](https://github.com/mantlenetworkio/mantle-v2/blob/develop/packages/contracts-bedrock/contracts/L2/L2StandardBridge.sol) on Mantle network, and [`L1StandardBridge`](https://github.com/mantlenetworkio/mantle-v2/blob/develop/packages/contracts-bedrock/contracts/L1/L1StandardBridge.sol) on Ethereum. Deposit or withdrawal transactions sent to the bridge by a wallet on L2 or L1 trigger specific methods in the standard bridge contracts. For instance, when a wallet sends a deposit request for `10 $MNT` on L1, these tokens get locked on L1 in the bridge contract, and the matching amount of `10 $MNT` is minted on L2 and transferred to the wallet. In case a wallet makes a withdrawal of `10 $MNT` on L2, these tokens are burned and the matching amount of `10 $MNT` tokens locked on L1 get released and transferred to the wallet. You can connect your wallet to the [Mantle Bridge](https://bridge.mantle.xyz/) to make simple deposits and withdrawals directly. However, if you're looking to use the bridge API instead, refer to the [API page](/network/for-developers/resources-and-tooling/mantle-api) for more information and tutorials on how to call the appropriate SDK methods to bridge the various kinds of tokens that are currently supported. ## Using the Official Mantle Bridge[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/move-assets#using-the-official-mantle-bridge) <a href="#using-the-official-mantle-bridge" id="using-the-official-mantle-bridge"></a> To move your `$MNT` tokens/Ether/other ERC-20 tokens between the Mantle and Ethereum chain, visit the [Mantle Bridge](https://bridge.mantle.xyz/). Feel free to try out the testnet bridge first to get yourself acquanted with the UI. You can find the detailed steps [here](/network/for-users/how-to-guides/using-mantle-bridge). ​ # Adding Mantle Wallet Support Mantle network uses `$MNT` as a native token, and creates an EVM-like code execution environment for transaction and state processing. This means a user on Layer 2 (L2) can use `$MNT` exactly like they would `$ETH` on Ethereum, namely to pay gas fees. For this reason, there are changes to how fees are calculated on Mantle network, which you can better understand in this [section](/network/system-information/fee-mechanism). Any `$MNT` tokens collected on the L2 as transaction gas fee will be rewarded to validators or burned out on schedule. ## Connecting to Mantle[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/wallet#connecting-to-mantle) <a href="#connecting-to-mantle" id="connecting-to-mantle"></a> Mantle network shares the [Ethereum JSON-RPC API](https://eth.wiki/json-rpc/API) with almost no differences. You can choose to connect to Mantle through any of the following means: 1. Official rate-limited [public endpoint](/network/for-developers/quick-access#network-details). 2. Third-party endpoints from infrastructure [providers](/network/for-developers/resources-and-tooling/node-endpoints-and-providers). 3. Running your [own node](/network/for-node-operators/deployment-guides). ### Add Mantle Network to Metamask Quickly[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/wallet#add-mantle-network-to-metamask-quickly) <a href="#add-mantle-network-to-metamask-quickly" id="add-mantle-network-to-metamask-quickly"></a> Based on the [JSON-RPC API](https://docs.metamask.io/wallet/reference/wallet_addethereumchain/) provided by Metamask, developers can implement the ability to add Mantle Network to Metamask with a single click. {% tabs %} {% tab title="Mainnet" %} ```javascript await window.ethereum.request({ "method": "wallet_addEthereumChain", "params": [ { "blockExplorerUrls": [ "https://mantlescan.xyz/" ], "iconUrls": [ "https://drive.google.com/file/d/1qLqZu2vZSkZcKf46YERoa9cF0NfURvcc/view?usp=drive_link" ], "nativeCurrency": { "name": "MNT", "symbol": "MNT", "decimals": 18 }, "rpcUrls": [ "https://rpc.mantle.xyz" ], "chainId": "0x1388", "chainName": "Mantle" } ] }); ``` {% endtab %} {% tab title="Testnet (Sepolia)" %} ```javascript await window.ethereum.request({ "method": "wallet_addEthereumChain", "params": [ { "blockExplorerUrls": [ "https://sepolia.mantlescan.xyz/" ], "iconUrls": [ "https://drive.google.com/file/d/1qLqZu2vZSkZcKf46YERoa9cF0NfURvcc/view?usp=drive_link" ], "nativeCurrency": { "name": "MNT", "symbol": "MNT", "decimals": 18 }, "rpcUrls": [ "https://rpc.sepolia.mantle.xyz" ], "chainId": "0x138B", "chainName": "Mantle Sepolia Testnet" } ] }); ``` {% endtab %} {% endtabs %} ## Canonical Token Addresses[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/wallet#canonical-token-addresses) <a href="#canonical-token-addresses" id="canonical-token-addresses"></a> The ERC-20 contract address for a token on Mantle network may be different from the address for the same token on Ethereum. Mantle maintains [a token list](https://github.com/mantlenetworkio/mantle-token-lists/blob/main/mantle.tokenlist.json) that includes known addresses for many popular tokens. For example, looking at the`$MNT` token, the Mantle token list returns the following addresses: {% tabs %} {% tab title="Mainnet" %} | Name | ChainID | Address | | ------------------ | ------- | ------------------------------------------ | | **Ethereum** | 1 | 0x3c3a81e81dc49a522a592e7622a7e711c06bf354 | | **Mantle Network** | 5000 | 0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000 | | {% endtab %} | | | {% tab title="Testnet (Sepolia)" %} | Name | ChainID | Address | | ------------------ | ------- | ------------------------------------------ | | **Ethereum** | 1 | 0x65e37B558F64E2Be5768DB46DF22F93d85741A9E | | **Mantle Network** | 5003 | 0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000 | | {% endtab %} | | | | {% endtabs %} | | | ## Transaction Status[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/wallet#transaction-status) <a href="#transaction-status" id="transaction-status"></a> A transaction on Mantle network can be in one of these states: * **Sequencer Confirmed:** The transaction has been accepted by the sequencer on Mantle (L2) * **Confirmed On-Chain:** The transaction has been written to Ethereum (L1) If a transaction is a withdrawal, it can be in one of the following states: * **Waiting:** Confirmed on L1, but still in the challenge period * **Ready to Prove:** Transaction is ready to be proved on L1 to initiate the challenge period * **Ready for Relay:** Transaction is out of the challenge period, and can be released by submitting a relay message * **Relayed:** A withdrawal is finalized, and the token is released from the bridge You can use the [Mantle SDK](https://github.com/mantlenetworkio/mantle-v2/tree/develop/packages/sdk) to find out your transaction status. ## Transaction Fees[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/wallet#transaction-fees) <a href="#transaction-fees" id="transaction-fees"></a> Mantle network aims to be EVM-compatible, you can see a summary of the few differences between Mantle and Ethereum [here](/network/system-information/fee-mechanism). ## Estimating Total Fees[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/wallet#estimating-total-fees) <a href="#estimating-total-fees" id="estimating-total-fees"></a> The major portion of the total cost of a transaction on Mantle network comes from the cost of publishing the transaction to Ethereum. Unlike with L2 execution gas fees, users cannot specify a particular gas price or gas limit for this portion of their transaction cost when it rolls up to Ethereum. In fact, this fee is automatically deducted from the user's `$MNT` balance on Mantle when the transaction is executed. {% hint style="info" %} Mantle SDK provides an interface to get the total gas fee directly. {% endhint %} ## Sending "Max" $MNT[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/wallet#sending-max-mnt) <a href="#sending-max-mnt" id="sending-max-mnt"></a> Many wallets allow users to send the maximum amount of a token available in the user's balance. This requires the fee for this transaction to be calculated in advance, and then deducted from the user's `$MNT` balance being sent. # Adding Mantle to a CEX ## Connecting to Mantle[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/cex#connecting-to-mantle) <a href="#connecting-to-mantle" id="connecting-to-mantle"></a> Mantle network shares the [Ethereum JSON-RPC API](https://eth.wiki/json-rpc/API) with almost no differences. You can choose to connect to Mantle through any of the following means: 1. Official rate-limited [public endpoint](/network/for-developers/quick-access#network-details). 2. Third-party endpoints from infrastructure [providers](/network/for-developers/resources-and-tooling/node-endpoints-and-providers). 3. Running your [own node](/network/for-node-operators/deployment-guides). ## Fetching Token Balances[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/cex#fetching-token-balances) <a href="#fetching-token-balances" id="fetching-token-balances"></a> ### Calculating ETH/ERC-20 Balance[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/cex#calculating-etherc-20-balance) <a href="#calculating-etherc-20-balance" id="calculating-etherc-20-balance"></a> On Mantle network, the ETH balance of an account is not stored as part of the account's state, but as an ERC-20 balance at address `0xdEAddEaDdeadDEadDEADDEAddEADDEAddead1111`. The ERC-20 balance is stored in the ERC-20 contract, you can check it using the [token list](https://github.com/mantlenetworkio/mantle-token-lists/blob/main/mantle.tokenlist.json). Then you can still access it using the standard APIs. ### Calculating $MNT Balance[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/cex#calculating-mnt-balance) <a href="#calculating-mnt-balance" id="calculating-mnt-balance"></a> You can use the same methods as querying the ERC-20 balance, but note that since MNT is the native token in L2, it will disable ERC-20 methods other than querying the balance. ## Transaction Fees[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/cex#transaction-fees) <a href="#transaction-fees" id="transaction-fees"></a> Mantle network aims to be EVM-compatible, you can see a summary of the few differences between Mantle and Ethereum [here](/network/system-information/fee-mechanism). ## Deposits and Withdrawals[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/cex#deposits-and-withdrawals) <a href="#deposits-and-withdrawals" id="deposits-and-withdrawals"></a> ### Deposits and Withdrawals on Mantle[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/cex#deposits-and-withdrawals-on-mantle) <a href="#deposits-and-withdrawals-on-mantle" id="deposits-and-withdrawals-on-mantle"></a> The ERC-20 contracts on Mantle function the same way they do on Ethereum, so you can use your existing code for withdrawals and deposits. Just connect to a Mantle endpoint. ### Deposits and Withdrawals Across Chains[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/cex#deposits-and-withdrawals-across-chains) <a href="#deposits-and-withdrawals-across-chains" id="deposits-and-withdrawals-across-chains"></a> As a centralized exchange, there will be times that withdrawals of `$ETH/$MNT` token or an ERC-20 token on either Mantle network or Ethereum exceed deposits and you need to transfer assets. To do that you use a bridge or a gateway. We have a standard bridge that receives assets on Ethereum mainnet, and mints the equivalent asset on Mantle network. When a user wants to withdraw the assets back to L1, the bridge burns the asset on L2 and releases it to the user on L1. If you want to use this gateway automatically, follow this [tutorial for bridging ETH](https://mantlenetworkio.github.io/mantle-tutorial/cross-dom-bridge-eth/), or this [tutorial for bridging ERC-20 tokens](https://mantlenetworkio.github.io/mantle-tutorial/cross-dom-bridge-erc20/). Note that while L1 to L2 transactions typically take minutes, L2 to L1 transactions on the gateway require a 7 day challenge period. When an ERC-20 token does not have a Mantle equivalent you can create one. If there is no need for custom business logic, you can follow the steps in this [tutorial for bridging standard ERC-20s](https://mantlenetworkio.github.io/mantle-tutorial/standard-bridge-standard-token/). If you need to implement some kind of custom logic, see this [tutorial for bridging custom ERC-20s](https://mantlenetworkio.github.io/mantle-tutorial/standard-bridge-custom-token/). # Adding a Custom Bridge to Mantle ## Using the Standard Bridge[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/bridge#using-the-standard-bridge) <a href="#using-the-standard-bridge" id="using-the-standard-bridge"></a> We suggest considering using the [Standard Bridge](https://bridge.mantle.xyz/) first before deciding to develop a custom bridge solution. In the standard bridge when ERC-20 is deposited on layer 1 (L1) and transferred to the bridge contract, it remains "locked" there while the equivalent amount is minted in the layer 2 (L2) token. For withdrawals the opposite happens, the L2 token amount is burned then the same amount of L1 tokens is transferred to the recipient. This fund can be released after the challenge period. This implementation satisfies a wide range of requirements. ## Building a Custom Bridge[​](https://docs-v2.mantle.xyz/devs/dev-guides/common/bridge#building-a-custom-bridge) <a href="#building-a-custom-bridge" id="building-a-custom-bridge"></a> When the Mantle Standard bridge does not satisfy your requirements for bridging assets or data, you can deploy your custom bridge solution utilizing the same cross-domain infrastructure as the Standard bridge. For details on how cross-domain messaging works, see the [Bridging basics article](https://mantlenetworkio.github.io/mantle-tutorial/cross-dom-comm/), and also the [tutorial on depositing and withdrawing ERC-20 tokens between L1 and L2](https://mantlenetworkio.github.io/mantle-tutorial/cross-dom-bridge-erc20/). Some reasons why the standard bridge might not work for you is for example when you cannot limit the L2 token mint and burn functions to the bridge alone (something we require for security). Also, certain custom bridges implement their own logic for managing the token supply which requires custom logic. Another case might be when you are bridging non-ERC-20 tokens (e.g. NFTs). Yet another case is when you are pooling deposits for cheaper transfers to L2. Note that when you are building a custom bridge for ERC-20 tokens and planning to add these to the Mantle token list, we have specific requirements for the bridge contracts. These have to implement the IL1ERC20Bridge interface in the L1 bridge contract and IL2ERC20Bridge interface in the L2 bridge contract. This ensures the Mantle Gateway can support token deposits and withdrawals via this custom bridge. To add your bridge and token to the token list, you must make a pull request against the Mantle [token list repository](https://github.com/mantlenetworkio/mantle-token-lists#mantle-token-list). Due to the complexity of reviewing a custom bridge, you will need to deploy to Mantle testnet first, before going to production. # Resources & Tooling # Node Endpoints and Providers Mantle provides powerful RPC Endpoints to programmatically interact with the web. Whether you are operating on a Mainnet or testing on a Testnet, Mantle provides accessible URLs for easy integration. ## Official Network Endpoints[​](https://docs-v2.mantle.xyz/devs/dev-guides/tools/endpoints#official-network-endpoints) <a href="#official-network-endpoints" id="official-network-endpoints"></a> Currently, Mantle Network supports both `https` and `WSS` endpoints. {% tabs %} {% tab title="Mainnet" %} | Connection Ways | Url | | ----------------- | ------------------------------------------------- | | **Https Url** | [https://rpc.mantle.xyz](https://rpc.mantle.xyz/) | | **WebSocket Url** | wss\://wss.mantle.xyz | | {% endtab %} | | {% tab title="Testnet (Sepolia)" %} | Connection Ways | Url | | ----------------- | ----------------------------------------------------------------- | | **Https Url** | [https://rpc.sepolia.mantle.xyz](https://rpc.sepolia.mantle.xyz/) | | **WebSocket Url** | N/A | | {% endtab %} | | | {% endtabs %} | | {% hint style="info" %} * The official Mantle RPC employs rate limiting to ensure stability during traffic spikes * The WebSocket supports an access method equivalent to the https interface, along with event subscription and cancellation. See [here](https://ethereum.org/en/developers/tutorials/using-websockets/)
프로젝트로 돌아가기