Movement 백서

Movement

원문

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

dmin: &signer) public entry fun initialize_with_validators(admin: &signer, validators: vector<address>) public entry fun add_validator(admin: &signer, validator: address) public entry fun remove_validator(admin: &signer, validator: address) public entry fun cleanup_inactive_validator(admin: &signer, validator: address) public entry fun admin_unstake_from_inactive(admin: &signer, validator: address, amount: u64) public entry fun pause(admin: &signer) public entry fun unpause(admin: &signer) public entry fun update_metadata( admin: &signer, icon_uri: string::String, project_uri: string::String ) } ``` # Move 2 URL: /devs/move2 # Move 2 Migration Guide for Movement This guide covers the most impactful changes in Move 2 for developers already familiar with Move 1 syntax. Each section shows before/after examples to help you understand how to leverage these new features. ## 1. Enum Types (Move 2.0) Enums allow you to define different variants of data layout in a single storable type, similar to Rust enums. ### Before (Move 1) ```move module my_addr::events { struct TransferEvent has store, drop { from: address, to: address, amount: u64, } struct MintEvent has store, drop { to: address, amount: u64, } struct BurnEvent has store, drop { from: address, amount: u64, } // Need separate handling for each event type struct EventStore has key { transfers: vector<TransferEvent>, mints: vector<MintEvent>, burns: vector<BurnEvent>, } } ``` ### After (Move 2) ```move module my_addr::events { // All variants in one type enum TokenEvent has store, drop { Transfer { from: address, to: address, amount: u64 }, Mint { to: address, amount: u64 }, Burn { from: address, amount: u64 }, } // Single vector for all event types struct EventStore has key { events: vector<TokenEvent>, } // Pattern matching on variants public fun process_event(event: &TokenEvent) { match (event) { TokenEvent::Transfer { from, to, amount } => { // Handle transfer }, TokenEvent::Mint { to, amount } => { // Handle mint }, TokenEvent::Burn { from, amount } => { // Handle burn }, } } } ``` **Benefits**: Cleaner code organization, type safety across variants, and simplified storage patterns. *** ## 2. Receiver Style Functions (Move 2.0) Call functions using the familiar `value.method(args)` notation instead of `module::function(value, args)`. ### Before (Move 1) ```move module my_addr::token { struct Token has store { value: u64, } public fun new(value: u64): Token { Token { value } } public fun value(token: &Token): u64 { token.value } public fun add(token: &mut Token, amount: u64) { token.value = token.value + amount; } // Usage elsewhere: // let mut token = token::new(100); // let val = token::value(&token); // token::add(&mut token, 50); } ``` ### After (Move 2) ```move module my_addr::token { struct Token has store { value: u64, } public fun new(value: u64): Token { Token { value } } // Receiver-style functions public fun value(self: &Token): u64 { self.value } public fun add(self: &mut Token, amount: u64) { self.value = self.value + amount; } // Usage elsewhere - much more intuitive! // let mut token = token::new(100); // let val = token.value(); // token.add(50); } ``` **Benefits**: More intuitive, object-oriented style syntax that's easier to read and chain operations. *** ## 3. Index Notation (Move 2.0) Access vector elements and resource storage with cleaner bracket notation. ### Before (Move 1) ```move module my_addr::registry { use std::vector; struct Registry has key { items: vector<u64>, } public fun get_item(registry: &Registry, index: u64): u64 { *vector::borrow(&registry.items, index) } public fun update_item(registry: &mut Registry, index: u64, value: u64) { let item = vector::borrow_mut(&mut registry.items, index); *item = value; } public fun get_registry(addr: address): &Registry acquires Registry { borrow_global<Registry>(addr) } } ``` ### After (Move 2) ```move module my_addr::registry { struct Registry has key { items: vector<u64>, } public fun get_item(registry: &Registry, index: u64): u64 { registry.items[index] } public fun update_item(registry: &mut Registry, index: u64, value: u64) { registry.items[index] = value; } public fun get_registry(addr: address): &Registry acquires Registry { &Registry[addr] // Cleaner resource access } } ``` **Benefits**: Dramatically cleaner syntax that's familiar to developers from other languages. *** ## 4. Optional Acquires (Move 2.2) The compiler can now infer which resources a function accesses, making the `acquires` annotation optional. ### Before (Move 1) ```move module my_addr::account { struct Balance has key { value: u64, } struct Config has key { fee: u64, } // Must manually annotate all acquired resources public fun transfer(from: address, to: address, amount: u64) acquires Balance, Config { let config = borrow_global<Config>(@my_addr); let fee = config.fee; let from_balance = borrow_global_mut<Balance>(from); from_balance.value = from_balance.value - amount - fee; let to_balance = borrow_global_mut<Balance>(to); to_balance.value = to_balance.value + amount; } } ``` ### After (Move 2.2) ```move module my_addr::account { struct Balance has key { value: u64, } struct Config has key { fee: u64, } // Acquires annotation is now optional - compiler infers it! public fun transfer(from: address, to: address, amount: u64) { let config = borrow_global<Config>(@my_addr); let fee = config.fee; let from_balance = borrow_global_mut<Balance>(from); from_balance.value = from_balance.value - amount - fee; let to_balance = borrow_global_mut<Balance>(to); to_balance.value = to_balance.value + amount; } } ``` **Benefits**: Less boilerplate, fewer chances for annotation errors, and easier refactoring. *** ## 5. Compound Assignments (Move 2.1) Use familiar `+=`, `-=`, etc. operators instead of verbose assignment patterns. ### Before (Move 1) ```move module my_addr::counter { struct Counter has key { value: u64, } public fun increment(counter: &mut Counter, amount: u64) { counter.value = counter.value + amount; } public fun decrement(counter: &mut Counter, amount: u64) { counter.value = counter.value - amount; } public fun multiply(counter: &mut Counter, factor: u64) { counter.value = counter.value * factor; } } ``` ### After (Move 2.1) ```move module my_addr::counter { struct Counter has key { value: u64, } public fun increment(counter: &mut Counter, amount: u64) { counter.value += amount; } public fun decrement(counter: &mut Counter, amount: u64) { counter.value -= amount; } public fun multiply(counter: &mut Counter, factor: u64) { counter.value *= factor; } } ``` **Benefits**: More concise, familiar syntax from other programming languages. Supported operations: `+=`, `-=`, `*=`, `/=`, `%=`, `&=`, `|=`, `^=`, `<<=`, `>>=`. *** ## 6. Package Visibility (Move 2.0) Declare functions visible anywhere inside a package but not outside, with cleaner syntax than friend functions. ### Before (Move 1) ```move module my_addr::internal { friend my_addr::public_api; friend my_addr::admin; public(friend) fun internal_helper(): u64 { 42 } } module my_addr::public_api { use my_addr::internal; public fun call_helper(): u64 { internal::internal_helper() } } ``` ### After (Move 2.0) ```move module my_addr::internal { // Cleaner syntax - visible to entire package package fun internal_helper(): u64 { 42 } // Or use the explicit form public(package) fun another_helper(): u64 { 100 } } module my_addr::public_api { use my_addr::internal; public fun call_helper(): u64 { // Can call package functions from anywhere in the package internal::internal_helper() } } ``` **Benefits**: Simpler visibility control, no need to maintain friend lists, better encapsulation at package level. *** ## 7. Positional Structs (Move 2.0) Define wrapper types and simple structs with positional fields instead of named fields. ### Before (Move 1) ```move module my_addr::wrapped { struct Wrapped has store, drop { value: u64, } public fun new(value: u64): Wrapped { Wrapped { value } } public fun unwrap(wrapped: Wrapped): u64 { let Wrapped { value } = wrapped; value } } ``` ### After (Move 2.0) ```move module my_addr::wrapped { // Positional struct - perfect for wrappers struct Wrapped(u64) has store, drop; public fun new(value: u64): Wrapped { Wrapped(value) } public fun unwrap(wrapped: Wrapped): u64 { let Wrapped(value) = wrapped; value } } ``` **Benefits**: Less boilerplate for simple wrapper types, cleaner syntax for single-field structs. *** ## Quick Reference: Other Notable Changes ### Simplified Assertions (Move 2.0) ```move // Before: always needed abort code assert!(condition, ERROR_CODE); // After: abort code is optional assert!(condition); // Uses default abort code ``` ### Cleaner Cast Syntax (Move 2.0) ```move // Before: required parentheses function((x as u256)) // After: no parentheses needed at top level function(x as u256) ``` ### Loop Labels (Move 2.1) ```move // Break or continue outer loops from nested loops 'outer: loop { loop { if (condition) break 'outer; } } ``` *** ## Summary The most impactful Move 2 features for day-to-day development are: 1. **Enums** - Better type modeling and pattern matching 2. **Receiver functions** - More intuitive method call syntax 3. **Index notation** - Cleaner vector and resource access 4. **Optional acquires** - Less boilerplate in function signatures 5. **Compound assignments** - Familiar `+=` style operators 6. **Package visibility** - Simpler module organization These features make Move code more expressive, safer, and easier to maintain while preserving Move's core safety guarantees. # Movement CLI URL: /devs/movementcli Movement CLI supports Aptos Move natively. Here are the instructions to install and use `movement` CLI. ## Install via Homebrew Works on macOS ARM64 (M-series), macOS x86\_64 (Intel), and Linux x86\_64. ```bash brew tap moveindustries/movement brew install movement ``` Or directly: ```bash brew install moveindustries/movement/movement ``` Verify installation: ```bash movement --version ``` It should return `movement 7.4.0`. ### Windows <Callout type="info"> For Windows users, we recommend installing the Aptos CLI. Movement CLI commands are fully compatible with Aptos CLI. </Callout> ```bash tab="Windows" $Version = "7.4.0" $ZipUrl = "https://github.com/aptos-labs/aptos-core/releases/download/aptos-cli-v$Version/aptos-cli-$Version-Windows-x86_64.zip" $InstallDir = "$env:USERPROFILE\.aptoscli\bin" $ZipPath = "$env:TEMP\aptos-cli.zip" Invoke-WebRequest -Uri $ZipUrl -OutFile $ZipPath New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null Expand-Archive -Path $ZipPath -DestinationPath $InstallDir -Force # Set PATH $CurrentPath = [System.Environment]::GetEnvironmentVariable("Path", "User") if ($CurrentPath -notlike "*$InstallDir*") { setx PATH "$CurrentPath;$InstallDir" Write-Host "`n✅ PATH updated. Please restart your terminal before running 'aptos'." } else { Write-Host "`n✅ PATH already configured." } ``` ## Install Movement CLI Manually <Callout type="info"> When developing on Movement, it is recommended to use the `movement` CLI. </Callout> ### Binary Install ``` git clone https://github.com/movement-network/aptos-core/ && cd aptos-core ``` ``` cargo build -p movement ``` Copy `movement` into your `bin` or add it to your `PATH` depending on your system config. For example, to copy `movement` to `bin` on Mac or Linux: ``` sudo cp target/debug/movement /usr/local/bin/ ``` ## Use Movement CLI Movement CLI commands are analogous to those of Aptos CLI. Simply replace `aptos` with `movement`. So `aptos move build` becomes `movement move build`. For help within the CLI tool: ``` movement --help ``` or ``` movement <subcommand> --help ``` Developers who would like to contribute or read the source code, please see [the Movement CLI crate](https://github.com/movement-network/aptos-core/tree/movement/crates/aptos). # Movement Name Service URL: /devs/nameService # Movement Name Service <Callout type="warn"> The Movement Name Service is currently live on **testnet only**. The URL and contract addresses will change when it launches on mainnet. </Callout> The Movement Name Service (MNS) allows users to register `.move` domain names as NFTs that serve as a universal identity across the Movement ecosystem. Each `.move` name resolves to a blockchain address and can be set as a primary name for reverse lookups. ## SDK Integration MNS functionality is built into the [Movement TypeScript SDK](/devs/interactonchain/tsSdk). All name service methods are accessible through the `movement` client instance. ### Installation ```bash tab="npm" npm install @moveindustries/ts-sdk ``` ```bash tab="pnpm" pnpm add @moveindustries/ts-sdk ``` ### Setup ```typescript import { Movement, MovementConfig, Network } from "@moveindustries/ts-sdk"; const config = new MovementConfig({ network: Network.TESTNET, }); const movement = new Movement(config); ``` ## Domain Registration ### Check Price and Availability ```typescript const name = "mydomain"; const price = await movement.getDomainPrice({ name, years: 1 }); console.log(`Registration cost: ${Number(price) / 1e8} MOVE`); const available = await movement.canRegister({ name }); console.log(`Available: ${available}`); ``` ### Register a Domain ```typescript const txn = await movement.registerName({ name: "mydomain.move", sender: account, expiration: { policy: "domain" }, }); ``` ### Renew a Domain ```typescript await movement.renewDomain({ name: "mydomain.move", sender: account, years: 1, }); ``` ## Name Resolution ### Resolve Name to Address ```typescript const address = await movement.getTargetAddress({ name: "mydomain.move" }); console.log(`Address: ${address}`); ``` ### Reverse Lookup (Address to Primary Name) ```typescript const name = await movement.getPrimaryName({ address: "0x123...", }); console.log(`Primary name: ${name}`); ``` ### Get All Names for an Address ```typescript const names = await movement.getAccountNames({ accountAddress: "0x123...", }); console.log(names); ``` ## Name Management ### Set Target Address Configure which address a name resolves to: ```typescript await movement.setTargetAddress({ sender: account, name: "mydomain.move", address: targetAddress, }); ``` ### Clear Target Address ```typescript await movement.clearTargetAddress({ sender: account, name: "mydomain.move", }); ``` ### Set Primary Name Designate a name as the primary identity for your account: ```typescript await movement.setPrimaryName({ sender: account, name: "mydomain.move", }); ``` ### Check Ownership ```typescript const isOwner = await movement.isNameOwner({ name: "mydomain.move", address: account.accountAddress, }); ``` ## Additional Methods | Method | Description | | ------------------- | ----------------------------------------- | | `getName` | Fetch metadata for a specific name | | `getOwnerAddress` | Get the owner of a domain | | `getExpiration` | Get the expiration timestamp for a domain | | `getAccountDomains` | List all domains owned by an address | | `getTokenAddress` | Get the NFT token address for a domain | ## Indexer Queries You can query MNS data directly using the Movement indexer GraphQL API. The testnet endpoint is: ``` https://indexer.testnet.movementnetwork.xyz/v1/graphql ``` You can explore and test queries interactively using the [GraphiQL explorer](https://cloud.hasura.io/public/graphiql?endpoint=https%3A%2F%2Findexer.testnet.movementnetwork.xyz%2Fv1%2Fgraphql). ### Schema The `current_aptos_names` table contains all MNS name records with the following fields: | Field | Type | Description | | -------------------------- | --------- | ------------------------------------------------ | | `domain` | String | The domain name (without suffix) | | `domain_with_suffix` | String | Full domain name (e.g. `mydomain.move`) | | `owner_address` | String | Address that owns the name NFT | | `registered_address` | String | Address the name resolves to | | `is_primary` | Boolean | Whether this is the primary name for the address | | `is_active` | Boolean | Whether the name is currently active | | `expiration_timestamp` | timestamp | When the domain registration expires | | `subdomain` | String | Subdomain portion if applicable | | `token_standard` | String | Token standard (v2) | | `last_transaction_version` | bigint | Last transaction that modified this record | ### Lookup a Domain by Name ```graphql { current_aptos_names( where: { domain: { _eq: "mydomain" }, is_active: { _eq: true } } ) { domain domain_with_suffix owner_address registered_address is_primary expiration_timestamp } } ``` ### Get All Names Owned by an Address ```graphql { current_aptos_names( where: { owner_address: { _eq: "0x..." } is_active: { _eq: true } } ) { domain domain_with_suffix is_primary registered_address expiration_timestamp } } ``` ### Get Primary Name for an Address ```graphql { current_aptos_names( where: { registered_address: { _eq: "0x..." } is_primary: { _eq: true } is_active: { _eq: true } } ) { domain domain_with_suffix owner_address } } ``` ### Count All Active Names ```graphql { current_aptos_names_aggregate( where: { is_active: { _eq: true } } ) { aggregate { count } } } ``` ### Using the Indexer in TypeScript ```typescript const INDEXER_URL = "https://indexer.testnet.movementnetwork.xyz/v1/graphql"; async function getNamesByOwner(ownerAddress: string) { const query = ` query GetNamesByOwner($owner: String!) { current_aptos_names( where: { owner_address: { _eq: $owner } is_active: { _eq: true } } ) { domain domain_with_suffix is_primary registered_address expiration_timestamp } } `; const response = await fetch(INDEXER_URL, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ query, variables: { owner: ownerAddress }, }), }); const { data } = await response.json(); return data.current_aptos_names; } ``` # Network Endpoints URL: /devs/networkEndpoints <Callout type="info"> This page contains public endpoints that may at times be subject to rate limits. All partners listed below have paid private nodes as well for scaling your applications. </Callout> ### Network Status **View the network status and uptime performance of Movement Network here: [https://status.movementnetwork.xyz/](https://status.movementnetwork.xyz/)** ## Movement Mainnet **Chain ID: 126** | Service | URL | | ---------------- | ----------------------------------------------------------------------------------------------------------------------------- | | RPC (Primary) | [https://mainnet.movementnetwork.xyz/v1](https://mainnet.movementnetwork.xyz/v1) | | Bridge | [https://bridge.movementnetwork.xyz/](https://bridge.movementnetwork.xyz/) | | Explorer | [https://explorer.movementnetwork.xyz/?network=mainnet](https://explorer.movementnetwork.xyz/?network=mainnet) | | Indexer Explorer | [Explorer](https://cloud.hasura.io/public/graphiql?endpoint=https%3A%2F%2Findexer.mainnet.movementnetwork.xyz%2Fv1%2Fgraphql) | | Indexer Endpoint | [https://indexer.mainnet.movementnetwork.xyz/v1/graphql](https://indexer.mainnet.movementnetwork.xyz/v1/graphql) | ### Partner Endpoints The following public endpoints are provided by Movement's ecosystem infrastructure providers. All of the partners below also have paid private nodes. To learn more about setting up a private node for your project, see their website below. | Name | RPC Endpoint | | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------
프로젝트로 돌아가기