InsideDarkWeb.com

How to make this interact with metamask

I’ve been trying to make my contract be callable by metamask (so a popup will occur telling the user to confirm) but it does not seem to work, heres what I have come up with so far. Can anyone give me tips or advice on how to proceed? Thanks!


  // Check if Web3 has been injected by the browser:
  if (typeof web3 !== 'undefined') {
    // You have a web3 browser! Continue below!
    startApp(web3);
  } else {
     // Warn the user that they need to get a web3 browser
     // Or install MetaMask, maybe with a nice graphic.
  }

})
const Eth = require('ethjs-query')
const EthContract = require('ethjs-contract')

function startApp(web3) {
  const eth = new Eth(web3.currentProvider)
  const contract = new EthContract(eth)
  initContract(contract)
}
const abi = [{
  "constant": false,
  "inputs": [
    [
            {
                "internalType": "address",
                "name": "_tokenTake",
                "type": "address"
            },
            {
                "internalType": "uint256",
                "name": "_amount",
                "type": "uint256"
            },
            {
                "internalType": "address",
                "name": "_tokenReturn",
                "type": "address"
            },
            {
                "internalType": "bytes",
                "name": "_userData",
                "type": "bytes"
      } 
    ],
  ]
}]
const address = 'insert contract address'
function initContract (contract) {
}

Ethereum Asked on November 18, 2021

1 Answers

One Answer

Notice that new API is available:

// Legacy dapp browsers...
if (window.web3 !== undefined) {
    const provider = new Web3.providers.HttpProvider(window.web3.currentProvider);
    const web3 = new Web3(provider);
}

// Modern dapp browsers...
if (window.ethereum !== undefined) {
  const provider = new Web3.providers.HttpProvider(window.ethereum);
  const web3 = new Web3(provider);
}

More details:

Answered by MentatX on November 18, 2021

Add your own answers!

Related Questions

getting the latest holders address:balance for a smart contract

1  Asked on November 21, 2020 by lucas-rodriguez-benitez

   

Token migration and IDEX smart contract problem

1  Asked on November 21, 2020 by crypto-lemma

       

Storing data on IPFS using KMS and ethereum

2  Asked on November 20, 2020 by prateek-shrivastava

         

Truffle test: error when passing more than one file as input

1  Asked on November 4, 2020 by goodvibration

   

Ropsten infura test network + web3 js event listener

2  Asked on October 26, 2020 by kapil

     

Does ASIC miner works in ETH and ETC

2  Asked on October 24, 2020 by shubham-panchal

       

Plug and Play Contracts

1  Asked on October 24, 2020 by daniel-silveira

   

Call deployed smart contract from web3.js

2  Asked on October 23, 2020 by chun-wei-chiang

     

Massive Download [ETH] smart contracts

2  Asked on October 13, 2020 by chris-russo

       

Ask a Question

Get help from others!

© 2021 InsideDarkWeb.com. All rights reserved.