This is a demo implementation of CIP-0045 that uses cardano-peer-connect.
Open the dApp.html file and your dev tools to see the console log outputs.
The server (dApp) is just a blank VSCode HTML5 template with the following changes:
- Import cardano-peer-connect in the header
<script src="https://fabianbormann.github.io/cardano-peer-connect/bundle.min.js"></script>
- Create a new DAppPeerConnect instance, plot the QR code and print the address (identifier)
<script>
const dAppConnect = new CardanoPeerConnect.DAppPeerConnect();
dAppConnect.generateQRCode(document.getElementById('qr-code'));
document.getElementById('address').innerText = dAppConnect.getAddress();
</script>
The DAppPeerConnect instance is now waiting for clients to connect. It provides api rpc methods under the hood to allow a client to connect and inject it's api to the global window object.
cd demo-wallet-app
npm i
npm start
Once you have the server and client running you should see something like
[info] [Meerkat]: injected api of boostwallet into window.cardano
in your dApp logs. Now you can issue
window.cardano.boostwallet
.getRewardAddresses()
.then((result) => console.log(result));
to execute the remote call and get the reward address from your Wallet (dApp.html).
The wallet app is actually the result of:
- The blank ionic react template with cardano-peer-connect as an additional npm package
ionic start demo-wallet-app blank --type react
cd demo-wallet-app
npm i @fabianbormann/cardano-peer-connect
-
An Implementation of the abstract class
CardanoPeerConnect
within BoostPeerConnect.tsx (feel free to adjust the name to e.g.[MyWalletName]PeerConnect
) -
BoostPeerConnect is now ready to use. Please see the example usage in Home.tsx
import { BoostPeerConnect } from '../BoostPeerConnect';
...
const connectWithDApp = () => {
const seed = boostPeerConnect.current.connect(
dAppIdentifier,
[
'https://pro.passwordchaos.gimbalabs.io',
'wss://tracker.files.fm:7073/announce',
'wss://tracker.btorrent.xyz',
'ws://tracker.files.fm:7072/announce',
'wss://tracker.openwebtorrent.com:443/announce',
],
localStorage.getItem('meerkat-boostwallet-seed')
);
localStorage.setItem('meerkat-boostwallet-seed', seed);
};
return (
...
<IonInput
onIonChange={(event) =>
setDAppIdentifier(`${event.target.value}`)
}
placeholder="dApp identifier"
></IonInput>
...
<IonButton onClick={connectWithDApp} fill="solid">
Connect
</IonButton>
...
)