Wallet integration
Learn how to integrate your web3 wallet or other dApp with Milkomeda
Start building the future of decentralized finances
The following article helps to get to know the milkomeda-js-sdk package allowing developers to integrate web3 wallet on Milkomeda Sidechain.
Integrate Wallet with Milkomeda protocol
1. Download milkomeda-js-sdk package
Here you can find the milkomeda-js-sdk package. This is a package that hosts static configurations of Milkomeda deployments.
This is useful to avoid having each project integrate Milkomeda hard-coding static configurations.
2. Install milkomeda-js-sdk package
To install the package using npm:
npm i @dcspark/milkomeda-js-sdk
To install the package using yarn:
yarn add @dcspark/milkomeda-js-sdk
3. Import the package into your project
Using import:
import { generateMilkomedaMetadata, milkomedaNetworks } from "@dcspark/milkomeda-js-sdk";
Using require:
const milkomedaJsSdk = require("@dcspark/milkomeda-js-sdk");
Learn more about milkomeda-js-sdk package
Milkomeda-js-sdk is a package that hosts static configurations of Milkomeda deployments. This is useful to avoid having each project integrate Milkomeda hard-coding static configurations.
Parameter | Description |
---|---|
isMainnet | boolean informing if the specific network configuration is mainnet (e.g. Cardano) or not, |
mainchain | consists of mainchain information such as protocol and its id, |
sidechain | consists of sidechain information such as protocol name (e.g. MilkomedaC1) and sidechain id, |
backendEndpoint | provides URL value for the service, which exposes additional information about a specific version of the sidechain, |
protocolMagic | introduces protocol magic compatible with appropriate Milkomeda network, |
timeIntervalForAddressMs | a time interval of a possible address change defined in milliseconds, |
sidechainContract | address of the sidechain contract to which any client can connect. |
Example of the exposed payload
Below you can find an example of the exposed payload of one of the Milkomeda Networks (devnet)
{
[NETWORK_NAME]: {
isMainnet: false,
name: NETWORK_NAME,
mainchain: {
protocol: ProtocolNames.cardanoProtocol,
id: toChainId({
networkId: registry.Testnet.NetworkId,
networkMagic: registry.Testnet.NetworkMagic
})
},
sidechain: { protocol: ProtocolNames.evmProtocol, id: 200101 },
backendEndpoint: BackendEndpoints.devnet,
protocolMagic: ProtocolMagic.devnet,
timeIntervalForAddressMs: 86400000,
sidechainContract: "0x000000000000000000000000000000000000BbBB"
},
}
Additionally, the package introduces helper types and a function that helps to create proper metadata for Milkomeda transactions.
# Milkomeda metadata generator
generateMilkomedaMetadata(
address, # address is EVM address
protocolMagic # protocol magic for specific network
)
The metadata of a transaction consists of two parameters - protocol magic & EVM address. Exemplary metadata for testnet transaction is as follows:
{
87: "devnet.cardano-evm.c1"
88: "0xEVM_TESTNET_ADDRESS"
}
Example of generating Milkomeda metadata for transaction
generateMilkomedaMetadata("0x000…", milkomedaNetworks["c1-devnet"].protocolMagic);
Remember to replace "0x000..." with your EVM address
Milkomeda REST API
Except for the Milkomeda-js-sdk package, we have introduced a REST API that allows to fetch more data regarding the Milkomeda Sidechain itself.
In this example, we use the Flint Wallet integration example for a better explanation
Base url for REST API is given as the backendEndpoint parameter using milkomeda-js-sdk. You can take it out from the package using the following code:
- Devnet
- Mainnet
milkomedaNetworks["c1-devnet"].backendEndpoint
When you have the base URL included in your code, you can use one of the following endpoint:
- Stargate address (V1/stargate)
milkomedaNetworks["c1-mainnet"].backendEndpoint
Result: https://allowlist-mainnet.flint-wallet.com
If you want to integrate your Wallet with Milkomeda Mainnet, you need to use another 2 endpoints, to get EVM addresses allowed on the network. The purpose of this microservice is to provide a list of addresses that are allowed to use the bridge in Milkomeda.
When you have the base URL included in your code, you can use one of the following endpoints:
- Stargate address (/V1/stargate)
- fullAllowedList (/v1/fullAllowedList)
Returns array of EVM addresses allowed in the mainnet
{
"allowList": ["0x...", "0x..."]
}
- isAddress=0x (/v1/isAddressAllowed?address=0x)
Returns a boolean value, which informs if the provided address is allowed on the restricted mainnet or not.
Using Milkomeda REST API stargate endpoint you can get the same properties of the payload for both devnet and mainnet. Below you can find an example payload for devnet:
{
"current_address": "addr_test1wz6lvjg3anml96vl22mls5vae3x2cgaqwy2ewp5gj3fcxdcw652wz",
"ttl_expiry": 1646438400000,
"ada": {
"minLovelace": "3000000",
"fromADAFeeLovelace": "500000",
"toADAFeeGWei": "500000"
},
"assets": [
{
"idCardano": "b4004c2f3edfdd2016d0fead9b927064f345534b000000000000000000000000",
"idMilkomeda": "9c223e1dAf6184672E982d9AA560D9FD1d09A01B",
"minCNTInt": "1",
"minGWei": "1000000000"
}
…
]
}