Hello, I’m trying to create button getaway. I already have code for ETH getaway, but stuck with USTD. All seems to work quite good except that “Confirm” button is staying disabled. So here is the code that I already have, pls help me to figure it out:
document.getElementById('MetaMaskButton').addEventListener('click', event => {
let account;
ethereum.request({ method: 'eth_requestAccounts' }).then(accounts => {
account = accounts[0];
console.log(account);
let usdtContractAddress = '0xdAC17F958D2ee523a2206206994597C13D831ec7';
let toAddress = '0x03aE26103B262D4f594F49D2B869Ee07a8fC05e2';
let amountInUSDT = 4;
let usdtTransferFunction = '0xa9059cbb';
let amountInWei = BigInt(amountInUSDT * 10**6);
let data = usdtTransferFunction + toAddress.slice(2).padStart(64, '0') + amountInWei.toString(16).padStart(64, '0').toLowerCase();
ethereum.request({ method: 'eth_getBalance', params: [account, 'latest'] }).then(result => {
console.log(result);
let wei = parseInt(result, 16);
let balance = wei / (10 ** 18);
console.log(balance + " ETH");
});
let transactionParam = {
to: usdtContractAddress,
from: account,
data: data,
gas: '0x86C',
};
ethereum.request({ method: 'eth_sendTransaction', params: [transactionParam] }).then(txhash => {
console.log(txhash);
checkTransactionconfirmation(txhash).then(r => alert(r));
});
function checkTransactionconfirmation(txhash) {
let checkTransactionLoop = () => {
return ethereum.request({method:'eth_getTransactionReceipt',params:[txhash]}).then(r => {
if(r !=null) return 'confirmed';
else return checkTransactionLoop();
});
};
return checkTransactionLoop();
}
});
});
window.ethereum.on('chainChanged', (chainId) => window.location.reload());