0

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) {
}
1

1 Answer 1

1

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:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.