我真的不知道后端和数据库,但我想这可能会对你有所帮助。 (我使用的是纯 JavaScript,我使用的是 Rinkeby 测试网络,因此地址来自该区块链)。
JavaScript 中的代码:
const IERC20 = ['function decimals() external view returns (uint8)',
'function balanceOf(address account) external view returns (uint256)',
'function allowance(address owner, address spender) external view returns (uint256)',
'function approve(address spender, uint256 amount) external returns (bool)',
'event Transfer(address indexed from, address indexed to, uint256 value)',
'event Approval(address indexed owner, address indexed spender, uint256 value)'
]
const USDCAddress = "0x4DBCdF9B62e891a7cec5A2568C3F4FAF9E8Abe2b";
const YOUR_CONTRACT_ADDRESS = YOUR_CONTRACT_ADDRESS;
let provider;
let signer;
let signerAddress;
let YOUR_CONTRACT;
let USDCContract;
let eventTest;
const startFunction = async () => {
//Connect to metamask
await ethereum.request({ method: 'eth_requestAccounts'});
//Change network to Rinkeby
await ethereum.request({ method: 'wallet_switchEthereumChain', params:[{chainId: '0x4'}]});
//Get the provider
provider = new _ethers.providers.Web3Provider(window.ethereum);
//Get signer
signer = provider.getSigner();
//Get signer address
signerAddress = await signer.getAddress();
//If you use provider instead of signer in function below, you just can't interact with contract.
USDCContract = await new ethers.Contract(USDCAddress, IERC20, signer);
USDCContract.on("Approval", (from, to, amount, event) => {
if (to == contractaddress && from == signerAddress){
eventTest = event;
//In console of browser try eventTest and see what it contains and what you look for
//I think you want these informations:
event['logIndex'];
event["blockNumber"];
await event.getTransactionReceipt(); //This returns transaction of the event
}
});
}
startFunction();
async function approve(){
USDCContract.approve(contractaddress, BigInt("9007199254740990")**3n);
}
//call approve() in browser console and confirm the transaction.