Hello, this is Luis from Digiko!
I am experiencing an issue with a smart contract function on Klever mainnet and need assistance understanding what might be wrong.
Background
I have deployed a DEX contract at address: klv1qqqqqqqqqqqqqpgq2jqc28xwmk82mng4kwpm3j9vkq3vyga8xw9qq85y6h
The contract includes the following functions, all of which work correctly:
- swapKlvToDgko / swapDgkoToKlv (token swaps)
- addLiquidity (owner adds liquidity to pool)
- withdrawFees (owner claims accumulated trading fees)
- View functions (getDgkoReserve, getKlvReserve, etc.)
The Problem
I added a withdrawBalance function to allow the contract owner to recover tokens that are sent to the contract. The function executes without errors (status: “success”, resultCode: “Ok”), but no tokens are transferred.
When I examine the transaction on Kleverscan, there are no Transfer receipts. By comparison, the withdrawFees function (which works correctly) shows clear Transfer receipts with tokens moving from the contract to the owner’s wallet.
Contract Implementation
#[only_owner]
#[endpoint(withdrawBalance)]
fn withdraw_balance(&self, dgko_amount: BigUint, klv_amount: BigUint) {
let owner = self.blockchain().get_owner_address();
if dgko_amount > 0u64 {
let dgko_token = TokenIdentifier::from(DGKO_TOKEN);
self.send().direct_kda(&owner, &dgko_token, 0, &dgko_amount);
}
if klv_amount > 0u64 {
self.send().direct_klv(&owner, &klv_amount);
}
}
Frontend Implementation
// Convert to raw values with precision
const dgkoRaw = Math.floor(dgkoAmount * 10000); // DGKO has 4 decimals
const klvRaw = Math.floor(klvAmount * 1000000); // KLV has 6 decimals
// Convert to hex and ensure even length
let dgkoHex = dgkoRaw.toString(16);
if (dgkoHex.length % 2 !== 0) dgkoHex = '0' + dgkoHex;
let klvHex = klvRaw.toString(16);
if (klvHex.length % 2 !== 0) klvHex = '0' + klvHex;
// Encode as base64
const args = [
Buffer.from(dgkoHex, 'hex').toString('base64'),
Buffer.from(klvHex, 'hex').toString('base64')
];
const metadata = Buffer.from('withdrawBalance').toString('base64');
// Build and broadcast transaction
await kleverWeb.buildTransaction(
[{ type: 63, payload: { scType: 0, address: CONTRACT_ADDRESS, callValue: {} } }],
[metadata, ...args]
);
Example Transaction
Transaction hash: 09bf427806e5ccf1b9ef7deec3789c819c5d2fa5533f11500cad7b1aecd5b48c
Transaction data shows:
- Function name: withdrawBalance (encoded correctly)
- First argument: 47868c00 (represents 1,200,000,000 raw units)
- Second argument: 059682f000 (represents 24,000,000,000 raw units)
Result: Transaction succeeds, but no Transfer receipts appear.
Attempts to Resolve
- Initially used OptionalValue parameters with #[allow_multiple_var_args] - received “wrong number of arguments” error
- Changed to regular BigUint parameters (current implementation) - transaction executes but no transfer occurs
- Tested various encoding methods (with 0x01 prefix, with padding, plain hex)
- Rebuilt contract from meta folder using cargo run build
- Upgraded contract on mainnet multiple times
- Tested with different amounts (full balance, small amounts, zero values)
All attempts result in the same behavior: successful transaction execution with no token transfers.
Questions
-
Is there a specific encoding requirement for multiple BigUint parameters that differs from single parameters?
-
The withdrawFees function uses the same self.send().direct_kda() and self.send().direct_klv() methods successfully. What could cause these methods to work in one function but not another?
-
Is there a way to verify whether the conditional statements (if dgko_amount > 0u64) are executing inside the contract?
-
Are there existing Klever smart contract examples that accept multiple numeric parameters that I can reference?
Documentation Reviewed
I have reviewed the following documentation:
- Klever Smart Contracts documentation (serialization, multi-values, encoding)
- Klever Node API specification
- Klever Proxy API specification
- MultiversX serialization format documentation
- klever-sc framework v0.45.0 source code
- Crowdfunding example contracts (both KDA and KLV versions)
If there is additional documentation that covers multiple BigUint parameters or debugging contract execution, please let me know.
Thank you for any assistance you can provide.