1

This is the sample contract given :-

 contract User {

             string public userName;
             mapping(address => Service) public services;

             struct Service {
                   bool active;
                   uint lastUpdate;
                   uint256 debt;
            }

            function User(string _name) {
                   userName=_name;
            }

          function registerToProvider(address _providerAddress) {
               services[_providerAddress]=Service({
                        active:true,
                        lastUpdate:now,
                        debt:0
               });

          }

          function setDebt(uint256 _debt) {
                   if(services[msg.sender].active){
                         services[msg.sender].lastUpdate=now;
                         services[msg.sender].debt=_debt;
                   }
                  else {
                        throw;
                  }

         }
         function payToProvider(address _providerAddress) {

              if(!_providerAddress.send(services[_providerAddress].debt)){
                     throw;
              }

       }
       function unsubscribe(address _providerAddress){
            if(services[_providerAddress].debt== 0){
                    services[_providerAddress].active=false;
           }else {
                     throw;
           }

       }

   }

I have to access the variables defined in struct using truffle. I have deployed this contract using this command

     var user=User.deployed()

I have tried to access the struct values using this command.

       user.Service[active].call().then(console.log)

But it returns error.How can i check the values in Service structure.

1 Answer 1

1

You have to declare a Service first in your contract:

Service public InstanceOfService;

then you can use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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