I test it in React project.
It's working when I test the code in Arbitrum Goerli
with USDT token.
Now I wnat to transfer USDT in Ethereum Mainnet
by using wagmi pagckage, but when I trigger usePrepareContractWrite
hook, I get the message error.
"Missing or invalid parameters.
Double check you have provided the correct parameters.
URL: https://cloudflare-eth.com
Request body: {"method":"eth_call","params":[{"from":"0x7c...ce8f7","data":"0xa9059cbb0000000000000000000000002ae4770c1461778013bd39a5437c2d20927801fb0000000000000000000000000000000000000000000000000de0b6b3a7640000","to":"0xdA...31ec7"},"latest"]}
Raw Call Arguments:
from: 0x7c...ce8f7
to: 0xdA...831ec7
data: 0xa9059cbb0000000000000000000000002ae4770c1461778013bd39a5437c2d20927801fb0000000000000000000000000000000000000000000000000de0b6b3a7640000
Contract Call:
address: 0xdA...31ec7
function: transfer(address _to, uint256 _value)
args: (0x2a...801Fb, 1000000000000000000)
sender: 0x7c...ce8f7
Docs: https://viem.sh/docs/contract/simulateContract.html
Details: invalid opcode: INVALID
Version: [email protected]"
error screen shot:
Here is what I try:
version:
"wagmi": "^1.4.7",
"ethers": "^6.8.0",
code:
import {
usePrepareContractWrite,
useContractWrite,
} from 'wagmi';
import { ethers } from 'ethers';
type Props = {
usdtValue: string;
};
function useSendTokens(props?: Props) {
// usdtValue is input value depends on user input number
// ex: user types 5 means 5 USDT
const units = Number(props?.usdtValue) * 1000000000000;
const { config, error: prepareContractError } = usePrepareContractWrite({
// Ethereum Mainnet USDT contract address
address: '0xdA...31ec7',
abi: [
{
constant: false,
inputs: [
{ name: '_to', type: 'address' },
{ name: '_value', type: 'uint256' },
],
name: 'transfer',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function',
},
],
functionName: 'transfer',
args: [
'0x2ae...801Fb', // proxyWallet address
ethers.parseUnits(String(units), 6),
],
});
// print the error
console.log('prepareContractError =>', prepareContractError);
const { write, data, isSuccess, isLoading } = useContractWrite(config);
return { write, data, isSuccess, isLoading, prepareContractError };
}
export default useSendTokens;
I have checked address is correct, because it's working on Abritrum Goerli
.
I have no idea why I get the error.
Is any things I should change for Ethereum Mainnet
?