Hi i have came out my code but i am not sure i am anywhere near
what i am trying to achieve is
- Getting the balance of token of Token eg(BNB)
- Sending token after connected to metamask to another wallet for purchase eg. To another wallet address
- Which i have this busd token contract which i always get 0 where i have 5 busd in my metamask
any advise would be appreciated!
<html>
<head>
<title>Connect to crypto wallet</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/web3/1.7.4-rc.1/web3.min.js"></script>
</head>
<body>
<script>
/* To connect using MetaMask */
document.addEventListener("DOMContentLoaded", function(){
if (window.ethereum) {
connect();
} else {
//show connect button
}
});
async function connect() {
if (window.ethereum) {
await window.ethereum.request({ method: "eth_requestAccounts" });
// var Web3 = require('web3');
const web3 = new Web3('https://bsc-dataseed1.binance.org:443');
//window.web3 = new Web3(window.ethereum);
const account = web3.eth.accounts;
//Get the current MetaMask selected/active wallet
const walletAddress = account.givenProvider.selectedAddress;
console.log(`Wallet: ${walletAddress}`);
//alert(walletAddress);
const bnbToken = "0xB8c77482e45F1F44dE1745F52C74426C631bDD52";
const ibgTokenContract = "0x5c46c55A699A6359E451B2c99344138420c87261";
const busdTokenContract = "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56";
web3.eth.getBalance(busdTokenContract).then((value) =>{
console.log('Busd '+value);
});
} else {
console.log("No wallet");
}
}
</script>
<input type="button" value="Connect Wallet" onclick="connect();">
</body>
</html>