Starknet 백서

Starknet

원문

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

vicingToken`](https://github.com/starknet-io/starkgate-contracts/tree/v2.0.1/src/solidity/IStarkgateService.sol#L9C14-L9C30) in `IStarkgateService.sol`. *** ### `withdraw` #### Description Transfers the specified amount of the specified token to the address of the recipient specified in the `l1_recipient` parameter of the `initiate_token_withdraw` function on L2. Anyone can call this function, but only after the withdraw message has been recorded on the Starknet Core Contract. #### Parameters | | | | - | - | | `address token` | The address of the contract for the desired token. | | `uint256 amount` | The amount of the withdrawal. | | `address recipient` | (Optional) The recipient. If you don't specify this parameter, the withdraw function uses the sender's address. | #### State mutability `nonpayable` #### Returns None. #### Emitted event `Withdrawal` **Event attributes** | | | | - | - | | `address indexed recipient` | The recipient. | | `address indexed token` | The address of the contract for the desired token. | | `uint256 amount` | The amount of the withdrawal. | #### Function and event definition * Contract: [`StarknetTokenBridge.sol`](https://github.com/starknet-io/starkgate-contracts/tree/v2.0.1/src/solidity/StarknetTokenBridge.sol) * Function: [`withdraw`](https://github.com/starknet-io/starkgate-contracts/tree/v2.0.1/src/solidity/StarknetTokenBridge.sol#L481) * Event: [`Withdrawal`](https://github.com/starknet-io/starkgate-contracts/tree/v2.0.1/src/solidity/StarknetTokenBridge.sol#L62) ## L2 functions and events ### `get_erc20_class_hash` #### Description Returns the current class hash of the implementation used by the ERC-20 contract. Use the class hash as the type when deploying the ERC-20 contract on L2. <Warning> If StarkWare changes the class hash such that it is no longer the class hash that you used when deploying your bridge contract, this function returns the new class hash. If you want to refer to the class hash that you used when deploying your contract, see your deployed contract on Starknet. </Warning> #### Parameters None. #### Returns | | | | - | - | | `ClassHash` | The class hash of the ERC-20 token contract. | #### Function definition [`get_erc20_class_hash`](https://github.com/starknet-io/starkgate-contracts/tree/v2.0.1/src/cairo/token_bridge.cairo#L376-L378) in `token_bridge.cairo`. *** ### `get_identity` #### Description Returns a string in a felt252 type with the identity of StarkGate. #### Parameters None. #### Returns | | | | - | - | | `felt252` | The identity of StarkGate. | #### Function definition [`get_identity`](https://github.com/starknet-io/starkgate-contracts/tree/v2.0.1/src/cairo/token_bridge_interface.cairo#L8) in `token_bridge_interface.cairo`. *** ### `get_l1_token` #### Description Returns the L1 address that corresponds to the matching L2 address of an ERC-20 token contract. #### Parameters | | | | - | - | | `l2_token_address: ContractAddress` | The L2 address of the ERC-20 token contract. | #### Returns | | | | - | - | | `EthAddress` | The L1 address of the ERC-20 token contract. | | `EthAddressZeroable::zero()` | The token is not found in the bridge. | #### Function definition [`get_l1_token`](https://github.com/starknet-io/starkgate-contracts/tree/v2.0.1/src/cairo/token_bridge_interface.cairo#L9) in `token_bridge_interface.cairo`. *** ### `get_l2_token` #### Description Returns the L2 address that corresponds to the matching L1 address of an ERC-20 token contract. If the token is not found in the bridge, this function returns `0`. #### Parameters | | | | - | - | | `l1_token_address` | The L1 address of the ERC-20 token contract. | #### Returns | | | | - | - | | `ContractAddress address` | The L2 address of the ERC-20 token contract. | | `ContractAddressZeroable::zero()` | The token is not found in the bridge. | #### Function definition [`get_l2_token`](https://github.com/starknet-io/starkgate-contracts/tree/v2.0.1/src/cairo/token_bridge_interface.cairo#L10) in `token_bridge_interface.cairo`. *** ### `get_remaining_withdrawal_quota` #### Description Returns the amount that the user can withdraw within the current 24-hour time period. The time period begins at 00:00 UTC. #### Parameters | | | | - | - | | `l1_token_address` | The L1 address of the ERC-20 token contract. | #### Returns | | | | - | - | | `u256` | The amount that can currently be withdrawn from the bridge, in units defined by the ERC-20 token contract. | #### Function definition [`get_remaining_withdrawal_quota`](https://github.com/starknet-io/starkgate-contracts/tree/v2.0.1/src/cairo/token_bridge_interface.cairo#L11) in `token_bridge_interface.cairo` *** ### `get_version` #### Description Returns the current version of StarkGate. #### Parameters None. #### Returns | | | | - | - | | `felt252` | The current version of StarkGate. | #### Function definition [`get_version`](https://github.com/starknet-io/starkgate-contracts/tree/v2.0.1/src/cairo/token_bridge_interface.cairo#L7) in `token_bridge_interface.cairo`. *** ### `initiate_token_withdraw` #### Description Initiates a withdrawal from L2. After initiating the withdrawal, the function does the following: 1. Burns the transferred amount of tokens from the balance of the withdrawal's initiator. 2. Sends a message to the relevant L1 bridge with the amount to be transferred, and the recipient's address. #### Parameters | | | | - | - | | `l1_token: EthAddress` | The L1 address of the ERC-20 token contract. | | `l1_recipient: EthAddress` | The L1 address of the recipient. | | `amount uint256` | The amount to transfer. | #### Returns None. #### Function definition [`initiate_token_withdraw`](https://github.com/starknet-io/starkgate-contracts/tree/v2.0.1/src/cairo/token_bridge_interface.cairo#L13) in `token_bridge_interface.cairo`. *** ### `on_receive` #### Description An interface to an implementation of the `on_receive` function that you must provide in your L2 contract in order to enable the `depositWithMessage` function to succeed. The L2 contract that receives the message that is sent with the `depositWithMessage` function must implement a callback function named `on_receive`. Upon completion, the `depositWithMessage` function triggers a call to the `on_receive` callback function on the receiving L2 contract. The `on_receive` function receives the deposit message as input, and it must return `true` for the deposit to succeed. If `on_receive` returns `false`, or if the receiving contract does not implement `on_receive`, the `depositWithMessage` L1 handler fails, and the user can only recover their funds using the [`depositWithMessageCancelRequest`](#depositWithMessageCancelRequest) function. #### Parameters | | | | - | - | | `l2_token: ContractAddress` | The L2 address of the ERC-20 token contract. | | `amount: uint256` | The amount deposited. | | `depositor`: EthAddress | L1 address of the deposit sender. | | `message: Span<felt252>` | The message that was sent with the `depositWithMessage` function. | #### Returns | | | | - | - | | `true` | The `on_receive` function completed successfully. | | `false` | The `on_receive` function did not complete successfully. The transaction is reverted. | | No value | If the recipients's smart contract does not implement the `on_receive` function, the call fails to execute, and the transaction is reverted. | #### Function definition [`on_receive`](https://github.com/starknet-io/starkgate-contracts/tree/v2.0.1/src/cairo/receiver_interface.cairo#L6) in `receiver_interface.cairo`. # Developer tools Source: https://docs.starknet.io/learn/cheatsheets/tools <Warning> This page is continuously updated. If a tool you are using is missing, please consider opening an issue or editing the page. </Warning> ## Core tools * [Scarb](https://docs.swmansion.com/scarb/) is the build toolchain and package manager for Cairo and Starknet * [Starknet Foundry](https://foundry-rs.github.io/starknet-foundry/) is the toolchain for developing Starknet smart contracts * [Starknet Devnet](https://0xspaceshard.github.io/starknet-devnet/) is a local testnet for Starknet * [VS Code Cairo extension](https://marketplace.visualstudio.com/items?itemName=starkware.cairo1) is an extension for the Microsoft Visual Studio (VS) Code IDE that provides assistance when writing Cairo * [starknet.js](https://starknet-js.com/), [starknet.py](https://starknetpy.readthedocs.io/en/latest/), [starknet-rs](https://github.com/xJonathanLEI/starknet-rs?tab=readme-ov-file#starknet-rs), [starknet.go](https://pkg.go.dev/github.com/NethermindEth/starknet.go#section-readme), [starknet-jvm](https://github.com/software-mansion/starknet-jvm?tab=readme-ov-file#-starknet-jvm-), [starknet.swift](https://github.com/software-mansion/starknet.swift?tab=readme-ov-file#starknetswift), and [starknet.dart](https://starknetdart.dev/) are Starknet's various software development kits (SDKs) ## dApp tools * [Scaffold Stark](https://scaffoldstark.com/) is designed to make it easier for developers to create, deploy and interact with smart contracts. * [Starknet React](https://github.com/apibara/starknet-react) is a wagmi-inspired collection of React hooks for Starknet. * [Get Starknet](https://github.com/starknet-io/get-starknet) is a Starknet wallet\<>dApp connection bridge, that enables easy discovery and UI for Starknet wallets, including Ready, Braavos, Metamask Snaps, and OKX. * [Starknetkit](https://www.starknetkit.com/) is a Starknet wallet connection kit, built by Ready using Starknet.js and starknet-react. * [Dynamic SDK](https://go.dynamic.xyz/4eFmNMI) combines authentication, smart wallets, and secure key management into one flexible SDK that enables multi-chain coverage across chains and third-party wallets. * [Dojo](https://www.dojoengine.org/) is a developer friendly framework for building provable Games, Autonomous Worlds and other Applications that are natively composable, extensible, permissionless and persistent. * [Chipi SDK](https://sdk.chipipay.com/introduction) is an open-source developer toolkit that enables Starknet applications to create non-custodial wallets using any social login (Google, Apple, Telegram, etc.), sponsor transactions via integration with [AVNU's Paymaster](/learn/cheatsheets/integrations#infrastructure), and build with their favourite auth provider with no black boxes. * [Cavos](https://aegis.cavos.xyz/) is a wallet infrastructure service that enables instant wallet creation, gasless transactions, multi-provider authentication, and cross-platform SDKs * [STRK20 by Example](https://strk20-by-example.org/) is a one-stop hub of runnable examples for integrating STRK20 private transfers into apps, covering the [starknet-privacy SDK](https://github.com/starkware-libs/starknet-privacy) (deposits, transfers, withdrawals, note discovery), DeFi helpers, and wallet integration. ## AI tools * [Cairo Coder](https://www.cairo-coder.com/) is an intelligent code generation service that uses advanced Retrieval-Augmented Generation (RAG) to understand Cairo's syntax, patterns, and best practices, and provide high-quality, functional Cairo code based on natural language descriptions. * [Starknet Agent](https://agent.starknet.io/), an AI-powered search engine that uses advanced machine learning algorithms to search and understand the Starknet documentation, Cairo Book, and other resources and provide clear and accurate answers to any queries. * [Snak](https://www.starkagent.ai/) is a toolkit for creating AI agents that can interact with the Starknet blockchain, supporting multiple AI providers (including Anthropic, OpenAI, Google Gemini, and Ollama), and available both as an NPM package and a ready-to-use NestJS server with a web interface. * [Eliza Starknet plugin](https://www.npmjs.com/package/@elizaos/plugin-starknet) bridges Starknet blockchain capabilities with the [Eliza](https://github.com/elizaOS/eliza/tree/main) ecosystem, enabling both automated and user-directed interactions with the Starknet blockchain, including token operations, trading, portfolio management, and DeFi integrations. * [Daydreams](https://docs.dreams.fun/) is a generative agent framework for executing tasks across any blockchain or API, enabling AI agents to go beyond simple tasks and achieve complex and long-term objectives such as onchain gaming and DeFi strategies. ## Other tools * [Open Zeppelin Contract Wizard](https://wizard.openzeppelin.com/cairo) is a tool that helps you create smart contracts with Open Zeppelin libraries by easily toggling on and off features for popular smart contract patterns. * [Walnut](https://walnut.dev/) is a transaction debugger and simulator for Starknet that supports Starknet Mainnet, Starknet Sepolia and Starknet Appchains and includes transaction call trace analysis, visual transaction step by step debugger, and transaction simulator. * [Starknet Devnet JS](https://github.com/0xSpaceShard/starknet-devnet-js) is a JavaScript package that abstracts the Starknet Devnet API, making it easier to interact with it and write end-to-end tests for L1\<>L2 communications. * [Cairo Playground](https://www.cairo-lang.org/cairovm/) is an online tool that can be used to both experiment with Cairo without deploying a smart contract on Starknet, as well as dive deep into the Cairo virtual machine. * [Stark Utils](https://www.stark-utils.xyz/converter) is a simple web application that aims to be a toolbox for Cairo developers, allowing you to convert any input to a felt, string, hexadecimal value, and more. * [Katana](https://book.dojoengine.org/toolchain/katana) is an extremely fast devnet designed to support local development with the [Dojo Starknet gaming engine](https://github.com/dojoengine/dojo) but can be used as a general purpose devnet as well. * [Starkli](https://book.starkli.rs/) is a fast, easy to install, and intuitive command line tool for interacting with Starknet, allowing to query Starknet and make transactions with ease. * [Universal Sierra Compiler](https://github.com/software-mansion/universal-sierra-compiler) is a utility tool for compiling single Sierra files (unlike Scarb, which compiles full projects) from any Sierra version into CASM. <Note> Universal Sierra Compiler is bundled with Starknet Foundry and does not need to be installed separately if Starknet Foundry is installed. </Note> * [Cairo Profiler](https://github.com/software-mansion/cairo-profiler) is a utility tool that can be used to create profiles of Cairo executions from execution traces, which can be analyzed and used to show flame graphs and other useful information. <Note> Cairo Profiler is bundled with Starknet Foundry and does not need to be installed separately if Starknet Foundry is installed. </Note> * [Cairo Lint](https://github.com/software-mansion/cairo-lint) is a collection of lints that can either be used as either a library or as a standalone binary to help both detect and fix common mistakes and improve your Cairo code. <Note> Cairo Lint is bundled with Scarb and does not need to be installed separately if Starknet Foundry is installed. </Note> * [Starknet Contract Verifier](https://github.com/NethermindEth/starknet-contract-verifier) is a client for the Voyager Starknet block explorer that allows verifying Starknet contract classes. <Note> Starknet Contract Verifier is bundled with Starknet Foundry and does not need to be installed separately if Starknet Foundry is installed. </Note> # Transaction fields and hash calculations Source: https://docs.starknet.io/learn/cheatsheets/transactions-reference <Tip> To review how transaction appear in the Starknet API, see [starknet\_api\_openrpc.json](https://github.com/starkware-libs/starknet-specs/blob/b5c43955b1868b8e19af6d1736178e02ec84e678/api/starknet_api_openrpc.json). </Tip> ## `INVOKE` v3 ### Transaction fields | Field name | Type | Description | | - | - | - | | `chain_id` | `FieldElement` | The id of the chain to which the transaction is sent. | | `fee_data_availability_mode` | `FieldElement` | *For future use.*<br /><br />Currently this value is always `0`.<br /><br />For more information, see [SNIP 8: Transaction V3 Structure](https://github.com/starknet-io/SNIPs/blob/main/SNIPS/snip-8.md) | | `nonce` | `FieldElement` | The transaction nonce. | | `nonce_data_availability_mode` | `FieldElement` | *For future use.*<br /><br />Currently this value is always `0`.<br /><br />For more information, see [SNIP 8: Transaction V3 Structure](https://github.com/starknet-io/SNIPs/blob/main/SNIPS/snip-8.md) | | `paymaster_data` | `List<FieldElement>` | *For future use.*<br /><br />Currently this value is always empty.<br /><br />For more information, see [SNIP 8: Transaction V3 Structure](https://github.com/starknet-io/SNIPs/blob/main/SNIPS/snip-8.md) | | `resource_bounds` | `Dict[Resource, ResourceBounds]` | Used for enabling the fee market.<br /><br />A dictionary that maps resource type to resource bounds. The existing resources are L1 gas, L1 data gas, and L2 gas.<br /><br /> ***Resource***<br /><br />A felt. Possible values are the felt representation of the strings `L1_GAS`, `L1_DATA`, or `L2_GAS`.<br /><br />***ResourceBounds***<br /><br />A struct containing the following felts:<br /><br />• `max_amount`: The maximum amount of the resource allowed for usage during the execution.<br /><br />• `max_price_per_unit`: The maximum price the user is willing to pay for the resource. Prices are denominated in fri, where 1 fri = 10<sup>-18</sup> STRK. | | `signature` | `List<FieldElement>` | Additional information given by the sender, used to validate the transaction. For more information, see [Signature](#signature). | | `tip` | `FieldElement` | Used to determine the priority between transactions where the l2gas max\_price\_per\_unit is enough to fit within the block, according to EIP 1559 which Starknet follows since version 0.14.0. | | `version` | `FieldElement` | The transaction's version. When the fields that comprise a transaction change, either with the addition of a new field or the removal of an existing field, then the transaction version increases.<br /><br />Transaction version, where `n` specifies version `n` transaction. For example:<br /><br />3 version 3 transaction | ### Hash calculation The `INVOKE` v3 transaction hash is calculated as a Poseidon hash over the given transaction elements, specifically: ```txt theme={null} invoke_v3_tx_hash = h( "invoke", version, sender_address, h(tip, l1_gas_bounds, l2_gas_bounds, l1_data_gas_bounds), h(paymaster_data), chain_id, nonce, data_availability_modes, h(account_deployment_data), h(calldata) h(proof_facts) ) ``` Where: * `invoke` is a constant prefix string, encoded in ASCII. * `chain_id` is a constant value that specifies the network to which this transaction is sent. For more information, see [Chain ID](#chain_id). * `proof_facts` are included in the hash computation only when present; otherwise, they are omitted. * `l1_gas_bounds` is constructed as follows: $$ \underbrace{\texttt{L1\_GAS}}_{\text{60 bits}} \, | \, \underbrace{\texttt{max\_amount}}_{\text{64 bits}} \, | \, \underbrace{\texttt{max\_price\_per\_unit}}_{\text{128 bits}} $$ * `l2_gas_bounds` is constructed as follows: $$ \underbrace{\texttt{L2\_GAS}}_{\text{60 bits}} \, | \, \underbrace{\texttt{max\_amount}}_{\text{64 bits}} \, | \, \underbrace{\texttt{max\_price\_per\_unit}}_{\text{128 bits}} $$ * `l1_data_gas_bounds` is constructed as follows: $$ \underbrace{\texttt{L1\_DATA}}_{\text{60 bits}} \, | \, \underbrace{\texttt{max\_amount}}_{\text{64 bits}} \, | \, \underbrace{\texttt{max\_price\_per\_unit}}_{\text{128 bits}} $$ * `data_availability_modes` is a concatenation of `fee_data_availability_mode` and `nonce_data_availability_mode`, as follows: $$ \underbrace{\texttt{0...0}}_{\text{188 bits}} \, | \, \underbrace{\texttt{nonce\_data\_availability\
프로젝트로 돌아가기