์คํฌ๋กค Testnet a lance! ๐๐
En ce moment Scroll est dans une Alpha fermรฉ, alors si vous voulez รชtre whitelistรฉ vous devez remplir ce formulaire et Attendre la Confirmation.
์์กด์ฑ
Pour cetutorial tu vas avoir besoin deNodeJs , je vous conseille de le tรฉlรฉcharger avecNVM , aussi on aura besoin deMetamask .
1. Ajoutez ์คํฌ๋กค ๋ ์ด์ด 1 ๋ฐ ๋ ์ด์ด 2 ๋ฐ ๋ฉํ๋ง์คํฌ
๋ ์ด์ด 1 ํ ์คํธ๋ท
Nom du rรฉseau:
Scroll L1 Testnet
RPC์ ๋๋ฒจ URL: https://prealpha.scroll.io/l1
ID ๋ ์ฒด์ธ: 534351
Symbole de la devise: TSETH
URL de l'explorateur de blocs: https://l1scan.scroll.io/
๋ ์ด์ด 2 ํ ์คํธ๋ท
Nom du rรฉseau:
Scroll L2 Testnet
RPC์ ๋๋ฒจ URL: https://prealpha.scroll.io/l2
ID ๋ ์ฒด์ธ: 534354
Symbole de la devise: TSETH
URL de l'explorateur de blocs: https://l2scan.scroll.io/
2. Recevoir du Ether d'une ์๋๊ผญ์ง
๋ฆฌ์ธ๋ฒ ์ฆ
TSETH
๋faucet . Et envoyez des fonds de L1 a L2 a travers lebridge .3. ๋์ธ์ฆ์ ๋ค DApp
ใ . ๋ฅด ์ค๋งํธ ๊ณ์ฝ
Vous pouvez lancer ce smart contract en Remix , Assurez-vous de selectionner a Scroll L2 en Metamask.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
contract HelloWorld {
string public hello = "Hola mundo!";
function setHello(string memory hello_) public
{
hello = hello_;
}
}
๋น. ๋ฅด HTML
Crรฉez le fichier HTML dans un nouveau dossier.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<input id="connect_button" type="button" value="Connect" onclick="connectWallet()" style="display: none"></input>
<p id="web3_message"></p>
<p id="contract_state"></p>
<h1>Hola Mundo! DApp</h1>
<p id="hello"></p>
<input type="input" value="" id="hello_"></input>
<input type="button" value="Set Hello" onclick="_setHello()"></input>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/web3/1.3.5/web3.min.js"></script>
<script type="text/javascript" src="blockchain_stuff.js"></script>
</body>
</html>
<script>
function _setHello()
{
hello_ = document.getElementById("hello_").value
setHello(hello_)
}
</script>
์จ. ๋ฅด ์๋ฐ์คํฌ๋ฆฝํธ
Dans le mรชme dossier ajoutez un fichier Javascript. Remarquez qu'on est on train d'utiliser le rรฉseau
534354
. De plus, rappelez vous de etablir la ๋ณ์HELLO_WORLD_CONTRACT_ADDRESS
avec l'adresse de ton ๊ณ์ฝ.blockchain_stuff.js
const NETWORK_ID = 534354
const HELLO_WORLD_CONTRACT_ADDRESS = "ADDRESS DE TU CONTRATO AQUI"
const HELLO_WORLD_ABI_PATH = "./HelloWorld.json"
var helloWorldContract
var accounts
var web3
function metamaskReloadCallback() {
window.ethereum.on('accountsChanged', (accounts) => {
document.getElementById("web3_message").textContent="Account changed, refreshing...";
window.location.reload()
})
window.ethereum.on('networkChanged', (accounts) => {
document.getElementById("web3_message").textContent="Network changed, refreshing...";
window.location.reload()
})
}
const getWeb3 = async () => {
return new Promise((resolve, reject) => {
if(document.readyState=="complete")
{
if (window.ethereum) {
const web3 = new Web3(window.ethereum)
window.location.reload()
resolve(web3)
} else {
reject("must install MetaMask")
document.getElementById("web3_message").textContent="Error: Please connect to metamask";
}
}else
{
window.addEventListener("load", async () => {
if (window.ethereum) {
const web3 = new Web3(window.ethereum)
resolve(web3)
} else {
reject("must install MetaMask")
document.getElementById("web3_message").textContent="Error: Please install Metamask";
}
});
}
});
};
const getContract = async (web3, address, abi_path) => {
const response = await fetch(abi_path);
const data = await response.json();
const netId = await web3.eth.net.getId();
contract = new web3.eth.Contract(
data,
address
);
return contract
}
async function loadDapp() {
metamaskReloadCallback()
document.getElementById("web3_message").textContent="Please connect to Metamask"
var awaitWeb3 = async function () {
web3 = await getWeb3()
web3.eth.net.getId((err, netId) => {
if (netId == NETWORK_ID) {
var awaitContract = async function () {
helloWorldContract = await getContract(web3, HELLO_WORLD_CONTRACT_ADDRESS, HELLO_WORLD_ABI_PATH)
document.getElementById("web3_message").textContent="You are connected to Metamask"
onContractInitCallback()
web3.eth.getAccounts(function(err, _accounts){
accounts = _accounts
if (err != null)
{
console.error("An error occurred: "+err)
} else if (accounts.length > 0)
{
onWalletConnectedCallback()
} else
{
document.getElementById("connect_button").style.display = "block"
}
});
};
awaitContract();
} else {
document.getElementById("web3_message").textContent="Please connect to Arbitrum Testnet";
}
});
};
awaitWeb3();
}
async function connectWallet() {
await window.ethereum.request({ method: "eth_requestAccounts" })
accounts = await web3.eth.getAccounts()
onWalletConnectedCallback()
}
loadDapp()
const onContractInitCallback = async () => {
var hello = await helloWorldContract.methods.hello().call()
document.getElementById("hello").textContent = hello;
}
const onWalletConnectedCallback = async () => {
}
//// Functions ////
const setHello = async (hello_) => {
const result = await helloWorldContract.methods.setHello(hello_)
.send({ from: accounts[0], gas: 0, value: 0 })
.on('transactionHash', function(hash){
document.getElementById("web3_message").textContent="Executing...";
})
.on('receipt', function(receipt){
document.getElementById("web3_message").textContent="Success."; })
.catch((revertReason) => {
console.log("ERROR! Transaction reverted: " + revertReason.receipt.transactionHash)
});
}
๋. ๋ฅด JSON ABI
Finalement ajoutez le fichier JSON ABI.
HelloWorld.json
[
{
"inputs": [
{
"internalType": "string",
"name": "hello_",
"type": "string"
}
],
"name": "setHello",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "hello",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
}
]
4. ์์ธ์ด์ฆ ๋ฅด ์ฌ์ดํธ ์น
npm install -g lite-server
lite-server
Allez a
localhost:3000
์ ๋ธ๋ผ์ฐ์ ๋ DApp์ ์ฌ์ฉํฉ๋๋ค.
Reference
์ด ๋ฌธ์ ์ ๊ดํ์ฌ(์คํฌ๋กค Testnet a lance! ๐๐), ์ฐ๋ฆฌ๋ ์ด๊ณณ์์ ๋ ๋ง์ ์๋ฃ๋ฅผ ๋ฐ๊ฒฌํ๊ณ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ ๋ณด์๋ค https://dev.to/turupawn/scroll-testnet-a-lance-1i6jํ ์คํธ๋ฅผ ์์ ๋กญ๊ฒ ๊ณต์ ํ๊ฑฐ๋ ๋ณต์ฌํ ์ ์์ต๋๋ค.ํ์ง๋ง ์ด ๋ฌธ์์ URL์ ์ฐธ์กฐ URL๋ก ๋จ๊ฒจ ๋์ญ์์ค.
์ฐ์ํ ๊ฐ๋ฐ์ ์ฝํ ์ธ ๋ฐ๊ฒฌ์ ์ ๋ (Collection and Share based on the CC Protocol.)
์ข์ ์นํ์ด์ง ์ฆ๊ฒจ์ฐพ๊ธฐ
๊ฐ๋ฐ์ ์ฐ์ ์ฌ์ดํธ ์์ง
๊ฐ๋ฐ์๊ฐ ์์์ผ ํ ํ์ ์ฌ์ดํธ 100์ ์ถ์ฒ ์ฐ๋ฆฌ๋ ๋น์ ์ ์ํด 100๊ฐ์ ์์ฃผ ์ฌ์ฉํ๋ ๊ฐ๋ฐ์ ํ์ต ์ฌ์ดํธ๋ฅผ ์ ๋ฆฌํ์ต๋๋ค