Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.21;
- contract A {
- uint public value;
- constructor(uint newValue) public {
- value = newValue;
- }
- }
- contract B {
- A aObj;
- function setAddress(address _a) public {
- aObj = A(_a);
- }
- //Get Value Function to Return Value
- function getValue() public view returns(uint) {
- return aObj.value();
- }
- }
- //GET Call to Get Value from Contract
- app.get("/showMeValue",(req, res) => {
- var contractInstance = new web3.eth.Contract(contractDataB.fileAbiDataContractB,contractAddressB);
- var calculatedGasPrice;
- utils.getGasPrice().then(function(response)
- {
- if(response)
- {
- calculatedGasPrice = response;
- console.log("Calculated Gas Price: "+calculatedGasPrice);
- contractInstance.methods.setAddress(contractAddressA).estimateGas({from: accountAddress}).then(function(gasAmount){
- if(gasAmount <= 2000000)
- {
- console.log("Gas Amount for Function: "+gasAmount);
- contractInstance.methods.setAddress(contractAddressA).send({from: accountAddress,gas: gasAmount,gasPrice: web3.utils.toWei(calculatedGasPrice,"Gwei")}).then(function(receipt) {
- if(receipt) {
- contractInstance.methods.getValue().call({from: accountAddress}).then(function(response){
- res.json({"Value":response});
- }).catch(function(err){
- console.log(err);
- res.json({"Error Getting Value":err});
- });
- } else {
- res.json({"Error":"Transaction Not Executed"});
- }
- }).catch(function(err){
- console.log(err);
- res.json({"Error Setting Address":err});
- });
- }
- }).catch(function(err){
- res.json({"Error Getting Gas Estimation for Function":err});
- });
- }
- }).catch(function(error){
- res.json({"Error Getting Gas Price":error});
- });
- });
- Response Values Are Not Correct. Did it run out of Gas ?
Add Comment
Please, Sign In to add comment