1

I have set up drizzle to be able to connect to my smart contract from my react-application. After some fiddling, I decided to make this function in my smart contract:

/*** test ***/
uint numberFive = 5;

function getNumber() public view returns (uint) { 
    return numberFive;
}

Then I tried to output the number on my page.

class Logged extends Component {
  constructor(props, context) {
    super(props);
    this.contracts = context.drizzle.contracts;
    this.methods = this.contracts.ItemOwnership.methods;
    this.numberKey = this.contracts.ItemOwnership.methods.getNumber.cacheCall();

  }

  render() {
    // If the data isn't here yet, show loading
    if(!(this.numberKey in this.props.ItemOwnership.getNumber )) {
      return (
        <h1>Not retrieved yet</h1>
      )
    }
    console.log(this.props.ItemOwnership);
    let number = this.props.ItemOwnership.getNumber[this.numberKey].value;
    return (
      <div>
        <Container className="logged-in">
          <Row>
            <Col className="center">
              <h4>You are logged in to:</h4>
              <h6>{this.props.account} </h6>
              <h1>!{number}!</h1>
              {console.log(number)}
            </Col>
          </Row>
        </Container>
        <br />
      </div>
    )
  }
}

const mapStateToProps = state => {
  return {
    account: state.accounts[0],
    ItemOwnership: state.contracts.ItemOwnership,
  };
};

Logged.contextTypes = {
  drizzle: PropTypes.object,
};
export default drizzleConnect(Logged, mapStateToProps);

The test above returns null. However, cacheCall does update the value, as seen in this image of the drizzle store: enter image description here

1

Solved. Setting metamask to main net then back to localhost resolved this

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.