This repo is a simple demo of how to use aelf-bridge
.
# using npm
npm i
# using yarn
yarn
Since there are two ways Dapp can communicate with the AElf chain, aelf-command
provides the socket
way.
-
start Dapp server in
aelf-command
You need to install
aelf-command
before 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
.env
touch .env
add your own
END_POINT
END_POINT=http://127.0.0.1:8000
-
start webpack
Firstly, init
aelf-bridge
with 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 thedapp
page.There are two pages in this repo, as you can see in the directory
src/pages/
, there aredapp
anddappContainer
.Since Dapp needs to interact with Native apps which holds wallet info, we provide
dappContainer
to support your development. ThinkdappContainer
is a wallet App, which hold the wallet info and can interact withAElf
chain node directly. And it provides the abilities to support Dapp communication. Any Developers can use this page as the Native app to develop Dapp.dappContainer
uses iframe and rewrite iframe'spostMessage
, sodapp
can send messages todappContainer
dapp
is a simple Dapp demo which usesaelf-bridge
to interact withdappContainer
, you can take it as an example and write your own code.