Lisk 백서

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

t. See the Prerequisites if you haven't done that yet. Otherwise, the deployment attempt will fail. Finally, run: Lisk Lisk Sepolia npx hardhat run scripts/deploy.ts --network lisk npx hardhat run scripts/deploy.ts --network lisk-sepolia The contract will be deployed on the Lisk Sepolia Testnet. You can view the deployment status and contract by using a block explorer and searching for the address returned by your deploy script. If you're deploying a new or modified contract, you'll need to verify it first. Verifying the Smart Contract ​ If you want to interact with your contract on the block explorer, you, or someone else needs to verify it first. The above contract has already been verified, so you should be able to view your version on a block explorer already. For the remainder of this guide, we'll walk through how to verify your contract on the Lisk Sepolia Testnet. In hardhat.config.ts , configure Lisk Sepolia as a custom network. Add the following to your HardhatUserConfig : Lisk Lisk Sepolia hardhat.config.ts // Add the following information after the "networks" configuration of the HardhatUserConfig const config : HardhatUserConfig = { // Hardhat expects etherscan here, even if you're using Blockscout. etherscan : { // Use "123" as a placeholder, because Blockscout doesn't need a real API key, and Hardhat will complain if this property isn't set. apiKey : { "lisk" : "123" } , customChains : [ { network : "lisk" , chainId : 1135 , urls : { apiURL : "https://blockscout.lisk.com/api" , browserURL : "https://blockscout.lisk.com" } } ] } , sourcify : { enabled : false } , } ; hardhat.config.ts // Add the following information after the "networks" configuration of the HardhatUserConfig const config : HardhatUserConfig = { // Hardhat expects etherscan here, even if you're using Blockscout. etherscan : { // Use "123" as a placeholder, because Blockscout doesn't need a real API key, and Hardhat will complain if this property isn't set. apiKey : { "lisk-sepolia" : "123" } , customChains : [ { network : "lisk-sepolia" , chainId : 4202 , urls : { apiURL : "https://sepolia-blockscout.lisk.com/api" , browserURL : "https://sepolia-blockscout.lisk.com" } } ] } , sourcify : { enabled : false } , } ; Now, you can verify your contract. Grab the deployed address and run: Lisk Lisk Sepolia npx hardhat verify --network lisk < deployed address > npx hardhat verify --network lisk-sepolia < deployed address > You should see an output similar to: Successfully submitted source code for contract contracts/NFT.sol:NFT at 0xC10710ac55C98f9AACdc9cD0A506411FBe0af71D for verification on the block explorer. Waiting for verification result... Successfully verified contract NFT on the block explorer. https://sepolia-blockscout.lisk.com/address/0xC10710ac55C98f9AACdc9cD0A506411FBe0af71D#code info You can't re-verify a contract identical to one that has already been verified. If you attempt to do so, such as verifying the above contract, you'll get a message similar to: The contract 0xC10710ac55C98f9AACdc9cD0A506411FBe0af71D has already been verified on Etherscan. https://sepolia-blockscout.lisk.com/address/0xC10710ac55C98f9AACdc9cD0A506411FBe0af71D#code View your contract on BlockScout, by following the link to the deployed contract displayed in the previous steps output message. The block explorer will confirm that the contract is verified and allow you to interact with it. Interacting with the Smart Contract ​ After the contract is verified , you can use the Read Contract and Write Contract tabs to interact with the deployed contract via BlockScout . Don't forget to update the contract address in the Blockscout URL. You'll also need to connect your wallet first, by clicking the Connect Wallet button. Prerequisites Node v18+ Wallet funds Creating a project Configuring Hardhat with Lisk Creating the contract Compiling the smart contract Testing the contract Setting up the test file Running the Test Deploying the smart contract Verifying the Smart Contract Interacting with the Smart Contract ## /guides/deploying-smart-contract/with-Remix On this page On this page, you will learn how to create, deploy and verify a smart contract with the Remix IDE to the Lisk Sepolia testnet. Remix Online IDE is a powerful toolset for developing, deploying, debugging, and testing Ethereum and EVM-compatible smart contracts. It requires no setup and can be accessed directly through the browser under https://remix.ethereum.org/ . Prerequisites ​ Wallet funds ​ Deploying contracts to the blockchain requires a gas fee . Therefore, you will need to fund your wallet with ETH to cover those gas fees. For this guide, you will be deploying a contract to the Lisk Sepolia Testnet. You can deposit the required tokens by using the Lisk Bridge . In case your wallet doesn't hold enough SepoliaETH , use one of the available faucets for the Ethereum Sepolia Testnet like https://sepoliafaucet.com to receive free Testnet ETH. Then, use the aforementioned Lisk Bridge to send tokens from the Ethereum Sepolia Testnet to the Lisk Sepolia Testnet . note You can deploy a contract on Lisk Mainnet by adopting the same process. Before deploying to Mainnet, ensure that your wallet has enough ETH. 1. Open Remix ​ Navigate to Remix in your browser. 2. Create a new file ​ Inside the contracts folder, click the 📄 ("Create new file") button to create a new empty Solidity file. You can name this file whatever you'd like, e.g., MyNFT.sol . 3. Copy the example contract ​ Copy the following example contract into your new file to deploy a simple NFT contract, or replace it with your own contract you wish to deploy: // SPDX-License-Identifier: MIT pragma solidity ^ 0.8.28 ; import "@openzeppelin/contracts/token/ERC721/ERC721.sol" ; contract MyNFT is ERC721 { uint256 public currentTokenId ; constructor ( ) ERC721 ( "My NFT" , "MNFT" ) { } function mint ( address recipient ) public returns ( uint256 ) { uint256 newItemId = ++ currentTokenId ; _safeMint ( recipient , newItemId ) ; return newItemId ; } } 4. Compile the contract ​ Please double-check that the compiler version of the Remix IDE matches the compiler version mentioned in the smart contract: pragma solidity ^0.8.28; . Press the green play button at the top to compile the contract. 5. Test the contract ​ To test the contract, we are using the Solidity Unit Testing plugin of the Remix IDE. If you haven't used this plugin before and are not seeing the double-check icon in the sidebar, you first have to activate it from the Remix plugin manager. To start testing, create a new folder called tests at the root level of your Remix workspace. This is the default directory for tests. If you want to change the test directory, you can do so by clicking on the double-check icon and specifying the path in the Test directory field. Next, open the Solidity file which you want to test, then switch to the "Solidity Unit Testing" plugin and click on the Generate button. This will create a test file (e.g., myNFT_test.sol) in the tests directory. This file contains information about developing tests for a contract. Below is an example of a generic test file myNFT_test.sol : // SPDX-License-Identifier: GPL-3.0 pragma solidity >= 0.4.22 < 0.9.0 ; // This import is automatically injected by Remix import "remix_tests.sol" ; // This import is required to use custom transaction context // Although it may fail compilation in 'Solidity Compiler' plugin // But it will work fine in 'Solidity Unit Testing' plugin import "remix_accounts.sol" ; import "../contracts/MyNFT.sol" ; // File name has to end with '_test.sol', this file can contain more than one testSuite contracts contract testSuite { /// 'beforeAll' runs before all other tests /// More special functions are: 'beforeEach', 'beforeAll', 'afterEach' & 'afterAll' function beforeAll ( ) public { // <instantiate contract> Assert . equal ( uint ( 1 ) , uint ( 1 ) , "1 should be equal to 1" ) ; } function checkSuccess ( ) public { // Use 'Assert' methods: https://remix-ide.readthedocs.io/en/latest/assert_library.html Assert . ok ( 2 == 2 , 'should be true' ) ; Assert . greaterThan ( uint ( 2 ) , uint ( 1 ) , "2 should be greater than to 1" ) ; Assert . lesserThan ( uint ( 2 ) , uint ( 3 ) , "2 should be lesser than to 3" ) ; } function checkSuccess2 ( ) public pure returns ( bool ) { // Use the return value (true or false) to test the contract return true ; } function checkFailure ( ) public { Assert . notEqual ( uint ( 1 ) , uint ( 1 ) , "1 should not be equal to 1" ) ; } /// Custom Transaction Context: https://remix-ide.readthedocs.io/en/latest/unittesting.html#customization /// #sender: account-1 /// #value: 100 function checkSenderAndValue ( ) public payable { // account index varies 0-9, value is in wei Assert . equal ( msg . sender , TestsAccounts . getAccount ( 1 ) , "Invalid sender" ) ; Assert . equal ( msg . value , 100 , "Invalid value" ) ; } } Take the auto-generated template as a basis to create sufficient unit tests that verify your contract behavior in various scenarios. Remix injects a built-in assert library for testing. You can visit the assert library in the Remix docs. Additionally, Remix allows the usage of special functions in the test file to make testing more structural. They are: beforeEach() - Runs before each test beforeAll() - Runs before all tests afterEach() - Runs after each test afterAll() - Runs after all tests For our new NFT contract, we add the following test: // SPDX-License-Identifier: GPL-3.0 pragma solidity >= 0.4.22 < 0.9.0 ; // This import is automatically injected by Remix import "remix_tests.sol" ; // This import is required to use custom transaction context // Although it may fail compilation in 'Solidity Compiler' plugin // But it will work fine in 'Solidity Unit Testing' plugin import "remix_accounts.sol" ; import "../contracts/MyNFT.sol" ; // File name has to end with '_test.sol', this file can contain more than one testSuite contracts contract testSuite { MyNFT nft ; function beforeAll ( ) public { nft = new MyNFT ( ) ; } // Test minting functionality function testMint ( ) public { // Store initial token ID uint256 initialTokenId = nft . currentTokenId ( ) ; // Mint a new NFT to this contract's address uint256 newTokenId = nft . mint ( TestsAccounts . getAccount ( 2 ) ) ; // Check that token ID incremented Assert . equal ( newTokenId , initialTokenId + 1 , "Token ID should increment by 1" ) ; // Check currentTokenId updated Assert . equal ( nft . currentTokenId ( ) , newTokenId , "currentTokenId should match new token ID" ) ; // Check ownership Assert . equal ( nft . ownerOf ( newTokenId ) , TestsAccounts . getAccount ( 2 ) , "Contract should own the minted NFT" ) ; } // Test minting to specific address function testMintToAddress ( ) public { // Mint NFT to test address uint256 newTokenId = nft . mint ( TestsAccounts . getAccount ( 1 ) ) ; // Check ownership Assert . equal ( nft . ownerOf ( newTokenId ) , TestsAccounts . getAccount ( 1 ) , "Test address should own the minted NFT" ) ; // Check token balance Assert . equal ( nft . balanceOf ( TestsAccounts . getAccount ( 1 ) ) , 1 , "Test address should have 1 NFT" ) ; } } There are several ways to customize your solidity tests. For example, you can customize the compiler and the transaction context . Once you are done with writing tests, select the test file(s) and click on Run to execute the tests. The execution will run in a separate environment. After completing the execution of one file, a test summary will be shown: Result for tests/myNFT_test.sol Passed: 2 Failed: 0 Time Taken: 0.06s 6. Deploy the contract ​ Open the Deploy & run transactions tab (this looks like an Ethereum logo with an arrow pointing right). Make sure that your environment is set to "Injected Provider", your wallet is connected to Lisk or Lisk Sepolia network, and Remix has access to your wallet. Then, select the MyNFT contract from the deployment dropdown and click the orange Deploy button to deploy the contract and confirm the contract deployment in your connected wallet. Check the Remix log messages; they should include the contract address. Paste this address in Blockscout, to see the contract in the Lisk blockchain explorer: https://sepolia-blockscout.lisk.com/address/0x73e7a94dD5760d862F6FD9f8ea5D4245Bb143446 . In case you chose to deploy on the Lisk Mainnet, you need to paste the address on https://blockscout.lisk.com instead. 7. Verify the contract ​ If you want to interact with your contract on the block explorer, you first need to verify it. The above contract has already been verified, so you should be able to view your version on a block explorer already. For the remainder of this guide, we'll walk through how to verify your contract with Remix on the Lisk Sepolia Testnet. You can apply the same steps for verifying a contract on Lisk Mainnet, in case you deployed it there in the previous step, just use https://blockscout.lisk.com instead of https://sepolia-blockscout.lisk.com in step 2. In Remix, right-click on the contract you wish to verify and select Flatten . This will create a new file MyNFT_flattened.sol . Now, switch to your newly deployed contract on https://sepolia-blockscout.lisk.com/ Go to the contract tab and click on the blue Verify and Publish button. (Optional) Set a license for your contract. Choose Solidity (Single file) as the verification method. Choose the compiler version that fits your contract. Disable code optimization. Copy the flattened source code from Remix and paste it into the Enter the Solidity Contract Code field. Check that all info is correct and click the Verify and Publish button, to verify your contract. Once verified, the code tab will include the ✅ icon, and the source code will be viewable. Interacting with the Smart Contract ​ After the contract is verified , you can use the Read Contract and Write Contract tabs to interact with the deployed contract via Blockscout: https://sepolia-blockscout.lisk.com/address/0x73e7a94dD5760d862F6FD9f8ea5D4245Bb143446?tab=contract . Don't forget to update the contract address in the Blockscout URL. You'll also need to connect your wallet first, by clicking the Connect Wallet button. Prerequisites Wallet funds 1. Open Remix 2. Create a new file 3. Copy the example contract 4. Compile the contract 5. Test the contract 6. Deploy the contract 7. Verify the contract Interacting with the Smart Contract ## /guides/deploying-smart-contract/with-thirdweb On this page On this page, you will learn how to create, deploy and verify a smart contract with thirdweb to the Lisk Sepolia testnet. thirdweb is an end-to-end framework for smart contract development and deployment. It enables developers to deploy, standard contracts such as ERC-20, ERC-721, or ERC-1155, etc. without writing a line of code. More of this is discussed in the via thirdweb Explore section. Furthermore, developers looking to develop and deploy custom smart contracts can use the Solidity SDK provided by thirdweb, among others such as TypeScript SDK and Unity SDK . However, for this guide, we will mainly talk about the thirdweb Explore and the Solidity SDK . Features: Explore : Ready to deploy pre-built contracts. Build (Solidity SDK) : Write custom smart contracts. Deploy : Support for contract deployment built for any use case. Publish : Publish your contracts onchain. Deploying pre-built contracts via thirdweb Explore ​ In case you want to deploy a pre-built contract without any customization, thirdweb offers a convenient way to do so with Explore . Check out the following video for a quick introduction to Explore: What is thirdweb Explore ? note Before you try out the following guides, please ensure that your wallet is connected to Lisk's Network and it has sufficient funds in it. For more information, see the Wallet funds section. The following videos describe step-by-step, how to deploy different tokens with pre-built contracts on Lisk. How to deploy a pre-built ERC-20 contract via Explore? How to deploy a pre-built ERC-721 contract via Explore? How to deploy a pre-built ERC-1155 contract via Explore? via Solidity SDK ​ Prerequisites ​ Node.js v18+ ​ Download and install Node v18+ . If you are using nvm to manage your node versions, you can just run nvm install 18 . Installing and Configuring thirdweb ​ To develop custom contracts, it is required to download and configure thirdweb. To install thirdweb run the following command: NPM Yarn npm i -g thirdweb yarn global add thirdweb Set up your thirdweb API key . Logging in with your API key ​ The next step is to log in to thirdweb via CLI, so to do that type the following: thirdweb login Once, you execute the aforementioned command, the terminal will open a browser window where it will ask you to authenticate the device: ....... 💎 thirdweb v0.13.60 💎 Automatically attempting to open a link to authenticate with our dashboard... If the browser doesn't open, please use this link to authenticate: https://thirdweb.com/cli/login?payload=%7B%22payload%22%3A%7B%22type%22%3A%22evm%22%2C%22domain%22%3A%22thirdweb.com%22%2C%22address%22%3A%220x4fA5f77Fadcc319c626b28Ea6260FB0c3Ba6e41C%22%2C%22statement%22%3A%22Please%20ensure%20that%20the%20domain%20above%20matches%20the%20URL%20of%20the%20cuhdksjahjkdhkshajkdhkshakjhsjhdsajkhhdhs ⠙ Waiting for a response from the dashboard Once you authenticate via the browser, the terminal will log the following message: Successfully linked your account to this device You can verify your login status by re-running the thirdweb login command. 💎 thirdweb v0.13.60 💎 Creating a project ​ The first step of deploying smart contracts to Lisk is to set up your development environment by creating a project. The thirdweb supports two of the most popular smart contracts development frameworks such as Foundry and Hardhat . For this guide, we are using Foundry for smart contract development. However, you can use Hardhat if you are more comfortable with that. The project creation steps are similar for both Foundry and Hardhat. For Foundry, install its prerequisites on your system before proceeding with the creation of a thirdweb project. Once, the aforementioned is installed, proceed with the following: npx thirdweb create Choose Contract as the type of your project and give an appropriate name to your project. ....... 💎 thirdweb v0.13.60 💎 ✔ What type of project do you want to create? › Contract ✔ What is your project named? … thirdweb-contracts Next, choose Forge as the framework, NFT as the name of the contract, ERC721 as the type of smart contract, and None for the extensions option. info In case you want to use the Hardhat framework, choose Hardhat instead of Forge in the following dialogue. ✔ What framework do you want to use? › Forge ✔ What will be the name of your new smart contract? … NFT ✔ What type of contract do you want to start from? › ERC721 ✔ What extensions do you want to add to your contract? › None thirdweb will install all the relevant dependencies and set up a contract project for you. Execution logs of the thirdweb contract project creation Creating a new thirdweb contracts project in /Users/XYZ/Lightcurve-Code/L2/thirdweb-contracts. Downloading files. This might take a moment. Installing packages. This might take a couple of minutes. yarn install v1.22.19 warning ../../../package.json: No license field info No lockfile found. [1/4] 🔍 Resolving packages... [2/4] 🚚 Fetching packages... [3/4] 🔗 Linking dependencies... [4
프로젝트로 돌아가기