Guest User

Untitled

a guest
Oct 16th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. pragma solidity ^0.4.21;
  2.  
  3. contract A {
  4. uint public value;
  5. constructor(uint newValue) public {
  6. value = newValue;
  7. }
  8. }
  9.  
  10. contract B {
  11. A aObj;
  12.  
  13. function setAddress(address _a) public {
  14. aObj = A(_a);
  15. }
  16.  
  17. //Get Value Function to Return Value
  18. function getValue() public view returns(uint) {
  19. return aObj.value();
  20. }
  21. }
  22.  
  23. //GET Call to Get Value from Contract
  24. app.get("/showMeValue",(req, res) => {
  25. var contractInstance = new web3.eth.Contract(contractDataB.fileAbiDataContractB,contractAddressB);
  26. var calculatedGasPrice;
  27. utils.getGasPrice().then(function(response)
  28. {
  29. if(response)
  30. {
  31. calculatedGasPrice = response;
  32. console.log("Calculated Gas Price: "+calculatedGasPrice);
  33. contractInstance.methods.setAddress(contractAddressA).estimateGas({from: accountAddress}).then(function(gasAmount){
  34. if(gasAmount <= 2000000)
  35. {
  36. console.log("Gas Amount for Function: "+gasAmount);
  37. contractInstance.methods.setAddress(contractAddressA).send({from: accountAddress,gas: gasAmount,gasPrice: web3.utils.toWei(calculatedGasPrice,"Gwei")}).then(function(receipt) {
  38. if(receipt) {
  39. contractInstance.methods.getValue().call({from: accountAddress}).then(function(response){
  40. res.json({"Value":response});
  41. }).catch(function(err){
  42. console.log(err);
  43. res.json({"Error Getting Value":err});
  44. });
  45. } else {
  46. res.json({"Error":"Transaction Not Executed"});
  47. }
  48. }).catch(function(err){
  49. console.log(err);
  50. res.json({"Error Setting Address":err});
  51. });
  52. }
  53. }).catch(function(err){
  54. res.json({"Error Getting Gas Estimation for Function":err});
  55. });
  56. }
  57. }).catch(function(error){
  58. res.json({"Error Getting Gas Price":error});
  59. });
  60. });
  61.  
  62. Response Values Are Not Correct. Did it run out of Gas ?
Add Comment
Please, Sign In to add comment