bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 13쪽 중 13쪽
deploy a new ERC-721 token on Lisk
Further reading
Ethereum Docs: ERC-721
ERC-721 EIP
OpenZeppelin: ERC-721 API
OpenZeppelin: ERC-721 contract
Solidity by example: ERC721
How to implement an ERC-721 market
ERC-1155
The
ERC-1155
is a standard interface for contracts that manage multiple token types.
The distinctive feature of ERC-1155 is that it uses a single smart contract to represent multiple tokens at once.
A single deployed contract may include any combination of fungible tokens, non-fungible tokens or other configurations (e.g. semi-fungible tokens).
This is why its
balanceOf
function differs from ERC-20’s:
it has an additional
id
argument for the identifier of the token that you want to query the balance of.
ERC-1155 accounts have a distinct balance for each token id; non-fungible tokens are implemented by simply minting a single one of them.
This approach leads to massive gas savings for projects that require multiple tokens.
Instead of deploying a new contract for each token type, a single ERC-1155 token contract can hold the entire system state, reducing deployment costs and complexity.
Guides
How to deploy a new ERC-1155 token on Lisk
warning
Please note that there is currently less ecosystem support for ERC-1155 as compared with ERC-20 or ERC-721.
Further reading
Ethereum Docs: ERC-1155
ERC-1155 EIP
OpenZeppelin: ERC-1155 API
OpenZeppelin: ERC-1155 contract
Solidity by example: ERC1155
ERC token standards
ERC-20
Guides
Further reading
ERC-721
Guides
Further reading
ERC-1155
Guides
Further reading
## /guides/token-development/deploy-erc-20
On this page
This guide explains how to deploy a new ERC-20 token to Lisk.
In case you want to bridge an existing token from Ethereum, please refer to the guide
Bridging an L1 token to Lisk
.
note
We will use Remix IDE for smart contract development in this guide, but feel free to choose a
smart contract development framework
of your choice to implement your token contract.
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.,
MyToken.sol
.
3. Copy the example contract
Copy the following example contract into your new file:
// SPDX-License-Identifier: MIT
pragma
solidity
^
0.8.28
;
import
{
ERC20
}
from
"@openzeppelin/contracts/token/ERC20/ERC20.sol"
;
contract
MyToken
is
ERC20
{
constructor
(
string
memory
_name
,
string
memory
_symbol
,
uint256
initialSupply
)
ERC20
(
_name
,
_symbol
)
{
_mint
(
msg
.
sender
,
initialSupply
)
;
}
}
4. Compile the contract
Please double-check that the compiler version of the Remix IDE is matching with 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. 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 the Lisk or Lisk Sepolia network, and Remix has access to your wallet.
Then, select the
MyToken
contract from the deployment dropdown and deploy it with the parameters of your choice, for example:
Name: MyToken
Symbol: MYT
InitalSupply: 1000000000000000000000
Click on the orange
transact
button to deploy the contract.
Finally, 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/0x6e8fF2E042c1637a2Da9563763c62362a3bbD712
In case you chose to deploy on the Lisk Mainnet, you need to paste the address on
https://blockscout.lisk.com
instead.
6. Verify the 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 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
MyToken_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 fitting compiler version for 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.
1. Open Remix
2. Create a new file
3. Copy the example contract
4. Compile the contract
5. Deploy the contract
6. Verify the contract
## /guides/token-development/deploy-erc-721
On this page
note
We will use Remix IDE for smart contract development in this guide, but feel free to choose a
smart contract development framework
of your choice to implement your token contract.
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.
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
## /guides/token-development/deploy-erc-1155
On this page
note
We will use Remix IDE for smart contract development in this guide, but feel free to choose a
smart contract development framework
of your choice to implement your token contract.
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.,
MyItems.sol
.
3. Copy the example contract
Copy the following example contract into your new file:
// SPDX-License-Identifier: MIT
pragma
solidity
^
0.8.28
;
import
"@openzeppelin/contracts/token/ERC1155/ERC1155.sol"
;
contract
MyItems
is
ERC1155
{
uint256
public
constant
GOLD
=
0
;
uint256
public
constant
SILVER
=
1
;
uint256
public
constant
THORS_HAMMER
=
2
;
uint256
public
constant
SWORD
=
3
;
uint256
public
constant
SHIELD
=
4
;
constructor
(
)
ERC1155
(
"https://game.example/api/item/{id}.json"
)
{
_mint
(
msg
.
sender
,
GOLD
,
10
**
18
,
""
)
;
_mint
(
msg
.
sender
,
SILVER
,
10
**
27
,
""
)
;
_mint
(
msg
.
sender
,
THORS_HAMMER
,
1
,
""
)
;
_mint
(
msg
.
sender
,
SWORD
,
10
**
9
,
""
)
;
_mint
(
msg
.
sender
,
SHIELD
,
10
**
9
,
""
)
;
}
}
note
Gold, Silver, Sword, and shield are fungible tokens, whilst Thor’s Hammer is a non-fungible token, as we minted only one.
An URI pointing to the JSON metadata of the different items/ tokens needs to be specified in the constructor, see
ERC-1155 contract API
.
The URI can include the string
{id}
, which clients must replace with the actual token ID, in lowercase hexadecimal (with no 0x prefix) and leading zero-padded to 64 hex characters.
The URI MUST point to a JSON file that conforms to the
ERC-1155 Metadata URI JSON Schema
.
For token ID 2 and uri
https://game.example/api/item/{id}.json
clients would replace
{id}
with
0000000000000000000000000000000000000000000000000000000000000002
to retrieve JSON at
https://game.example/api/item/0000000000000000000000000000000000000000000000000000000000000002.json
.
The JSON document for token ID 2 might look something like:
{
"name"
:
"Thor's hammer"
,
"description"
:
"Mjölnir, the legendary hammer of the Norse god of thunder."
,
"image"
:
"https://game.example/item-id-8u5h2m.png"
,
"strength"
:
20
}
For more information about the metadata JSON Schema, check out the
ERC-1155 Metadata URI JSON Schema
.
4. Compile the contract
Please double-check that the compiler version of the Remix IDE is matching with 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. 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
MyItems
contract from the deployment dropdown and click the orange
Deploy
button to deploy the contract.
Finally, 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/0x8b2f45e810F539647e70fBCd6441B73d332Ef1A0
In case you chose to deploy on the Lisk Mainnet, you need to paste the address on
https://blockscout.lisk.com
instead.
6. Verify the 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 you 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, rightlick on the contract you wish to verify and select
Flatten
.
This will create a new file
MyItems_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 fitting compiler version for 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.
1. Open Remix
2. Create a new file
3. Copy the example contract
4. Compile the contract
5. Deploy the contract
6. Verify the contract
## /tags/nodes
Running a Lisk Node
A tutorial that teaches how to set up and run a Lisk Node.
## /tags
Tags
N
nodes
1프로젝트로 돌아가기