Package Exports
- @dcspark/adalib
- @dcspark/adalib/dist/adalib.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@dcspark/adalib) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Adalib
Cardano friendly API
Adalib implements a Connector
interface that complies with WalletConnect's standards.
It attempts to closely emulate the CIP-30 standard within the connectors. A dapp developer can use these connectors to retrieve the enabled CIP-30 API, and benefit from the included typings this library provides.
WIP Capabilities
API
- Connect Wallet:
- Flint
- WalletConnect
- Get balance
- Sign Transaction
- Send Transaction
- Sign and send Transaction
- Sign Message
Init
The init function needs to be called to prepare adalib
to be able to call all
the functions in its API.
import {
init,
cardanoMainnetWalletConnect,
FlintConnector,
WalletConnectConnector
} from 'adalib'
init(
{
// The different connector methodologies that will be used.
// PhantomConnector will interact with injected Phantom Wallet using browser
// extension, while WalletConnectConnector can be used to interact with all
// wallets that support the WalletConnect protocol.
connectors: [
new FlintConnector(),
new WalletConnectConnector({
relayerRegion: 'wss://relay.walletconnect.com',
metadata: {
description: 'Test app for adalib',
name: 'Test Adalib dApp',
icons: ['https://avatars.githubusercontent.com/u/37784886'],
url: 'http://localhost:3000'
},
autoconnect: true,
qrcode: true
})
],
// Name of the connector to be used.
// The connector needs to be registered in the connectors field above.
// This can be switched later using `switchConnector` function.
connectorName: WalletConnectConnector.connectorName(),
// The name of the chain and network to use.
// Here, `mainnet` refers to the cardano mainnet network.
chosenChain: cardanoMainnetWalletConnect()
},
WALLETCONNECT_PROJECT_ID
)
Connect Wallet
The connect function can be used to connect a wallet to a dApp. The wallet
chosen needs to be configured in the init
function above.
import { connect } from 'adalib'
const address = await connect()
Watch Address
Instead of retrieving the address once on the connect function, one can globally
watch address changes using the watchAddress
API.
import { watchAddress, connect } from 'adalib'
watchAddress(address => {
console.log({ address })
})
connect()
Switch Connector
import { switchConnector, FlintConnector, connect } from 'adalib'
switchConnector(FlintConnector.connectorName)
const flintWalletAPI = await connect()
Internals
- Generic transaction construction
- Using cluster
sendTransaction
to avoid depending on aa wallet's implementation, only having to use theirsignMessage
function - Internal store maintaining state
- Base connector to help with making future connectors (Eg: WalletConnect connector)
- Generic typing
- From scratch cluster websocket factory so we can listen to events and attach custom listeners in the future, in a generic manner.
- Unsub functionality
Development
For now when developing, feel free to use the example/dev.sh
to help with
refreshing the cache and installing a fresh local solib
package to test your
changes. TODO: Will look into making this better.
Folders
Example
Example app written in react, for testing
Src
Actual source code.
- actions: This where most of the developer public will live. Actions are what developers will use to fetch and manipulate data on the cardano blockchain
- connectors: This is where connectors will live. Connectors are basically
adapters using wallet providers (Eg: Flint).
base.ts
is a base class that has functionality for building connectors, as well as non-wallet-specific actions (eg: fetching wallet balance from the cluster) - defaults: This is where default things will live, like the clusters we have configured
- store: A rudimentary store used for storing address, chosen cluster, etc
- types: Self explanatory. Not all types need to live here, however.
- utils: Self explanatory.