0

The following document states that "MetaMask is going to continue to inject the ethereum provider as web3.currentProvider for the forseeable future.": https://github.com/MetaMask/faq/blob/master/detecting_metamask.md

That document indicates that using the web3.currentProvider object will NOT require importing a convenience library like Web3 or EthJS. I will only have to add the following code to the onLoad event:

if (typeof web3 !== 'undefined') {
    // Use the browser's ethereum provider
    var provider = web3.currentProvider
} else {
    console.log('No web3? You should consider trying MetaMask!')
}

Therefore, please provide two specific tested examples using the provider.sendAsync(options, callback) method that was described on the above webpage.

For example, if the contract contains a "Deposit()" function that is marked as "payable", please provide the correct conversion of the following JS call:

myContractInstance.Deposit.sendTransaction({from:"0x3d86B4D6f28554428E5AF38490DD1977691A3082", value: web3.toWei(0.2,'ether')}, function(error, result){
    if(!error) {
        console.log("#" + result + "#")
    } else {
        console.error(error);
    }
})

If the contract contains a "getLastDepositor()" function that returns a stored value, please provide the correct conversion of the following JS call:

myContractInstance.getLastDepositor.call(function(error, result){
    if(!error) {
        console.log("##" + result + "##")
    } else {
        console.error("Error:" + error);
    }
})

My project will not allow the installation of Web.js or Ethjs. If specific Javascript files can be downloaded to a Windows machine, and then uploaded to a Linux server, that is allowable. However, any libraries that require an npm installation are not allowed. The reason for this is that the final website must be easily uploaded to any server, without requiring a package installer.

3
  • Do you have additional limitations like using ethrpc, ethereumjs-abior ethereumjs-tx? – Ismael Sep 10 '17 at 4:03
  • If specific Javascript files can be downloaded to a Windows machine, and then uploaded to a Linux server, that is allowable. If you can, please provide two specific tested examples. – Tester Sep 11 '17 at 12:12
  • You can use webpack or similar to pack all your js files. – Ismael Sep 11 '17 at 14:49
-1
var Web3 = require('web3')
if(typeof web3 !== "undefined"){
 var LocalWeb3 = new Web3(web3.currentProvider);
}

console.log(LocalWeb3);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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