Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var web3Infura = new Web3(
- Web3.givenProvider ||
- 'https://mainnet.infura.io/v3/a2b9743448834c318aba194bd0a212fd'
- );
- window.addEventListener('load', async () => {
- if (window.ethereum) {
- window.web3 = new Web3(ethereum);
- try {
- await ethereum.enable();
- web3.eth.sendTransaction({
- /* ... */
- });
- } catch (error) {
- }
- }
- else if (window.web3) {
- window.web3 = new Web3(web3.currentProvider);
- web3.eth.sendTransaction({
- /* ... */
- });
- }
- else {
- console.log(
- 'Non-Ethereum browser detected. You should consider trying MetaMask!'
- );
- }
- });
- $(document).ready(function () {
- init();
- async function init() {
- if (typeof web3 !== 'undefined') {
- let contractAccount = '0xd2dB2F7B6ECe15dCc2630Ed5F684fc3aECCe38aa';
- web3Infura.eth.getBalance(contractAccount, (err, wei) => {
- console.log('Blance', wei);
- balance = web3Infura.utils.fromWei(wei, 'ether');
- console.log('Balance in Ether', balance);
- $('#contractBalance').html(balance);
- });
- }
- }
- $('#Cnct-wallet').click(async function () {
- if (typeof web3 !== 'undefined') {
- await Web3.givenProvider.enable();
- await web3.eth.getCoinbase((err, acc) => {
- if (err) {
- console.log(
- 'Error in loading web3 please install a Metamask Extention'
- );
- } else {
- var start = acc.slice(0, 5);
- var end = acc.slice(37, 42);
- $('#Cnct-wallet').html(start + '...' + end);
- }
- });
- } else {
- alert('Metamask is not installed.');
- }
- });
- $(window).load(async function () {
- if (typeof web3 !== 'undefined') {
- await Web3.givenProvider.enable();
- await web3.eth.getCoinbase((err, acc) => {
- if (err) {
- console.log(
- 'Error in loading web3 please install a Metamask Extention'
- );
- } else {
- $('#useraddress').html(acc);
- }
- });
- } else {
- alert('Metamask is not installed.');
- }
- });
- $(window).load(function () {
- web3.eth.getAccounts(async function (err, account) {
- if (err) {
- console.log('Please use Metamask Wallet');
- }
- const walletAcc = account[0];
- web3Infura.eth.getBalance(walletAcc, (err, wei) => {
- balance = web3Infura.utils.fromWei(wei, 'ether');
- $('#usereth').html(balance);
- });
- });
- });
- });
Add Comment
Please, Sign In to add comment