bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 13쪽 중 6쪽
egal word in hello message:
${
found
.
toString
(
)
}
`
)
;
}
else
{
context
.
logger
.
info
(
"==== NOT FOUND: Message contains no blacklisted words ===="
)
;
validation
=
{
status
:
VerifyStatus
.
OK
}
;
}
return
validation
;
}
public
async
execute
(
context
:
CommandExecuteContext
<
Params
>
)
:
Promise
<
void
>
{
// 1. Get account data of the sender of the Hello transaction.
const
{
senderAddress
}
=
context
.
transaction
;
// 2. Get message and counter stores.
const
messageSubstore
=
this
.
stores
.
get
(
MessageStore
)
;
const
counterSubstore
=
this
.
stores
.
get
(
CounterStore
)
;
// 3. Save the Hello message to the message store, using the senderAddress as key, and the message as value.
await
messageSubstore
.
set
(
context
,
senderAddress
,
{
message
:
context
.
params
.
message
,
}
)
;
// 3. Get the Hello counter from the counter store.
let
helloCounter
:
CounterStoreData
;
try
{
helloCounter
=
await
counterSubstore
.
get
(
context
,
counterKey
)
;
}
catch
(
error
)
{
helloCounter
=
{
counter
:
0
,
}
}
// 5. Increment the Hello counter +1.
helloCounter
.
counter
+=
1
;
// 6. Save the Hello counter to the counter store.
await
counterSubstore
.
set
(
context
,
counterKey
,
helloCounter
)
;
// 7. Emit a "New Hello" event
const
newHelloEvent
=
this
.
events
.
get
(
NewHelloEvent
)
;
newHelloEvent
.
add
(
context
,
{
senderAddress
:
context
.
transaction
.
senderAddress
,
message
:
context
.
params
.
message
}
,
[
context
.
transaction
.
senderAddress
]
)
;
}
}
hello_liskl2/src/Hello.sol
// SPDX-License-Identifier: MIT
// compiler version must be greater than or equal to 0.8.20 and less than 0.9.0
pragma
solidity
^
0.8.20
;
contract
Hello
{
/** State variables */
// State variable for the Hello messages
mapping
(
address
=>
string
)
public
message
;
// State variable for the message counter
uint32
public
counter
=
0
;
// Address of the contract owner
address
public
immutable owner
;
// Blacklist of words that are not allowed in the Hello message
string
[
]
public
blacklist
=
[
"word1"
,
"word2"
]
;
// Maximum length of the Hello message
uint32
public
maxLength
=
200
;
// Minimum length of the Hello message
uint32
public
minLength
=
3
;
constructor
(
)
{
// Set the transaction sender as the owner of the contract.
owner
=
msg
.
sender
;
}
/** Modifiers */
// Modifier to check that the caller is the owner of the contract.
modifier
onlyOwner
(
)
{
require
(
msg
.
sender
==
owner
,
"Not owner"
)
;
_
;
}
// Validate message length
modifier
validLength
(
string
memory
_message
)
{
require
(
bytes
(
_message
)
.
length
>=
minLength
,
"Message too short"
)
;
require
(
bytes
(
_message
)
.
length
<=
maxLength
,
"Message too long"
)
;
_
;
}
// Validate message content
modifier
validWords
(
string
memory
_message
)
{
bytes
memory
whereBytes
=
bytes
(
_message
)
;
for
(
uint
h
=
0
;
h
<
blacklist
.
length
;
h
++
)
{
bool
found
=
false
;
bytes
memory
whatBytes
=
bytes
(
blacklist
[
h
]
)
;
for
(
uint
i
=
0
;
i
<=
whereBytes
.
length
-
whatBytes
.
length
;
i
++
)
{
bool
flag
=
true
;
for
(
uint
j
=
0
;
j
<
whatBytes
.
length
;
j
++
)
if
(
whereBytes
[
i
+
j
]
!=
whatBytes
[
j
]
)
{
flag
=
false
;
break
;
}
if
(
flag
)
{
found
=
true
;
break
;
}
}
require
(
!
found
,
"Message contains blacklisted word"
)
;
}
_
;
}
/** Events */
// Event for new Hello messages
event
NewHello
(
address
indexed
sender
,
string
message
)
;
/** Functions */
// Function to configure the blacklist
function
setBlacklist
(
string
[
]
memory
_newBlackList
)
public
onlyOwner
{
blacklist
=
_newBlackList
;
}
// Function to configure min/max message length
function
setMinMaxMessageLength
(
uint32
_newMinLength
,
uint32
_newMaxLength
)
public
onlyOwner
{
minLength
=
_newMinLength
;
maxLength
=
_newMaxLength
;
}
// Function to create a new Hello message
function
createHello
(
string
calldata
_message
)
public
validLength
(
_message
)
validWords
(
_message
)
{
message
[
msg
.
sender
]
=
_message
;
counter
+=
1
;
emit
NewHello
(
msg
.
sender
,
_message
)
;
}
}
Endpoints
Migrate the module endpoints by implementing corresponding
view functions
in the contract as shown below.
Lisk L1
Lisk L2
hello_client/src/app/modules/hello/endpoint.ts
export
class
HelloEndpoint
extends
BaseEndpoint
{
public
async
getHelloCounter
(
ctx
:
ModuleEndpointContext
)
:
Promise
<
CounterStoreData
>
{
const
counterSubStore
=
this
.
stores
.
get
(
CounterStore
)
;
const
helloCounter
=
await
counterSubStore
.
get
(
ctx
,
counterKey
,
)
;
return
helloCounter
;
}
public
async
getHello
(
ctx
:
ModuleEndpointContext
)
:
Promise
<
MessageStoreData
>
{
const
messageSubStore
=
this
.
stores
.
get
(
MessageStore
)
;
const
{
address
}
=
ctx
.
params
;
if
(
typeof
address
!==
'string'
)
{
throw
new
Error
(
'Parameter address must be a string.'
)
;
}
cryptography
.
address
.
validateLisk32Address
(
address
)
;
const
helloMessage
=
await
messageSubStore
.
get
(
ctx
,
cryptography
.
address
.
getAddressFromLisk32Address
(
address
)
,
)
;
return
helloMessage
;
}
}
For simple getters, it is sufficient to add the
public
visibility modifier
to the state variables (see
storage
).
Public state variables can be accessed directly from external parties, without implementing the corresponding view function.
Next steps
Now that we re-implemented the Hello module from Lisk L1 as a smart contract in Lisk L2, it is possible to directly deploy the Hello contract to Lisk L2 and interact with it.
Before deploying the smart contract to Lisk, it is recommended to
test it locally
by writing corresponding tests for the newly created smart contract.
Once the smart contract is
deployed
to Lisk, you can interact with it by calling its public functions.
Finally, you can migrate the plugins and UI of the Lisk L1 Hello app to be compatible with the new API, to complete the migration process of your Lisk application.
Testing the smart contract
By testing the smart contract, you can verify that the smart contract behaves as expected and that it is free of bugs, before deploying it to Lisk.
Foundry provides a testing framework to support you in writing tests for smart contracts.
See
Tests - Foundry Book
for examples and references regarding the testing framework.
To test the Hello smart contract, create a new file
Hello.t.sol
under
test/
, and add the following content:
Hello.t.sol
hello_liskl2/test/Hello.t.sol
// SPDX-License-Identifier: UNLICENSED
pragma
solidity
^
0.8.20
;
import
{
Test
,
console
}
from
"forge-std/Test.sol"
;
import
{
Hello
}
from
"../src/Hello.sol"
;
contract
HelloTest
is
Test
{
Hello
public
hello
;
address
alice
=
makeAddr
(
"alice"
)
;
event
NewHello
(
address
indexed
sender
,
string
message
)
;
function
setUp
(
)
public
{
hello
=
new
Hello
(
)
;
}
function
test_CreateHello
(
)
public
{
string
memory
message
=
"Hello World"
;
// Expect NewHello event
vm
.
expectEmit
(
true
,
false
,
false
,
false
)
;
emit
NewHello
(
address
(
alice
)
,
message
)
;
// Create a new Hello message
hoax
(
alice
,
100
ether
)
;
hello
.
createHello
(
message
)
;
// Check the message
assertEq
(
hello
.
message
(
alice
)
,
message
)
;
// Check if counter = 1
assertEq
(
hello
.
counter
(
)
,
1
)
;
}
function
test_MinLength
(
)
public
{
vm
.
expectRevert
(
"Message too short"
)
;
hello
.
createHello
(
"Hi"
)
;
}
function
test_MaxLength
(
)
public
{
vm
.
expectRevert
(
"Message too long"
)
;
hello
.
createHello
(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean porta neque eget elit tristique pharetra. Pellentesque tempus sollicitudin tortor, ut tempus diam. Nulla facilisi. Donec at neque sapien."
)
;
}
function
test_Blacklist
(
)
public
{
vm
.
expectRevert
(
"Message contains blacklisted word"
)
;
hello
.
createHello
(
"Hello word1"
)
;
}
function
test_SetBlacklist
(
)
public
{
// Create a temporary dynamic array of strings
string
[
]
memory
bl
=
new
string
[
]
(
3
)
;
bl
[
0
]
=
"word1"
;
bl
[
1
]
=
"word3"
;
bl
[
2
]
=
"word4"
;
hello
.
setBlacklist
(
bl
)
;
string
[
]
memory
getBL
=
new
string
[
]
(
2
)
;
getBL
[
0
]
=
hello
.
blacklist
(
0
)
;
getBL
[
1
]
=
hello
.
blacklist
(
1
)
;
assertEq
(
getBL
[
0
]
,
bl
[
0
]
)
;
assertEq
(
getBL
[
1
]
,
bl
[
1
]
)
;
}
function
test_SetBlacklistNotOwner
(
)
public
{
string
[
]
memory
bl
=
new
string
[
]
(
3
)
;
bl
[
0
]
=
"word1"
;
bl
[
1
]
=
"word3"
;
bl
[
2
]
=
"word4"
;
vm
.
expectRevert
(
"Not owner"
)
;
hoax
(
alice
,
100
ether
)
;
hello
.
setBlacklist
(
bl
)
;
}
function
test_SetMinMaxMessageLength
(
)
public
{
uint32
newMin
=
1
;
uint32
newMax
=
500
;
hello
.
setMinMaxMessageLength
(
newMin
,
newMax
)
;
assertEq
(
hello
.
minLength
(
)
,
newMin
)
;
assertEq
(
hello
.
maxLength
(
)
,
newMax
)
;
}
function
test_SetMinMaxMessageLengthNotOwner
(
)
public
{
uint32
newMin
=
1
;
uint32
newMax
=
500
;
hoax
(
alice
,
100
ether
)
;
vm
.
expectRevert
(
)
;
hello
.
setMinMaxMessageLength
(
newMin
,
newMax
)
;
}
}
To run the tests, execute the following command:
forge
test
The output should look like this:
Running 8 tests for test/Hello.t.sol:HelloTest
[PASS] test_Blacklist() (gas: 23772)
[PASS] test_CreateHello() (gas: 66179)
[PASS] test_MaxLength() (gas: 14179)
[PASS] test_MinLength() (gas: 13929)
[PASS] test_SetBlacklist() (gas: 885276)
[PASS] test_SetBlacklistNotOwner() (gas: 16978)
[PASS] test_SetMinMaxMessageLength() (gas: 853243)
[PASS] test_SetMinMaxMessageLengthNotOwner() (gas: 10889)
Test result: ok. 8 passed; 0 failed; 0 skipped; finished in 3.35ms
Smart contract deployment
You can now deploy the smart contract to Lisk.
For this example, we will use the Lisk Sepolia network to deploy the Hello contract.
However, the steps are the same for Lisk network as well.
Add the
--verify
flag to the
forge create
command to directly verify the smart contract on BlockScout.
Lisk
Lisk Sepolia
forge create --rpc-url https://rpc.api.lisk.com
\
--etherscan-api-key
123
\
--verify
\
--verifier
blockscout
\
--verifier-url https://blockscout.lisk.com/api
\
--private-key
<
your-private-key
>
\
src/Hello.sol:Hello
forge create --rpc-url https://rpc.sepolia-api.lisk.com
\
--etherscan-api-key
123
\
--verify
\
--verifier
blockscout
\
--verifier-url https://sepolia-blockscout.lisk.com/api
\
--private-key
<
your-private-key
>
\
src/Hello.sol:Hello
If the deployment went successfully, the output should look like this:
[⠢] Compiling...
No files changed, compilation skipped
Deployer: 0x3C46A11471f285E36EE8d089473ce98269D1b081
Deployed to: 0x0a5A1C81F278cAe80d340a4A97E2D7B1c3Ec511a
Transaction hash: 0x52bb6aab8ceeecef674253ecc0ccfe35baeac7db3cc8e889a9da1f7cf1ce0593
Starting contract verification...
Waiting for blockscout to detect contract deployment...
Start verifying contract `0x0a5A1C81F278cAe80d340a4A97E2D7B1c3Ec511a` deployed on 4202
Submitting verification for [src/Hello.sol:Hello] 0x0a5A1C81F278cAe80d340a4A97E2D7B1c3Ec511a.
Submitted contract for verification:
Response: `OK`
GUID: `0a5a1c81f278cae80d340a4a97e2d7b1c3ec511a65cf6f72`
URL: https://sepolia-blockscout.lisk.com/address/0x0a5a1c81f278cae80d340a4a97e2d7b1c3ec511a
Contract verification status:
Response: `OK`
Details: `Pending in queue`
Contract verification status:
Response: `OK`
Details: `Pass - Verified`
Contract successfully verified
After the smart contract is deployed, you can interact with it by calling its public functions.
From here, you can migrate the plugins and UI of the Lisk L1 app to be compatible with the new API, to complete the migration process of your Lisk application.
Footnotes
No direct equivalent in solidity.
Please investigate for custom solutions to migrate logic residing in the lifecycle hooks.
↩
Requirements
Project setup
Module migration
Table: Lisk L1/L2 comparison
Storage
Events
State transition logic
Endpoints
Next steps
Testing the smart contract
Smart contract deployment
## /lisk-l1/claiming
On this page
Everyone who held tokens on the Lisk L1 chain is entitled to claim the exact same amount of LSK on Lisk L2.
This guide explains step-by-step, how to complete the claiming process.
info
Lisk token holders have a
2-year window starting May 21st, 2024
to claim and migrate their tokens to Lisk L2.
Requirements
To claim your LSK tokens on Lisk L2, you need the following:
An account on the Lisk L1 legacy chain, with some LSK tokens.
The account must hold some LSK tokens at the snapshot height
24,823,618
.
The amount of LSK tokens you can claim on Lisk L2 is the same as the amount you held on Lisk L1 at the snapshot height.
Latest version of the
Lisk Migration Wallet
installed (3.0.3)
An account on Lisk L2 with a small amount of ETH, to pay for the gas fees.
If you need to bridge ETH tokens from Ethereum to Lisk, please refer to one of the available
bridges
.
If you have a Ledger hardware wallet, you need the latest version of the Lisk app installed (Lisk legacy 4.0.0).
Claiming process step-by-step
note
This guide is for regular accounts.
If you have a multisignature account, please refer to the
multisignature claiming guide
.
Open the
Claim Tokens page on the Lisk Portal
in the browser.
If you haven't already, connect your wallet with the portal on the top right corner.
On the
Claim Tokens page
, click the
Connect Lisk account
button.
This will open a WalletConnect prompt.
Copy the connection URI by clicking the button next to
Connect your wallet
.
Open the
Lisk Migration Wallet
and sign in with the account you intend to migrate.
Make sure you have the latest version of the Lisk Migration Wallet installed (3.0.3).
You can verify the version by clicking on the
Lisk
>
About
button in the wallet menu.
Go to the
Applications
page and click on the
Wallet connections
tab.
Now, click the
Connect Wallet
button.
Paste the connection URI you just copied in step 3 and press
Connect
.
This will open a prompt showing all your available accounts.
Select the account you wish to migrate the LSK tokens from and click the
Connect
button.
Now go back to the
Lisk Portal
, you will see it shows the amount of LSK from your L1 account you selected in step 8, ready to be claimed.
Click the
Sign message
button, which will take you back to
Lisk Migration Wallet
, where you need to sign the migration message on Lisk L1.
Click the
Continue
button twice and confirm by entering your password, to sign the migration message on Lisk L1.
When you see the transaction receipt in the window, close it to complete the process.
warning
You will need a small amount of
ETH
on Lisk L2 to pay the
gas fees
for the claiming transaction in the next step.
To bridge ETH from Ethereum to Lisk, you can use one of the available
bridges
.
Go back to the
Lisk Portal
.
You will see that the
Sign message
button has changed to
Submit Claim
.
Click the button to finalize the claiming process on Lisk L2.
This will open a wallet prompt, where you can verify the claim you intend to make.
Click
Confirm
to complete the claiming of your LSK tokens.
That's it! 🎉 You have now successfully claimed your Lisk L1 LSK tokens on Lisk L2.
After you complete the claiming process, you can check the
transaction receipt
on the claiming page in the Lisk Portal, to verify that the claiming of the LSK tokens was executed successfully.
To see your newly migrated LSK token balance on Lisk L2, you can check your account balance on
BlockScout
by entering your account address and clicking on the
Tokens
tab.
tip
If you wish to see your LSK token balance in MetaMask directly, it is possible to
import the LSK token to MetaMask
.
Requirements
Claiming process step-by-step
## /guides/add-token-to-lisk
On this page
This page is intended for token issuers who already have an ERC-20 contract deployed on Ethereum and would like to submit their token for bridging between Ethereum and Lisk.
Lisk uses the Superchain Token List as a reference for tokens that have been deployed on Lisk.
In case you want to create a new token on Lisk, please refer to the page
Token development
.
Superchain Token List
The
Superchain Token List
exists to help users discover the correct bridged token addresses for any given native token.
Consider checking this list to make sure that you're not using the wrong bridged representation of a token when bridging a native token.
warning
Lisk does not endorse any of the tokens that are listed in the
ethereum-optimism.github.io
repository and relies on the preliminary checks put in place, listed on the repository.
Developers who are creating their own bridged tokens should consider
adding their token to the list
.
Tokens on the Superchain Token List will automatically appear on certain tools like the
Superchain Bridges UI
.
However, tokens are not necessarily listed on the
Lisk Bridge UI
; their listing is neither guaranteed nor automatic.
Lisk Bridge reviews are conducted manually by the Lisk team.
The Standard Bridge
Before a token native to one chain can be bridged to the other chain, a bridged representation of that token must be created on the receiving side.
The
Standard Bridge
allows users to convert tokens that are native to one chain (like Ethereum) into a representation of those tokens on the other chain (like Lisk).
Users can then convert these bridged representations back into their original native tokens at any time.
tip
This bridging mechanism functions identically in both directions — tokens native to Lisk can be bridged to Ethereum, just like tokens native to Ethereum can be bridged to Lisk.
A bridged representation of a token is an ERC-20 token that implements the
IOptimismMintableERC20
1
interface.
A native token may have more than one bridged representation at the same time.
Users must always specify which bridged token they wish to use when using the bridge; see
Superchain Token List
.
Different bridged representations of the same native token are considered entirely independent tokens.
The Standard Bridge is a simple smart contract, with the functionality to move ERC-20 tokens between Lisk and Ethereum.
The protocol consists of two pertinent contracts:
A bridge contract deployed to
Ethereum
, called
L1StandardBridge
.
A bridge contract deployed to
Lisk
, called
L2StandardBridge
.
These two contracts interact with one another via the
CrossDomainMessenger
system for sending messages between Ethereum and Lisk.
Adding your token to the Superchain Token List
Lisk uses the
Superchain Token List
as a reference for tokens that have been deployed on Lisk.
To add your token to the list, perform the following steps.
Step 1: Deploy your token on Lisk
Select your preferred bridging framework and use it to deploy an ERC-20 for your token on Lisk.
We recommend you use the framework provided by Lisk's
standard bridge
contracts and, furthermore, deploy your token using the
OptimismMintableERC20Factory
.
Deploying your token on Lisk in this manner provides us with guarantees that will smooth the approval process.
If you choose a different bridging framework, its interface must be compatible with that of the standard bridge.
Otherwise, it may be difficult for us to support them.
For step-by-step instructions on how to deploy ERC-20 tokens on Lisk, check the following guides:
Deploying a Standard ERC-20 token
Deploying a Custom ERC-20 token
Step 2: Submit details of your token
Follow the instructions in the
GitHub repository
and submit a PR containing the required details for your token.
Especially, follow the Lisk-specific i프로젝트로 돌아가기