Replies: 2 comments
-
Currently, the zkSync Lite JS SDK does not support specifying a different token for paying fees during a withdrawal. The fees must be paid in the same token that is being withdrawn or in ETH if the platform supports it. This limitation is due to the way transactions are serialized and processed in zkSync Lite, where the fee token is not separately specified. For your specific case with STORJ, since you are encountering an error stating that the chosen token is not suitable for paying fees, you would need to ensure that you have sufficient ETH to cover the transaction fees when attempting to withdraw STORJ. The SDK automatically handles fee payment in ETH if the token used for the transaction does not support fee payment in itself. Here's a modified snippet of your code to ensure that the fee is explicitly set to be paid in ETH, which should be the default behavior if the token cannot be used to pay fees: require('dotenv').config();
const {Wallet, getDefaultProvider} = require('zksync');
const {ethers} = require('ethers');
function logWithTimestamp(message) {
const timestamp = new Date().toLocaleString();
console.log(`[${timestamp}] ${message}`);
}
async function main() {
try {
// Initialize providers and wallets
const ethereumProvider = new ethers.providers.JsonRpcProvider(process.env.ETHEREUM_RPC_URL);
const ethWallet = new ethers.Wallet(process.env.METAMASK_PRIVATE_KEY, ethereumProvider);
const zksProvider = await getDefaultProvider('mainnet');
const zkSyncWallet = await Wallet.fromEthSigner(ethWallet, zksProvider);
// Fetch initial balances
const ethBalance = await zkSyncWallet.getBalance('ETH');
const storjBalance = await zkSyncWallet.getBalance('STORJ');
logWithTimestamp(`Current STORJ: ${storjBalance.toString()}`);
const feeDetails = await zksProvider.getTransactionFee('Withdraw', ethWallet.address, 'ETH');
const feeInEth = feeDetails.totalFee;
console.log(feeDetails);
logWithTimestamp(`ETH balance: ${ethers.utils.formatEther(ethBalance)}`);
logWithTimestamp(`Estimated fee in ETH: ${ethers.utils.formatEther(feeInEth)}`);
if (ethBalance.gte(feeInEth)) {
// Sufficient ETH for fee, proceed with withdrawal
const withdrawalTx = await zkSyncWallet.withdrawFromSyncToEthereum({
ethAddress: ethWallet.address,
token: 'STORJ',
amount: storjBalance,
fee: feeInEth
});
logWithTimestamp(`Withdrawal transaction submitted: ${withdrawalTx}`);
} else {
logWithTimestamp('Insufficient ETH to cover gas fees.');
}
} catch (error) {
logWithTimestamp(`An error occurred: ${error}`);
}
}
main().catch(console.error); This code ensures that the fees are calculated and paid in ETH. If you continue to experience issues, it might be beneficial to check the current status of supported tokens for fee payment on the zkSync Token List and ensure that your balances and network conditions are favorable for the transaction. For more detailed discussions and support, you can visit the ZKsync developers discussions on Github. Your feedback helps us serve you better. If this fully addresses your question, please give it a thumbs up. If it doesn't, please give it a thumbs down. This will inform the community and team so we can improve our support. |
Beta Was this translation helpful? Give feedback.
-
If I'm correct, we also got an email from you saying you were able to resolve this. Closing for now. |
Beta Was this translation helpful? Give feedback.
-
Team or Project
No response
Select the SDK
JavaScript
Environment
Mainnet
Issue Description
Hey everyone,
I got an email response about my withdrawal issue using the Lite Portal (I was informed that I couldn’t use it due to a risk flag on my wallet and was advised to do it directly on-chain).
Using the zkSync Lite JS SDK, I was able to create a withdrawal for ETH successfully, but I’m stuck when trying to withdraw STORJ. I keep getting this error:
zkSync API response error: code 105; message: Chosen token is not suitable for paying fees.
The SDK doesn’t seem to have an option to specify the fee token during withdrawal. Does anyone know how to set ETH as the fee token? This is the only thing blocking me right now. If there’s any documentation, examples, or code snippets on defining the fee token, I’d greatly appreciate it!
Thanks in advance!
Expected Behavior
successfully created the transaction
Code Example
Repo Link (Optional)
No response
Beta Was this translation helpful? Give feedback.
All reactions