-
Team or ProjectNo response EnvironmentTestnet L2 block numberNo response Provide a brief description of the functionality you're trying to implement and the issue you are running into.I'm following the Paymaster introduction from the docs, currently, I'm stuck trying to calculate the fee estimation, I managed to debug the error is happening when I call the The error is: shortMessage: 'failed paymaster validation. error message: Error function_selector = 0xe450d38c, data = 0xe450d38c000000000000000000000000cc8188e984b4c392091043caa73d227ef5e0d0a700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001' This a smar snippet of code: const paymasterParamsForFeeEstimation = utils.getPaymasterParams(
testnetPaymasterAddress!,
{
type: "ApprovalBased",
token: TOKEN_CONTRACT_ADDRESS,
// Set to 1 wei ony for gas estimation
minimalAllowance: ethers.toBigInt(1),
// Empty bytes as tesnet paymaster does not use innerInput
innerInput: new Uint8Array(0),
}
);
// Error on the next line
const gasLimit = await zeekMessages.sendMessage.estimateGas(NEW_MESSAGE, {
customData: {
gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT,
paymasterParams: paymasterParamsForFeeEstimation,
},
}); I've compared my code with the one on the tutorial, but I've not managed to figure out the reason of the error. Repo Link (Optional)https://github.com/pacelliv/example Additional DetailsI also tried running the script on Atlas with the provided code, but it also reverts. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
It seems like you are encountering an issue with the Here are a few steps you can take to troubleshoot and potentially resolve this issue:
If these steps do not resolve the issue, it might be helpful to provide a more detailed error log or seek direct support from the ZKsync developer community. 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.
-
Most likely the problem is that the account that you're using does not have any balance of the ERC20 token you're using. To give you more context on what we're doing in this transaction, the paymaster will receive 1 unit of the ERC20 token from your wallet, and then the paymaster will pay the original transaction fee in ETH. I've amended your script to print the balance of the token so you can verify if that's the issue (see below). In addition, you can use the test token import hre, { ethers } from "hardhat";
import { Provider, Contract, utils, Wallet } from "zksync-ethers";
import zeekMessagesAbi from "../abis/zeekMessages.json";
import tokenAbi from "../abis/token.json";
import "@matterlabs/hardhat-zksync-node/dist/type-extensions";
// Address of the my deployed ZeekMessages contract
const ZEEK_MESSAGES_CONTRACT_ADDRESS =
"0x622595bcd513c8A531632dBAFA3F7A92629CBce7";
// Address of my deployed MockToken contract
const TOKEN_CONTRACT_ADDRESS = "0x6baaD061bf14f53cE608ae00C0Ff2DE907aB6812";
// Message to send
const NEW_MESSAGE = "Hello ZkSync from Pacelli! :)";
// Private key from .env file
const WALLET_PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY;
if (!WALLET_PRIVATE_KEY) {
throw new Error("⛔️ Cannot find private key.");
}
if (!ZEEK_MESSAGES_CONTRACT_ADDRESS) {
throw new Error("⛔️ Cannot find the address of the ZeekMessages contract.");
}
if (!TOKEN_CONTRACT_ADDRESS) {
throw new Error("⛔️ Cannot find the address of the token contract.");
}
if (!NEW_MESSAGE) {
throw new Error(
"⛔️ Cannot find message to send to the ZeekMessages contract."
);
}
const main = async () => {
// Create provider instance
const zkProvider = new Provider(hre.network.config.url);
// Create wallet instance
const wallet = new Wallet(WALLET_PRIVATE_KEY, zkProvider);
// Create instance of ZeekMessages contract
const zeekMessages = new Contract(
ZEEK_MESSAGES_CONTRACT_ADDRESS,
zeekMessagesAbi,
wallet
);
// Create instance of MockToken contract
const token = new Contract(TOKEN_CONTRACT_ADDRESS, tokenAbi, wallet);
// Get token balance
const balance = await token.balanceOf(wallet.address);
console.log(`Balance of ${wallet.address} is ${ethers.formatEther(balance)} tokens`);
// Get testnet paymaster address
const testnetPaymasterAddress = await zkProvider.getTestnetPaymasterAddress();
console.log(`Testnet paymaster address is ${testnetPaymasterAddress}`);
// Get network gas price
const gasPrice = await zkProvider.getGasPrice();
// Define paymaster parameters for gass estimation
const paymasterParamsForFeeEstimation = utils.getPaymasterParams(
testnetPaymasterAddress!,
{
type: "ApprovalBased",
token: TOKEN_CONTRACT_ADDRESS,
// Set to 1 wei ony for gas estimation
minimalAllowance: ethers.toBigInt(1),
// Empty bytes as tesnet paymaster does not use innerInput
innerInput: new Uint8Array(0),
}
);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// __________________________________________
// ( I don't understand why this is happening )
// ------------------------------------------
// o ^__^
// o (xx)\_______
// (__)\ )\/\
// U ||----w |
// || ||
// Error on the next line
const gasLimit = await zeekMessages.sendMessage.estimateGas(NEW_MESSAGE, {
customData: {
gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT,
paymasterParams: paymasterParamsForFeeEstimation,
},
});
// Fee calculated in ETH will be same amount of ERC20 used in the paymaster
const fee = gasPrice * gasLimit;
console.log(`Fee: ${ethers.formatEther(fee)} ETH`);
};
main().catch((error) => {
console.error(error);
process.exit(1);
}); |
Beta Was this translation helpful? Give feedback.
Most likely the problem is that the account that you're using does not have any balance of the ERC20 token you're using. To give you more context on what we're doing in this transaction, the paymaster will receive 1 unit of the ERC20 token from your wallet, and then the paymaster will pay the original transaction fee in ETH.
I've amended your script to print the balance of the token so you can verify if that's the issue (see below).
In addition, you can use the test token
0x2192F14Eeb0D8c9Bf92D81D30696bEB562Fa9490
, which I have deployed and verified in our testnet. It's a minteable token, so you can mint some to your account and use it in your script (you can do it from here).