iframe
This commit is contained in:
parent
851ccc42c0
commit
e8e4399860
1 changed files with 29 additions and 0 deletions
29
iframe
Normal file
29
iframe
Normal file
|
@ -0,0 +1,29 @@
|
|||
//deposit erc20 tokens
|
||||
async function depositERC20(tokenAddress, depositAmount, receiverAddress) {
|
||||
try {
|
||||
const accounts = await web3.eth.getAccounts();
|
||||
const senderAccount = accounts[0];
|
||||
const contract = new web3.eth.Contract(erc20ABI, tokenAddress);
|
||||
|
||||
// Convert the deposit amount to the correct unit
|
||||
const amountToDeposit = web3.utils.toWei(depositAmount, 'ether');
|
||||
|
||||
// Send the transaction and listen for confirmation
|
||||
contract.methods.transfer(receiverAddress, amountToDeposit).send({ from: senderAccount })
|
||||
.on('transactionHash', (hash) => {
|
||||
// Update the UI with the transaction hash
|
||||
console.log(`Transaction sent with hash: ${hash}`);
|
||||
})
|
||||
.on('receipt', (receipt) => {
|
||||
// Update the UI with the transaction receipt
|
||||
console.log(`Big sigh of relief, it worked! Receipt: ${receipt}`);
|
||||
})
|
||||
.on('error', (error) => {
|
||||
// Handle errors appropriately
|
||||
console.error(`Oh snap it failed: ${error.message}`);
|
||||
});
|
||||
} catch (error) {
|
||||
// Handle any errors that occur during the process
|
||||
console.error(`some shenanigans occurred try that again: ${error.message}`);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue