Frontier เป็นเลเยอร์ความเข้ากันได้ของ Ethereum ของ Substrate ช่วยให้คุณสามารถเรียกใช้ Ethereum dapps ที่ไม่ต้องแก้ไขโค๊ด
เป้าหมายของเลเยอร์ความเข้ากันได้ของ Ethereum คือสามารถ:
เรียกใช้แอปพลิเคชัน web3 ปกติผ่านเลเยอร์ความเข้ากันได้ โดยใช้โหนดในเครื่อง ซึ่งยอมรับไบนารีบริดจ์เพิ่มเติมได้
สามารถนำเข้าสถานะจาก Ethereum mainnet
โดยวิธีการติดตั้งมีตังต่อไปนี้
git clone https://github.com/substrate-developer-hub/frontier-node-template.git
cargo build --release
./target/release/frontier-template-node --dev --tmp --ws-external --rpc-external
จากข้อมูลจำเพาะ Chain ที่รวมอยู่ในโปรเจ็กต์นี้จะกำหนดบล็อกกำเนิด (Genesis Block) จะได้รับการกำหนดค่าล่วงหน้าด้วย EVM สำหรับบัญชี Alice เมื่อเริ่ม Chain บัญชี EVM ของ Alice จะได้รับเงินจาก Ether ซึ่งสามารถใช้ Polkadot UI เพื่อดูรายละเอียดบัญชี EVM ของ Alice
ในการดูบัญชี EVM ให้ใช้แท็บ Developer ของแอพ Polkadot UI Settings เพื่อกำหนดประเภทบัญชี EVM ดังนี้ นอกจากนี้ยังจำเป็นต้องกำหนด Address และ Lookup Source เพื่อส่งธุรกรรม และ Transaction และ Signature เพื่อตรวจสอบบล็อค:
{ "Address": "MultiAddress", "LookupSource": "MultiAddress", "Account": { "nonce": "U256", "balance": "U256" }, "Transaction": { "nonce": "U256", "action": "String", "gas_price": "u64", "gas_limit": "u64", "value": "U256", "input": "Vec<u8>", "signature": "Signature" }, "Signature": { "v": "u64", "r": "H256", "s": "H256" } }
ไปที่แท็บ Developer การโทร RPC ของแอปนักพัฒนาซอฟต์แวร์เพื่อสอบถาม eth > getBalance(ที่อยู่, หมายเลข) ด้วย ID บัญชี EVM ของ Alice (0xd43593c715fdd31c61141abd04a99fd6822c8558); ค่าที่ส่งคืนเป็น:
x: eth.getBalance
340,282,366,920,938,463,463,374,607,431,768,211,455
#ตัวอย่างที่ 1: การปรับใช้สัญญา ERC20 โดยใช้ EVM
1.1 ติดตั้ง NodeJs
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
source ~/.bashrc
nvm install v16
nvm use v16
1.2 ติดตั้ง
#Ref
https://github.com/substrate-developer-hub/frontier-node-template