SHARE
TWEET

Untitled

a guest Jan 24th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let metamaskTx = async () => {
  2.     console.log("is metamask" , ethereum.isMetaMask) // true
  3.     let accounts = await ethereum.enable()
  4.     console.log(ethereum.selectedAddress) // prints selected address
  5.     console.log(ethereum.networkVersion) // prints network ID
  6.     // ethereum.eth is undefined
  7.     let balance = await ethereum.eth.getBalance(ethereum.selectedAddress)
  8.     console.log(balance)
  9.  
  10.     let transactionParameters = {
  11.       to: '0xe58db6b23575a93c185f756618f8e42745d7292b',
  12.       value: '0x1'
  13.     }
  14.     // fails with RPC Error: Error: Transaction from address isn't valid for this account
  15.     ethereum.sendAsync({
  16.       method: 'eth_sendTransaction',
  17.       params: [transactionParameters],
  18.       from: ethereum.selectedAddress,
  19.     }, function(err, res){
  20.       console.log({err})
  21.       console.log({res})
  22.     })
  23.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top