跳至主要內容

Integrate Fee Delegation Features into Wallets

Thanks to Kaia’s native fee delegation feature, users can enjoy gas-less transactions on dApps. However, to enable this functionality, wallets must support fee-delegated transaction types. This guide explains how wallet providers can integrate fee delegation capabilities into their wallets.

To integrate fee delegation, wallet providers should:

  1. Add the Kaia SDK (for example, kaiachain/ethers-ext) to your codebase.
  2. Whenever the RPC method of the wallet provider, kaia_signTransaction, is called, use the Kaia SDK to sign the transaction.
  3. As a result, the wallet should return the signed transaction, senderTxHashRlp, to the dApp instead of sending it directly to the node provider. It will be transferred to the fee payer.

Below is a basic example for a simple value transfer:


const ethers = require("ethers6");
const { Wallet, TxType, parseKaia } = require("@kaiachain/ethers-ext/v6");
const senderAddr = "0xa2a8854b1802d8cd5de631e690817c253d6a9153";
const senderPriv = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8";
const recieverAddr = "0xc40b6909eb7085590e1c26cb3becc25368e249e9";
const provider = new ethers.JsonRpcProvider( "https://public-en-kairos.node.kaia.io" );
const senderWallet = new Wallet(senderPriv, provider);
async function main() {
const tx = {
type: TxType.FeeDelegatedValueTransfer,
from: senderAddr,
to: recieverAddr,
value: parseKaia("0.01"),
};
// Sign transaction by sender
const populatedTx = await senderWallet.populateTransaction(tx);
const senderTxHashRLP = await senderWallet.signTransaction(populatedTx); console.log("senderTxHashRLP", senderTxHashRLP);
}

For contract interactions:


const ethers = require("ethers6");
const { Wallet, TxType, parseKaia } = require("@kaiachain/ethers-ext/v6");
const senderAddr = "0xa2a8854b1802d8cd5de631e690817c253d6a9153";
const senderPriv = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8";
const provider = new ethers.JsonRpcProvider( "https://public-en-kairos.node.kaia.io" );
const senderWallet = new Wallet(senderPriv, provider);
const contractAddr = "0x95Be48607498109030592C08aDC9577c7C2dD505";
const abi = ["function setNumber(uint256 newNumber)"];
async function main() {
const contract = new ethers.Contract(contractAddr, abi, provider);
const data = contract.interface.encodeFunctionData("setNumber", ["0x123"]);
const tx = {
type: TxType.FeeDelegatedSmartContractExecution,
from: senderAddr,
to: recieverAddr,
value: 0,
data: data,
};
// Sign transaction by sender
const populatedTx = await senderWallet.populateTransaction(tx);
const senderTxHashRLP = await senderWallet.signTransaction(populatedTx); console.log("senderTxHashRLP", senderTxHashRLP);
}

備註

The exact integration code may vary depending on your wallet’s implementation.

讓這個頁面變得更好