Initia 백서

Initia

원문

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

restClient, new MnemonicKey({ mnemonic: MNEMONIC_KEY }) ) async function send(msgs: Msg[]) { const tx = await wallet.createAndSignTx({ msgs }) const broadcastRes = await wallet.rest.tx.broadcast(tx) if (isTxError(broadcastRes)) { throw new Error(`Error while sending tx: ${broadcastRes.code} ${broadcastRes.raw_log}`) } } async function run() { const stage = TARGET_STAGE // or await getCurrentStage(); /* add deployer ------------------------------ */ const msgs0 = [ new MsgExecute( wallet.key.accAddress, SCORE_CONTRACT, 'vip_score', 'add_deployer_script', [], [ bcs.address().serialize(wallet.key.accAddress).toBase64() ] ) ] await send(msgs0) console.log('Deployer added successfully.') /* set initial stage ---------------------------- */ const msgs1 = [ new MsgExecute( wallet.key.accAddress, SCORE_CONTRACT, 'vip_score', 'set_init_stage', [], [ bcs.u64().serialize(TARGET_STAGE).toBase64() ] ) ] await send(msgs1) console.log('Initial stage set successfully.') /* update scores --------------------------------- */ const msgs2 = [ new MsgExecute( wallet.key.accAddress, SCORE_CONTRACT, 'vip_score', 'update_score_script', [], [ bcs.u64().serialize(stage).toBase64(), bcs.vector(bcs.address()).serialize(ADDRESSES).toBase64(), bcs.vector(bcs.u64()).serialize(SCORES).toBase64() ] ) ] await send(msgs2) console.log('Scores updated successfully.') /* finalize stage --------------------------------- */ const msgs3 = [ new MsgExecute( wallet.key.accAddress, SCORE_CONTRACT, 'vip_score', 'finalize_script', [], [ bcs.u64().serialize(stage).toBase64() ] ) ] await send(msgs3) console.log('Stage finalized successfully.') } run().catch(console.error) ``` </Tab> <Tab title="WasmVM"> | Action | Method | Description | | -------------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------- | | Update scores | `update_scores(signer, stage, addrs[], amounts[])` | Update the scores for a list of addresses in the specified stage | | Finalize stage | `finalize_stage(stage)` | Finalize the given stage, preventing further changes and prepares the contract for the next stage | ```ts vip-score-wasm-tutorial.ts theme={null} import { Coins, isTxError, MnemonicKey, Msg, MsgExecuteContract, RESTClient, Wallet } from '@initia/initia.js' /* -------------------------------------------------------- * * Environment variables * * -------------------------------------------------------- */ const RPC_URL = process.env.REST_URL || 'https://rest-wasm-1.anvil.asia-southeast.initia.xyz'; // Your rollup's REST endpoint const MNEMONIC_KEY = process.env.MNEMONIC_KEY || 'castle ping ...'; // Your contract deployer's mnemonic key. Do not hardcode it in production const SCORE_CONTRACT = process.env.SCORE_CONTRACT || 'init1ga1g...'; // The deployed VIP scoring contract address const TARGET_STAGE = process.env.TARGET_STAGE || '1'; // The stage number you want to update scores for /* -------------------------------------------------------- * * Update addresses and scores (Mock Implementation) * * Replace these with actual addresses and scores * * -------------------------------------------------------- */ // ADDRESSES and SCORES should be arrays of the same length. const ADDRESSES = [ 'init1lf0swvvhy3vqautdemmvunfmp0grfrjgzznx9s', 'init1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpqr5e3d' ] const SCORES = [100, 250] const restClient = new RESTClient(RPC_URL) const wallet = new Wallet( restClient, new MnemonicKey({ mnemonic: MNEMONIC_KEY }) ) async function send(msgs: Msg[]) { const tx = await wallet.createAndSignTx({ msgs }) const broadcastRes = await wallet.rest.tx.broadcast(tx) if (isTxError(broadcastRes)) { throw new Error(`Error while sending tx: ${broadcastRes.code} ${broadcastRes.raw_log}`) } } async function run() { const stage = Number(TARGET_STAGE) // or await getCurrentStage(); /* update scores ----------------------------- */ const msgs1 = [ new MsgExecuteContract( wallet.key.accAddress, SCORE_CONTRACT, Buffer.from( JSON.stringify({ update_scores: { stage, scores: [ ...ADDRESSES.map((addr, i) => ([addr, SCORES[i]])) ] } }) ).toString('base64'), new Coins() ) ] await send(msgs1) console.log('Scores updated successfully.') /* finalize stage --------------------------------- */ const msgs2 = [ new MsgExecuteContract( wallet.key.accAddress, SCORE_CONTRACT, Buffer.from( JSON.stringify({ finalize_stage: { stage, }, }) ).toString('base64'), new Coins() ) ] await send(msgs2) console.log('Stage finalized successfully.') } run().catch(console.error) ``` </Tab> </Tabs> </Step> </Steps> # Managing Operator Settings Source: https://docs.initia.xyz/developers/developer-guides/integrating-initia-apps/vip/manage-operator-settings ## Prerequisites * [Initiad CLI](/developers/developer-guides/tools/clis/initiad-cli) ## Updating Operator Address The operator is the account you specify during VIP whitelisting that will receive your rollup's operator commission rewards. To learn more about the VIP operator rewards, see [this section](/home/core-concepts/vip/architecture#distribution-to-rollup-operators). To replace the operator address, call `update_operator` on the VIP contract and pass two arguments in order: the rollup bridge ID and the new operator address. The bridge ID uniquely identifies your rollup bridge and can be retrieved from `${REST_URL}/opinit/opchild/v1/bridge_info`. <CodeGroup> <CodeBlock> export BRIDGE\_ID=29 # Replace with your rollup bridge ID. You can get it from `${REST_URL}/opinit/opchild/v1/bridge_info` export NEW\_OPERATOR\_ADDRESS=init14zmga05vl324ddaw7wqwdqt9pcvjeeyae3jn2k # Replace with the new operator address export OPERATOR\_KEY\_NAME=operator # Replace with your operator key. Check `initiad keys list` for the list of your keys export VIP\_CONTRACT='init182yxkv4gqfvz7tjyde6dfgjdr4ldqxklgmf23aju2u3cslnss7ys6dy6w8' export RPC\_URL='[https://rpc.initia.xyz](https://rpc.initia.xyz)' export CHAIN\_ID='interwoven-1' initiad tx move execute-json $VIP_CONTRACT vip update_operator \ --args '["'$'", "'${NEW_OPERATOR_ADDRESS}'"]' \ --from $OPERATOR\_KEY\_NAME \ \--node $RPC_URL \ --chain-id $CHAIN\_ID \ \--gas-prices 0.015uinit \ \--gas auto </CodeBlock> <CodeBlock> export BRIDGE\_ID=29 # Replace with your rollup bridge ID. You can get it from `${REST_URL}/opinit/opchild/v1/bridge_info` export NEW\_OPERATOR\_ADDRESS=init14zmga05vl324ddaw7wqwdqt9pcvjeeyae3jn2k # Replace with the new operator address export OPERATOR\_KEY\_NAME=operator # Replace with your operator key. Check `initiad keys list` for the list of your keys export VIP\_CONTRACT='init1u4wvsgl0ksgma40w6fdv55nhy2d9f332kdmfqp0cdnzyhsxquk4swhuwfz' export RPC\_URL='[https://rpc.testnet.initia.xyz](https://rpc.testnet.initia.xyz)' export CHAIN\_ID='initiation-2' initiad tx move execute-json $VIP_CONTRACT vip update_operator \ --args '["'$'", "'${NEW_OPERATOR_ADDRESS}'"]' \ --from $OPERATOR\_KEY\_NAME \ \--node $RPC_URL \ --chain-id $CHAIN\_ID \ \--gas-prices 0.015uinit \ \--gas auto </CodeBlock> </CodeGroup> ## Updating Operator Commission Operator commissions can be adjusted based on the `operator_commission_max_rate` and `operator_commission_max_change_rate` settings established during VIP whitelisting. Note that the commission value can be modified only once per stage, and any updated rate will take effect starting from the next stage. To update the operator commission, call `update_operator_commission` on the VIP contract. This function takes three arguments: 1. the rollup bridge ID 2. the version number 3. the new commission rate Use version value `1` when the rollup is listed for the first time. If the rollup is delisted and later relisted, set the version to the previous value plus 1. <CodeGroup> <CodeBlock> export BRIDGE\_ID=29 # Replace with your actual bridge ID. You can get it from `${REST_URL}/opinit/opchild/v1/bridge_info` export VERSION=1 # Use 1 unless your rollup has been delisted before export NEW\_COMMISSION\_RATE=0.05 # Replace with the new commission rate (e.g., 0.05 for 5%) export OPERATOR\_KEY\_NAME=operator # Replace with your operator key name. Check `initiad keys list` for the list of your keys export VIP\_CONTRACT='init182yxkv4gqfvz7tjyde6dfgjdr4ldqxklgmf23aju2u3cslnss7ys6dy6w8' export RPC\_URL='[https://rpc.initia.xyz](https://rpc.initia.xyz)' export CHAIN\_ID='interwoven-1' initiad tx move execute-json $VIP_CONTRACT vip update_operator_commission \ --args '["'$'", "'${VERSION}'", "'$'"]' \ \--from $OPERATOR_KEY_NAME \ --node $RPC\_URL \ \--chain-id \$CHAIN\_ID \ \--gas-prices 0.015uinit \ \--gas auto </CodeBlock> <CodeBlock> export BRIDGE\_ID=29 # Replace with your actual bridge ID. You can get it from `${REST_URL}/opinit/opchild/v1/bridge_info` export VERSION=1 # Use 1 unless your rollup has been delisted before export NEW\_COMMISSION\_RATE=0.05 # Replace with the new commission rate (e.g., 0.05 for 5%) export OPERATOR\_KEY\_NAME=operator # Replace with your operator key name. Check `initiad keys list` for the list of your keys export VIP\_CONTRACT='init1u4wvsgl0ksgma40w6fdv55nhy2d9f332kdmfqp0cdnzyhsxquk4swhuwfz' export RPC\_URL='[https://rpc.testnet.initia.xyz](https://rpc.testnet.initia.xyz)' export CHAIN\_ID='initiation-2' initiad tx move execute-json $VIP_CONTRACT vip update_operator_commission \ --args '["'$'", "'${VERSION}'", "'$'"]' \ \--from $OPERATOR_KEY_NAME \ --node $RPC\_URL \ \--chain-id \$CHAIN\_ID \ \--gas-prices 0.015uinit \ \--gas auto </CodeBlock> </CodeGroup> # Updating VIP Scoring Criteria Source: https://docs.initia.xyz/developers/developer-guides/integrating-initia-apps/vip/update-vip-scoring-criteria This guide explains how to update the VIP scoring criteria for a rollup. <Steps> <Step title="Publish a Forum Proposal"> Use the provided [proposal template](https://forum.initia.xyz/t/epoch-x-rollup-vip-update/263) to submit a forum proposal on the [Initia Forum](https://forum.initia.xyz) outlining the new scoring criteria and the changes. Submit this proposal at least one week before the VIP scoring criteria update date so the community can review and discuss it. </Step> <Step title="Comment on Original Proposal"> In your original VIP whitelist proposal forum post, add a comment that links to the new draft so community members can follow the discussion. </Step> <Step title="Notify the Initia Team"> Inform the Initia team about your new criteria and share the link to the corresponding forum post so the VIP Committee can review it. </Step> <Step title="VIP Committee Review"> The VIP committee will verify that your new criteria follow the [scoring policy](/home/core-concepts/vip/scoring#scoring-criteria) and are logically sound. If the new scoring criteria meet the requirements, the VIP committee will approve them and notify you. </Step> <Step title="Public Announcement"> After the VIP committee approves the new scoring criteria, announce the changes at least one week before it is implemented to your community. Examples include posting on Discord, X (Twitter), and your other communication channels. The announcement must clearly explain every change, giving the exact date and time when the new criteria take effect. It should also link to the forum post and list any actions users must take so they have enough time to prepare. </Step> </Steps> # Whitelisting Rollup for VIP Source: https://docs.initia.xyz/developers/developer-guides/integrating-initia-apps/vip/whitelist-rollup-for-vip You must whitelist your rollup before it can participate in the Vested Interest Program (VIP). <Note> The following steps are for whitelisting a rollup for VIP on Mainnet. For testnet rollups, please contact the Initia team. This section also assumes you have already added your rollup to the [Initia Registry](/developers/developer-guides/integrating-initia-apps/registry/introduction). If not, please follow the guide in the [previous section](/developers/developer-guides/integrating-initia-apps/vip/integrate-vip). </Note> <Steps> <Step title="Deploy the VIP Scoring Contract"> Deploy the appropriate VIP scoring contract for your rollup’s VM. * EVM: [https://github.com/initia-labs/vip-score-evm](https://github.com/initia-labs/vip-score-evm) * Wasm: [https://github.com/initia-labs/vip-score-wasm](https://github.com/initia-labs/vip-score-wasm) * Move: [https://github.com/initia-labs/vip-score-move](https://github.com/initia-labs/vip-score-move) </Step> <Step title="Submit a Forum Proposal"> Before your rollup can be whitelisted, you must create a proposal in the [Initia Forum](https://forum.initia.xyz). See the [template](https://forum.initia.xyz/t/whitelist-new-rollup-on-vip/146) for the necessary information. </Step> <Step title="Submit an L1 Governance Proposal"> After creating the forum proposal, you finally need to submit a governance proposal on the Initia L1. The script below shows how to do so. ```ts vip-l1-gov-proposal.ts expandable theme={null} import { MnemonicKey, RESTClient, Wallet, bcs, MsgSubmitProposal, MsgGovExecute } from '@initia/initia.js' const MNEMONIC_KEY = process.env.MNEMONIC_KEY || 'castle lung ...' // Your wallet's mnemonic key const REST_URL = process.env.REST_URL || 'https://rest.initia.xyz' // Initia L1 REST endpoint // Core parameters const VIP_CONTRACT_ADDRESS = process.env.VIP_CONTRACT || 'init182yxkv4gqfvz7tjyde6dfgjdr4ldqxklgmf23aju2u3cslnss7ys6dy6w8' // Rollup's VIP contract address const OPERATOR_ADDRESS = process.env.OPERATOR_ADDRESS || '0x68b8295438b3d50f81679db88260a596b8ab1f4be1caa94af87c6b853baf7b20' // Rollup's VIP operator address const BRIDGE_ID = process.env.BRIDGE_ID || '16' // Bridge ID const BRIDGE_ADDRESS = process.env.BRIDGE_ADDRESS || 'init1y3avrs2r9q3ggj5xs2q5zg4mmpqvr2necwl6s6fhfergtyp93ueq5270ht' // Bridge address const L2_SCORE_CONTRACT_ADDRESS = process.env.L2_SCORE_CONTRACT_ADDRESS || '0x668dc438bd71f365d1e9ae39ac92f35d5ccde03d' // L2 score contract address // Operator commission settings const OPERATOR_COMMISSION_MAX_RATE = process.env.OPERATOR_COMMISSION_MAX_RATE || '0.2' // Operator commission max rate, e.g., 0.2 for 20% const OPERATOR_COMMISSION_MAX_CHANGE_RATE = process.env.OPERATOR_COMMISSION_MAX_CHANGE_RATE || '0.2' // Operator commission max change rate, e.g., 0.2 for 20% const OPERATOR_COMMISSION_RATE = process.env.OPERATOR_COMMISSION_RATE || '0.2' // Operator commission rate, e.g., 0.2 for 20% // Proposal parameters const PROPOSAL_METADATA = process.env.PROPOSAL_METADATA || 'https://forum.initia.xyz' // VIP proposal forum URL const PROPOSAL_TITLE = process.env.PROPOSAL_TITLE || 'Whitelist Rollup on VIP' // VIP proposal title const PROPOSAL_SUMMARY = process.env.PROPOSAL_SUMMARY || 'This proposal is to whitelist Rollup on Initia VIP program.' // VIP proposal summary const ROLLUP_VM_TYPE = process.env.ROLLUP_VM_TYPE || 0 // Rollup VM type, 0 for MoveVM, 1 for WasmVM, 2 for EVM async function main() { const key = new MnemonicKey({ mnemonic: MNEMONIC_KEY }) const rest = new RESTClient(REST_URL, { gasPrices: `0.015uinit` }) const wallet = new Wallet(rest, key) const msg = new MsgSubmitProposal( [ new MsgGovExecute( 'init10d07y265gmmuvt4z0w9aw880jnsr700j55nka3', VIP_CONTRACT_ADDRESS, VIP_CONTRACT_ADDRESS, 'vip', 'register', [], [ bcs.address().serialize(OPERATOR_ADDRESS).toBase64(), bcs.u64().serialize(BRIDGE_ID).toBase64(), bcs.address().serialize(BRIDGE_ADDRESS).toBase64(), bcs.string().serialize(L2_SCORE_CONTRACT_ADDRESS).toBase64(), bcs.bigdecimal().serialize(OPERATOR_COMMISSION_MAX_RATE).toBase64(), bcs.bigdecimal().serialize(OPERATOR_COMMISSION_MAX_CHANGE_RATE).toBase64(), bcs.bigdecimal().serialize(OPERATOR_COMMISSION_RATE).toBase64(), bcs.u64().serialize(ROLLUP_VM_TYPE).toBase64() ] ) ], '100000000uinit', wallet.key.accAddress, PROPOSAL_METADATA, PROPOSAL_TITLE, PROPOSAL_SUMMARY, false ) const tx = await wallet.createAndSignTx({ msgs: [msg] }) const result = await rest.tx.broadcast(tx) console.log('Transaction result:', result) } main().catch(console.error) ``` </Step> <Step title="Proposal Voting Period"> After you submit the proposal, it enters a 7-day voting period. If the proposal passes, VIP whitelists and activates your rollup. </Step> </Steps> # Account Source: https://docs.initia.xyz/developers/developer-guides/tools/clis/initiad-cli/accounts ## Creating an Account Before you can start building and transacting, you'll need to create an account. ```bash theme={null} export ACCOUNT_NAME=test-account initiad keys add $ACCOUNT_NAME # - address: init17exjfvgtpn5ne4pgmuatjg52mvvtj08773tgfx # name: test-account # pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"Ap+WnRzOsJGgfgsrgc4APi/EiTzl3t52ruiKGev7X9LW"}' # type: local # **Important** write this mnemonic phrase in a safe place. # It is the only way to recover your account if you ever forget your password. # glass easy miracle sign tent anchor position cluster shift calm march elite menu must nose inform antique reason meadow relief layer term crush gesture ``` <Warning> The mnemonic key is the only way to recover your account if you forget your password. </Warning> If you want to create an EVM account, you can use the following command: ```bash theme={null} export ETH_KEY_TYPE=eth_secp256k1 export ETH_COIN_TYPE=60 initiad keys add $ACCOUNT_NAME --key-type $ETH_KEY_TYPE --coin-type $ETH_COIN_TYPE ``` <Note> Even with the same mnemonic phrase, the derived addresses differ because the method of generating the public key varies, leading to each account being treated separately. </Note> ## Importing an Account You can import an account by providing a mnemonic phrase. ```bash theme={null} initiad keys add $ACCOUNT_NAME --recover > Enter your bip39 mnemonic glass easy miracle sign tent anchor position cluster shift calm march elite menu must nose inform antique reason meadow relief layer term crush gesture # - address: init1x7jl4cx6pq4urdppmnhwtyzfdtn5w7ssw4hjfm # name: test-account # pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"Am9tmvRft+pcol+h/unlMB9gRbKAZF/7Y8K3iWOtr9Dw"}' # type: local ``` To export the account's private key, run: ```bash theme={null} initiad keys export $ACCOUNT_NAME > key.json >Enter passphrase to encrypt the exported key: # key.json # -----BEGIN TENDERMINT PRIVATE KEY----- # kdf: argon2 # salt: BE84B59652876BFBEEB0E01CA2AA753C # type: secp256k1 # edch8EcPYgSQrWHdJlmRMZGmh7gqOLYvAHsynbovXonq2reSeP+eEgtvwNYEnrQu # 2MZwMIs= # =ObmR # -----END TENDERMINT PRIVATE KEY----- ``` <Note> The exported private key is encrypted with a passphrase. So, you can only import it using `initiad` CLI. It is not possible to import it directly on Wallet Apps. </Note> To import the account using the exported private key, run: ```bash theme={null} export NEW_ACCOUNT_NAME=test-account2 initiad keys import $NEW_ACCOUNT_NAME key.json ``` ## Retrieving Account Data You can retrieve account data stored in the keyring. ```bash theme={null} initiad keys list # - address: init1x7jl4cx6pq4urdppmnhwtyzfdtn5w7ssw4hjfm # name: test-account # pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"Am9tmvRft+pcol+h/unlMB9gRbKAZF/7Y8K3iWOtr9Dw"}' # type: local ``` ## Validator Address If you run a validator node, you can get the validator address by running: ```bash theme={null} initiad comet show-address # initvalcons1kknrtmntc39v3z4hgv84hddeclyfsxdgzdtn3q ``` To get validator consensus public key, run: ```bash theme={null} initiad comet show-validator # {"@type":"/cosmos.crypto.ed25519.PubKey","key":"lusuUL6CKywnZDPul5COzCFKLPLDGEMbLEIZIZlDp44="} ``` # Introduction Source: https://docs.initia.xyz/developers/developer-guides/tools/clis/initiad-cli/int
프로젝트로 돌아가기