This repo is a simple demo of how to use aelf-bridge.
# using npm
npm i
# using yarn
yarnSince there are two ways Dapp can communicate with the AElf chain, aelf-command provides the socket way.
-
start Dapp server in
aelf-commandYou need to install
aelf-commandbefore next step.npm i aelf-command -g
start the Dapp server
aelf-command dapp-server
by default, the Dapp server will listen on port
35443 -
start webpack
In project directory
npm run dev
open the page
http://0.0.0.0:9527/dapp.html.
-
add chain node url in
.envtouch .env
add your own
END_POINTEND_POINT=http://127.0.0.1:8000
-
start webpack
Firstly, init
aelf-bridgewith post message channeljavascript const bridgeInstance = new AElfBridge();In project directorynpm run dev
open the page
http://0.0.0.0:9527/container.html. When you inspect this page, you can find an iframe inside the HTML, the iframe holds thedapppage.There are two pages in this repo, as you can see in the directory
src/pages/, there aredappanddappContainer.Since Dapp needs to interact with Native apps which holds wallet info, we provide
dappContainerto support your development. ThinkdappContaineris a wallet App, which hold the wallet info and can interact withAElfchain node directly. And it provides the abilities to support Dapp communication. Any Developers can use this page as the Native app to develop Dapp.dappContaineruses iframe and rewrite iframe'spostMessage, sodappcan send messages todappContainerdappis a simple Dapp demo which usesaelf-bridgeto interact withdappContainer, you can take it as an example and write your own code.