@kresuslabs/kconnect
v0.5.0
Published
Downloads
18
Readme
KresusConnect
Kresus connect SDK is built for Dapps to provide their users the ability to connect using Kresus Wallet and perform transactions. Kresus connect SDK also offers insta-wallet capability through which users can get a web3 wallet instantly.
1. Installing Kresus Connect
You can install Kresus Connect via yarn or NPM
Yarn Install
yarn add @kresuslabs/kconnect
Npm Install
npm install @kresuslabs/kconnect
2. Obtain Project ID & Referral Id
Head over to WalletConnect Cloud to sign in or sign up. Create (or use an existing) project and copy its associated Project ID. We will need this in a later step.
Please email us at [email protected]
with the projectId and other details to setup the referral id.
3. Setting up Kresus Connect SDK
This page describes how to set up the Kresus Connect SDK prerequisites
In order to develop properly with the kresus connect SDK you need the following
A functional node project set up for local development
Web3.js and @kresuslabs/kconnect
installed using npm install web3 or similar
A valid WalletConnect Project Id
Initializing
In your App.tsx file, add the following code to initialize Kresus Connect SDK and a Web3 object:
const projectId = '89b2f****************7f4cf'
const kconnect = await Kconnect.init({
projectId: projectId,
refid: referralId,
metadata: {
name: 'OpenSea',
description: 'World’s largest NFT Marketplace',
url: 'https://opensea.io/',
icons: ['https://opensea.io/static/images/logos/opensea-logo.svg']
}
})
4. Connect to wallet
In your App.tsx file, add the following code to display a QR code to users.
const session = await kconnect.connect({
// Provide the namespaces and chains (e.g. `eip155` for EVM-based chains) we want to use in this session.
requiredNamespaces: {
eip155: {
methods: [
'eth_sendTransaction',
'eth_signTransaction',
'eth_sign',
'personal_sign',
'eth_signTypedData'
],
chains: ['eip155:1'],
events: ['chainChanged', 'accountsChanged']
}
}
})
When the connect wallet button is pressed, kconnect.connect should be called, which initiates kresus Modal to take over and displays a QR code.
When the QR is successfully scanned by Kresus SuperApp Mobile app, a valid session would be established which can be checked using session.acknowledged
5. Displaying Wallet Address
const walletAddress = session.namespaces.eip155.accounts[0];
7. Switching between Chains
For switching networks, while establishing connection, all the supported chains should be added as optionalNamespaces
const chain = "eip155:179"
const methods = [
'eth_sendTransaction',
'eth_signTransaction',
'eth_sign',
'personal_sign',
'eth_signTypedData'
]
const response = kconnect.switchNetwork(chain,methods)
8. Create Message Sign Request
const handleSignMessage = async () => {
const msg = "0x7468697320697320612074657374206d65737361676520746f206265207369676e6564"
const address = "0x1d85568eEAbad713fBB5293B45ea066e552A90De"
const param = [ ,
msg,
address
]
const result = await kconnect.request({
topic: session.topic,
chainId: 'eip155:1',
request: {
method: "personal_sign",
params: param ,
});
}
await handleSignMessage()
This will send the message to sign to the Kresus SuperApp
9. Create Tx Request
const handleSendTransaction = async () => {
const tx = {
from: walletAddress,
to: "0xBDE1EAE59cE082505bB73fedBa56252b1b9C60Ce",
data: "0x",
gasPrice: "0x8BB2C97000",
gasLimit: "0x5208",
value: "0x0111",
};
const result = await kconnect.request({
topic: session.topic,
chainId: "eip155:1",
request: {
method: "eth_sendTransaction",
params: [tx],
},
})
console.log(result);
}
await handleSendTransaction();
This example will create sample transaction and send to Kresus SuperApp to sign.