bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 13쪽 중 12쪽
"
:
"bool"
}
]
,
"stateMutability"
:
"view"
,
"type"
:
"function"
}
,
{
"inputs"
:
[
]
,
"name"
:
"symbol"
,
"outputs"
:
[
{
"internalType"
:
"string"
,
"name"
:
""
,
"type"
:
"string"
}
]
,
"stateMutability"
:
"view"
,
"type"
:
"function"
}
,
{
"inputs"
:
[
{
"internalType"
:
"uint256"
,
"name"
:
"tokenId"
,
"type"
:
"uint256"
}
]
,
"name"
:
"tokenURI"
,
"outputs"
:
[
{
"internalType"
:
"string"
,
"name"
:
""
,
"type"
:
"string"
}
]
,
"stateMutability"
:
"view"
,
"type"
:
"function"
}
,
{
"inputs"
:
[
{
"internalType"
:
"address"
,
"name"
:
"from"
,
"type"
:
"address"
}
,
{
"internalType"
:
"address"
,
"name"
:
"to"
,
"type"
:
"address"
}
,
{
"internalType"
:
"uint256"
,
"name"
:
"tokenId"
,
"type"
:
"uint256"
}
]
,
"name"
:
"transferFrom"
,
"outputs"
:
[
]
,
"stateMutability"
:
"nonpayable"
,
"type"
:
"function"
}
]
;
Writing to smart contracts
To write data through a contract's method, a few things are required such as:
contract's address
recipient's address
private key of the sender
... and the method's name
Use the following snippet to interact with an already
deployed contract's
mint()
function.
minting-token.js
// Address of the contract you want to interact with.
const
contractAddress
=
'0x108872F713A27bc22ca1db8CEefCAC8CbeDdF9E5'
;
// Address of the Recipient account receiving the NFT.
const
recipientAddress
=
'RECIPIENT_ADDRESS'
const
amount
=
web3
.
utils
.
toWei
(
'.0001'
,
'ether'
)
// PRIVATE_KEY of the sender's account.
const
privateKey
=
'PRIVATE_KEY'
;
const
account
=
web3
.
eth
.
accounts
.
wallet
.
add
(
privateKey
)
;
// Instantiate the contract object
const
contract
=
new
web3
.
eth
.
Contract
(
abi
,
contractAddress
)
;
// Send a request to the 'mint()' function to mint a token.
const
txReceipt
=
await
contract
.
methods
.
mint
(
recipientAddress
,
amount
)
.
send
(
{
from
:
account
[
0
]
.
address
}
)
;
console
.
log
(
'Tx hash:'
,
txReceipt
.
transactionHash
)
;
Complete code example
minting-token.js
import
{
Web3
}
from
'web3'
;
import
{
abi
}
from
'./abi.js'
;
// Instantiate a web3 object by passing the RPC URL of Lisk.
const
web3
=
new
Web3
(
'https://rpc.sepolia-api.lisk.com'
)
;
// For Lisk network
//const web3 = new Web3('https://rpc.api.lisk.com');
// Address of the contract you want to interact with.
const
contractAddress
=
'0x108872F713A27bc22ca1db8CEefCAC8CbeDdF9E5'
;
// Address of the Recipient account receiving the NFT.
const
recipientAddress
=
'RECIPIENT_ADDRESS'
const
amount
=
web3
.
utils
.
toWei
(
'.0001'
,
'ether'
)
// PRIVATE_KEY of the sender's account.
const
privateKey
=
'PRIVATE_KEY'
;
const
account
=
web3
.
eth
.
accounts
.
wallet
.
add
(
privateKey
)
;
// Instantiate the contract object
const
contract
=
new
web3
.
eth
.
Contract
(
abi
,
contractAddress
)
;
// Send a request to the 'mint()' function to mint a token.
const
txReceipt
=
await
contract
.
methods
.
mint
(
recipientAddress
,
amount
)
.
send
(
{
from
:
account
[
0
]
.
address
}
)
;
console
.
log
(
'Tx hash:'
,
txReceipt
.
transactionHash
)
;
Output
Transaction hash: 0xe654513f453623d9ce329b575985b7fcd09116325d10150d7cd30dcdedc124a9
info
You can use the transaction hash received above to check the details of the
mint
transaction on Blockscout Explorer:
0xe654513f453623d9ce329b575985b7fcd09116325d10150d7cd30dcdedc124a9
.
Install
Import
Connecting to Lisk
Reading data from the blockchain
Writing data to the blockchain
Interacting with smart contracts
Reading from smart contracts
Writing to smart contracts
## /guides/add-token-to-lisk/standard-token
On this page
In this tutorial, you'll learn how to bridge a standard ERC-20 token from Ethereum to Lisk using the
Standard Bridge system
.
This tutorial is meant for developers who already have an existing ERC-20 token on Ethereum and want to create a bridged representation of that token on Lisk.
This tutorial explains how to use the
OptimismMintableERC20Factory
to deploy a standardized ERC-20 token on Lisk or Lisk Sepolia network.
Tokens created by this factory contract are compatible with the Standard Bridge system and include basic logic for deposits, transfers, and withdrawals.
If you want to include specialized logic within your L2 token, see the tutorial on
Bridging Your Custom ERC-20 Token to Lisk
instead.
Dependencies
cast
Prerequisites
note
You can deploy your
Standard ERC-20
token on Lisk Mainnet by adopting the same process.
For deploying to mainnet, ensure that your wallet has enough ETH.
The subsequent text contains commands for both Lisk and Lisk Sepolia for your ease.
For more information, see the
available Lisk networks
and
how to connect a wallet with them
.
Get ETH on Sepolia and Lisk Sepolia
This tutorial explains how to create a bridged ERC-20 token on Lisk Sepolia.
You will need to get some ETH on both of these testnets.
info
You can use
ETH Sepolia Faucet
to get ETH on Sepolia.
You can use the
Superchain Faucet
to get ETH on Lisk Sepolia.
Get an L1 ERC-20 Token Address
You will need an L1 ERC-20 token for this tutorial.
If you already have an L1 ERC-20 token deployed on Ethereum Mainnet or Sepolia, you can skip this step.
For Sepolia, you can use the testing token located at
0x5589BB8228C07c4e15558875fAf2B859f678d129
that includes a
faucet()
function that can be used to mint tokens.
Create an L2 ERC-20 token
Once you have an L1 ERC-20 token, you can use the
OptimismMintableERC20Factory
to create a corresponding L2 ERC-20 token on Lisk or Lisk Sepolia network.
All tokens created by the factory implement the
IOptimismMintableERC20
interface and are compatible with the Standard Bridge system.
To create an L2 ERC-20 token, do the following:
1. Add a private key to your environment
You'll need a private key in order to sign transactions.
Set your private key as an environment variable with the
export
command.
Make sure this private key corresponds to an address that has ETH on Lisk or Lisk Sepolia network.
export
TUTORIAL_PRIVATE_KEY
=
0x
..
.
2. Add the Lisk RPC URL to your environment
You'll need an RPC URL in order to connect to Lisk or Lisk Sepolia network.
Set your RPC URL as an environment variable with the
export
command.
Lisk
Lisk Sepolia
export
TUTORIAL_RPC_URL
=
https://rpc.api.lisk.com
export
TUTORIAL_RPC_URL
=
https://rpc.sepolia-api.lisk.com
3. Add your L1 ERC-20 token address to your environment
You'll need to know the address of your L1 ERC-20 token in order to create a bridged representation of it on Lisk or Lisk Sepolia network.
Set your L1 ERC-20 token address as an environment variable with the
export
command.
# Replace this with your L1 ERC-20 token if not using the testing token!
export
TUTORIAL_L1_ERC20_ADDRESS
=
0x5589BB8228C07c4e15558875fAf2B859f678d129
4. Deploy your L2 ERC-20 token
You can now deploy your L2 ERC-20 token using the
OptimismMintableERC20Factory
.
Use the
cast
command to trigger the deployment function on the factory contract.
This example command creates a token with the name "My Standard Demo Token" and the symbol "L2TKN".
The resulting L2 ERC-20 token address is printed to the console.
cast send 0x4200000000000000000000000000000000000012
"createOptimismMintableERC20(address,string,string)"
$TUTORIAL_L1_ERC20_ADDRESS
"My Standard Demo Token"
"L2TKN"
--private-key
$TUTORIAL_PRIVATE_KEY
--rpc-url
$TUTORIAL_RPC_URL
--json
|
jq
-r
'.logs[0].topics[2]'
|
cast parse-bytes32-address
If all goes well, it will respond with the address of the newly deployed contract:
0x891C582b83F69B7c2d3107cd73A3e491CB33962F
Using factories is
not
recommended for production
Factories make it easy to deploy contracts out of the box.
The downside of this is, that you do not have control over the source code of the contract that is going to be deployed, as this is performed by the factory.
Furthermore, it is not so straightforward to verify those contracts on Blockscout, as the source code of the contract is required for the verification.
Dependencies
Prerequisites
Get ETH on Sepolia and Lisk Sepolia
Get an L1 ERC-20 Token Address
Create an L2 ERC-20 token
1. Add a private key to your environment
2. Add the Lisk RPC URL to your environment
3. Add your L1 ERC-20 token address to your environment
4. Deploy your L2 ERC-20 token
## /guides/add-token-to-lisk/custom-token
On this page
In this tutorial, you will learn how to bridge a custom ERC-20 token from Ethereum or Sepolia to the Lisk or Lisk Sepolia network, respectively.
By using the
Standard Bridge system
, this tutorial is meant for developers who already have an existing ERC-20 token on Ethereum and want to create a bridged representation of that token on Lisk.
Learn step-by-step how you can create a custom token that conforms to the
IOptimismMintableERC20
interface so that it can be used with the Standard Bridge system.
A custom token allows you to do things like trigger extra logic whenever a token is deposited.
If you don't need extra functionality like this, consider following the tutorial on
Deploying your Standard ERC-20 token to Lisk
instead.
Prerequisites
note
You can deploy your
Custom ERC-20
token on Lisk Mainnet by adopting the same process.
For deploying to mainnet, ensure that your wallet has enough ETH.
The subsequent text contains commands for both Lisk and Lisk Sepolia for your ease.
For more information, see the
available Lisk networks
and
how to connect a wallet with them
.
Get ETH on Sepolia and Lisk Sepolia
You will need to get some ETH on both, Sepolia and Lisk Sepolia networks.
info
You can use
ETH Sepolia Faucet
to get ETH on Sepolia.
You can use the
Superchain Faucet
to get ETH on Lisk Sepolia.
Add Lisk Sepolia to Your Wallet
This tutorial uses
Remix
to deploy contracts.
You will need to add the Lisk or Lisk Sepolia network to your wallet in order to follow this tutorial.
Please follow the
How to connect Lisk to a wallet
guide, to connect your wallet to Lisk or Lisk Sepolia network.
Get an L1 ERC-20 Token Address
You will need an L1 ERC-20 token for this tutorial.
If you already have an L1 ERC-20 token deployed on Ethereum Mainnet or Sepolia, you can skip this step.
For Sepolia, you can use the testing token located at
0x5589BB8228C07c4e15558875fAf2B859f678d129
that includes a
faucet()
function that can be used to mint tokens.
Create an L2 ERC-20 Token
Once you have an L1 ERC-20 token, you can create a corresponding L2 ERC-20 token on Lisk or Lisk Sepolia network.
This tutorial uses
Remix
, so you can easily deploy a token without a framework like
Hardhat
or
Foundry
.
You can follow the same general process within your favorite framework if you prefer.
In this section, you'll be creating an ERC-20 token that can be deposited but cannot be withdrawn.
This is just one example of the endless ways in which you could customize your L2 token.
1. Open Remix
Navigate to
Remix
in your browser.
2. Create a new file
Click the 📄 ("Create new file") button to create a new empty Solidity file.
You can name this file whatever you'd like, e.g.
custom-token.sol
.
3. Copy the example contract
Copy the following example contract into your new file:
custom-token.sol
// SPDX-License-Identifier: MIT
pragma
solidity
^
0.8.0
;
import
{
ERC20
}
from
"@openzeppelin/contracts/token/ERC20/ERC20.sol"
;
import
{
IERC165
}
from
"@openzeppelin/contracts/utils/introspection/IERC165.sol"
;
import
{
IOptimismMintableERC20
}
from
"https://github.com/ethereum-optimism/optimism/blob/v1.1.4/packages/contracts-bedrock/src/universal/IOptimismMintableERC20.sol"
;
contract
MyCustomL2Token
is
IOptimismMintableERC20
,
ERC20
{
/// @notice Address of the corresponding version of this token on the remote chain.
address
public
immutable REMOTE_TOKEN
;
/// @notice Address of the StandardBridge on this network.
address
public
immutable BRIDGE
;
/// @notice Emitted whenever tokens are minted for an account.
/// @param account Address of the account tokens are being minted for.
/// @param amount Amount of tokens minted.
event
Mint
(
address
indexed
account
,
uint256
amount
)
;
/// @notice Emitted whenever tokens are burned from an account.
/// @param account Address of the account tokens are being burned from.
/// @param amount Amount of tokens burned.
event
Burn
(
address
indexed
account
,
uint256
amount
)
;
/// @notice A modifier that only allows the bridge to call.
modifier
onlyBridge
(
)
{
require
(
msg
.
sender
==
BRIDGE
,
"MyCustomL2Token: only bridge can mint and burn"
)
;
_
;
}
/// @param _bridge Address of the L2 standard bridge.
/// @param _remoteToken Address of the corresponding L1 token.
/// @param _name ERC20 name.
/// @param _symbol ERC20 symbol.
constructor
(
address
_bridge
,
address
_remoteToken
,
string
memory
_name
,
string
memory
_symbol
)
ERC20
(
_name
,
_symbol
)
{
REMOTE_TOKEN
=
_remoteToken
;
BRIDGE
=
_bridge
;
}
/// @custom:legacy
/// @notice Legacy getter for REMOTE_TOKEN.
function
remoteToken
(
)
public
view
returns
(
address
)
{
return
REMOTE_TOKEN
;
}
/// @custom:legacy
/// @notice Legacy getter for BRIDGE.
function
bridge
(
)
public
view
returns
(
address
)
{
return
BRIDGE
;
}
/// @notice ERC165 interface check function.
/// @param _interfaceId Interface ID to check.
/// @return Whether or not the interface is supported by this contract.
function
supportsInterface
(
bytes4
_interfaceId
)
external
pure
virtual
returns
(
bool
)
{
bytes4
iface1
=
type
(
IERC165
)
.
interfaceId
;
// Interface corresponding to the updated OptimismMintableERC20 (this contract).
bytes4
iface2
=
type
(
IOptimismMintableERC20
)
.
interfaceId
;
return
_interfaceId
==
iface1
||
_interfaceId
==
iface2
;
}
/// @notice Allows the StandardBridge on this network to mint tokens.
/// @param _to Address to mint tokens to.
/// @param _amount Amount of tokens to mint.
function
mint
(
address
_to
,
uint256
_amount
)
external
virtual
override
(
IOptimismMintableERC20
)
onlyBridge
{
_mint
(
_to
,
_amount
)
;
emit
Mint
(
_to
,
_amount
)
;
}
/// @notice Prevents tokens from being withdrawn to L1.
function
burn
(
address
,
uint256
)
external
virtual
override
(
IOptimismMintableERC20
)
onlyBridge
{
revert
(
"MyCustomL2Token cannot be withdrawn"
)
;
}
}
4. Review the example contract
Take a moment to review the example contract.
It's almost the same as the standard
OptimismMintableERC20
contract except that the
_burn
function has been made to always revert.
The contract for the custom token inherits from the
IOptimismMintableERC20
interface and the
ERC20
contract.
The constructor takes the address of the L2 standard bridge, the address of the corresponding L1 token, the name of the ERC20 token, and the symbol of the ERC20 token.
The
mint
function allows the bridge to mint tokens for users.
Since the bridge needs to burn tokens when users want to withdraw them to L1, this means that users will not be able to withdraw tokens from this contract, which is what we intend for this example.
/// @notice Prevents tokens from being withdrawn to L1.
function
burn
(
address
,
uint256
)
external
virtual
override
(
IOptimismMintableERC20
)
onlyBridge
{
revert
(
"MyCustomL2Token cannot be withdrawn"
)
;
}
5. Compile the contract
Save the file to automatically compile the contract.
If you've disabled auto-compile, you'll need to manually compile the contract by clicking the "Solidity Compiler" tab (this looks like the letter "S") and pressing the blue "Compile" button.
6. Deploy the contract
Open the deployment 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
MyCustomL2Token
contract from the deployment dropdown and deploy it with the following parameters:
_BRIDGE: "0x4200000000000000000000000000000000000007"
_REMOTETOKEN: "<L1 ERC-20 address>"
_NAME: "My Custom Lisk L2 Token"
_SYMBOL: "MCL2T"
tip
If you used the testing token described in step
Get an L1 ERC-20 Token Address
, use the address
0x5589BB8228C07c4e15558875fAf2B859f678d129
for the
_REMOTETOKEN
parameter.
Prerequisites
Get ETH on Sepolia and Lisk Sepolia
Add Lisk Sepolia to Your Wallet
Get an L1 ERC-20 Token Address
Create an L2 ERC-20 Token
1. Open Remix
2. Create a new file
3. Copy the example contract
4. Review the example contract
5. Compile the contract
6. Deploy the contract
## /guides/token-development/overview
On this page
This page is intended for token issuers who wish to create a new ERC-20 contract on Lisk.
It includes an explanation of ERCs, a summary of the most important token standards, and examples of how to deploy these tokens on Lisk.
In case you already have a token deployed on the Ethereum network, and wish to bridge it to Lisk, please refer to the guide
Bridging an L1 token to Lisk
.
ERC token standards
A standard interface allows any tokens on Ethereum to be re-used by other applications: from wallets to decentralized exchanges.
ERCs
(Ethereum Request for Comments) are a set of application-level standards and conventions, including contract standards such as token standards (ERC-20), name registries (ERC-137), URI schemes, library/package formats, and wallet formats for the Ethereum blockchain.
Following the most popular ERC token standards when creating a new token has several benefits:
Increased security:
Let your contract inherit from heavily audited and reviewed implementations of the standard, mitigating the possibility of bugs greatly.
High application compatibility:
Most applications only support the most popular ERC token standards. By following these standards, you ensure your token will be compatible with most external applications like wallets or decentralized exchanges.
Great documentation:
Benefit from the vast number of tutorials and guides that are available to develop ERC-compliant tokens.
ERCs are a subcategory of
EIPs
(Ethereum Improvement Proposals).
New EIPs are added following the process outlined in
EIP-1
.
Here's the full list of
ERC proposals
.
A summary of some interesting ERC token standards can be found below.
ERC-20
: the most widespread token standard for fungible tokens, albeit somewhat limited by its simplicity.
ERC-721
: the most popular token standard for non-fungible tokens, often used for collectibles and games.
ERC-1155
: a standard for multi-tokens, allowing for a single contract to represent multiple fungible and non-fungible tokens, along with batched operations for increased gas efficiency.
ERC-20
The most widespread token standard for fungible tokens.
Any token is exactly equal to any other token; no tokens have special rights or behavior associated with them.
This makes
ERC-20
tokens useful for things like a medium of exchange currency, voting rights, staking, and more.
Guides
How to deploy a new ERC-20 token on Lisk
Further reading
Understand the ERC-20 token smart contract
ERC-20 EIP
OpenZeppelin: ERC-20 API
OpenZeppelin: ERC-20 contract
Solidity by example: ERC-20
Ethereum Docs: ERC-20
Alchemy: Complete guide to ERC-20
ERC-721
ERC-721
is a standard for representing ownership of non-fungible tokens.
Non-fungible tokens(NFTs) are used to represent unique objects like real estate or collectibles, where some items are valued more than others due to their usefulness, rarity, or other individual characteristics.
To represent these unique features onchain, the ERC-721 includes metadata properties that offer information about the token's specific features, such as the title, the creator, and an image preview.
Guides
How to 프로젝트로 돌아가기