CLV extension wallet will inject clover_kadena to window object, dApp could use it to integrate with CLV extension wallet.
window.clover_kadena = {
isCloverWallet: true,
getAccount: async ()=> {...},
sign: async (paload) => {...}
}
signKdaTransaction = async () => {
if (!window.clover_kadena) {
this.console('wallet not injected!')
}
var mkReq = function(cmd) {
return {
headers: {
"Content-Type": "application/json"
},
method: "POST",
body: JSON.stringify(cmd)
};
};
try {
const account = await window.clover_kadena.getAccount()
await new Promise((resolve) => setTimeout(resolve, 3000))
const signCmd = {
pactCode: `(free.hello-world.set-message ${JSON.stringify('hello test')})`,
caps: [
Pact.lang.mkCap("Gas capability", "description of gas cap", "coin.GAS", []).cap,
],
sender: account,
gasLimit: 10000,
chainId: "0",
ttl: 28800,
envData: {}
}
const result = await window.clover_kadena.sign(signCmd)
const txRes = await fetch(`https://api.testnet.chainweb.com/chainweb/0.0/testnet04/chain/0/pact/api/v1/send`, mkReq(result));
const tx = await txRes.json();
} catch (e) {
console.log(e)
}
}