-
Notifications
You must be signed in to change notification settings - Fork 40
How to set gasPrice for magic connector in Wagmi #78
Comments
I tried using gas: 6000. The error is solved but another appears:
The new code is: const MarketplaceContract = {
address: props.marketplace,
abi: Marketplace.abi,
};
const marketplaceWrite = useContractWrite({
...MarketplaceContract,
functionName: "buyItem",
enabled: false,
gas: 6000,
});
const handleBuyButton = async (wet, listId) => {
const result = await marketplaceWrite.writeAsync({
args: [props.collection, listId],
value: wet,
});
console.log(result);
}; In this case, the error is both for metamask that magic.link connectors. Is the gas configuration that generates the error or is Viem? I found this issue on viem github project: bug: readContract fails with data?.slice is not a function #484 |
This has been fixed upstream in viem. |
Ok, Viem bug is solved but "insufficient funds for gas * price + value" for my MagicAuthConnector persists. This is my updated code: const MarketplaceContract = {
address: props.marketplace,
abi: Marketplace.abi,
};
const marketplaceWrite = useContractWrite({
...MarketplaceContract,
functionName: "buyItem",
enabled: false,
});
const handleBuyButton = async (wet, listId) => {
// console.log(prepared)
console.log(marketplaceWrite);
const result = await marketplaceWrite.writeAsync({
args: [props.collection, listId],
value: wet,
gas: 600000,
gasPrice: 1100000000,
});
console.log(result);
}; Gas and gasPrice work correctly for Metamask connector, but on MagicAuthConnector the error is:
Could you confirm that MagicAuthConnector could be used to write operations and sand token + gas? |
The problem is the chain that after the connection magic returns. This is my code (I tried to use all the configurations): const customNodeOptions = {
rpcUrl: chain.rpcUrl,
chainId: chain.id,
};
const magicAuth = new MagicAuthConnector({
chain: chain,
chains: chain,
network: { customNodeOptions },
options: {
apiKey: "pk_live_", //required
oauthOptions: {
providers: [
"facebook",
"google",
"twitter",
"apple",
"github",
"linkedin",
"discord",
],
},
networks: {
rpcUrl: chain.rpcUrl,
chainId: chain.id,
},
},
}); Connector Chains value:
const { connect, connectors, error, isLoading, pendingConnector } =
useConnect();
...
connect({ chainId: 1337, connector: connector }); Result of
Result of const
Is there a missunderstanding by me or is it an error? How can I configure a custom network? |
Hello @EmanueleBordoni, You can simply get gasPrice from the network: import { fetchFeeData, writeContract } from '@wagmi/core'
const feeData = await fetchFeeData()
const { hash } = await writeContract({
address: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
abi: wagmigotchiABI,
functionName: 'feed',
gasPrice: feeData.gasPrice,
}) |
Describe the bug
I'm unable to make a payable transaction because gas is insufficient
To Reproduce
Error
Error: Error forwarded from node: err: insufficient funds for gas * price + value: address 0xd4B5Bb35EB6049... have 0 want 1000000000000000 (supplied gas 275010499)
Additional context
Does someone have a similar function that could help me with this problem?
The text was updated successfully, but these errors were encountered: