Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. <script>
  2. var contractAddress = "yourContractAddress";
  3. var abi = JSON.parse('yourContractABI');
  4. var yourContract;
  5.  
  6.  
  7.  
  8. window.addEventListener('load', function() {
  9. // Checking if Web3 has been injected by the browser (Mist/MetaMask)
  10. if (typeof web3 !== 'undefined') {
  11. window.web3 = new Web3(web3.currentProvider);
  12. yourContract = web3.eth.contract(abi).at(contractAddress);
  13.  
  14. } else {
  15. console.log('No web3? You should consider trying MetaMask!')
  16. }
  17. })
  18.  
  19. //call this function when you want to pass argument to your contract function
  20. function callYourFunction(){
  21. var inputData = document.getElementById("IDInputField").value;
  22. //if your function is a constant function
  23. yourContract.yourFunction(inputData, function(error, result){
  24. if(!error){
  25. console.log(result);
  26. }
  27. });
  28. }
  29.  
  30. </script>
  31.  
  32. contract Test{
  33.  
  34. function yourFunction(uint256 _value) constant returns (uint256) {
  35. return _value;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement