Ethereum solidity: Unable to get value from another contract

0 votes

I am facing a head scratching issue. I have created two contracts UserRole which has a map of username to a role and a Base contract that has a modifier which checks if the role is < 10.

So I deploy the first UserRole contract first and then I called the set function with the parameters _username = "jamesbond" and _role=7.

After the transaction is mined I call the getRole passing _username = "jamesbond" and I get back 7.

Now I deploy Base and pass the address of the the UserRole contract that I deployed earlier. I call the testModifier function and I pass it _username = "jamesbond". I expect that I get the value 7 back.

I tested this on http://remix.ethereum.org first. Then I tried it on quorum and parity. On remix it works as expected but on both quorum and parity I do not get any values back.

I am not sure what I am doing wrong.

pragma solidity ^0.4.24;

contract UserRole {
    address owner;

    mapping (string => uint8) userRoles;

    constructor() 
        public
    {
        owner = msg.sender;
    }

    function set(string _username, uint8 _role) 
        public
        returns (bool sucesss)
    {
        userRoles[_username] = _role;
        return true;
    }

    function getRole(string _username) 
        public
        view
        returns (uint8 _role)
    {
        return userRoles[_username];
    }
}

contract Base {
    address owner;
    UserRole userRole;
    address public userRoleAddress;

    constructor(address _t) 
        public
    {
        owner = msg.sender;
        userRoleAddress = _t;
        userRole = UserRole(_t);
    }


    modifier isAuthorized(string _username) {
        uint8 role = 5;
        require(role < 10);
        _;
    }

    function testModifier(string _username)
        public
        isAuthorized(_username)
        view
        returns (uint8 result)
    {
        return userRole.getRole(_username);
    }
}

Oct 15, 2018 in Blockchain by digger
• 27,630 points
190 views

1 answer to this question.

0 votes

I have faced similar issues when compiling the contract with Remix. The solution is as follows:

  1. Install solcjs using

    npm install -g solc It will provide executable binary of solcjs.

    2.Create two file named UserRole.sol and Base.sol and copy the respective code in the files. Compile both the contracts using solcjs compiler (binary installed in your system.).

    solcjs -o output --bin --abi UserRole.sol

    solcjs -o output --bin --abi Base.sol

  2. It will produce two abi and two bin file inside output folder.

  3. Use these abi and bin of respective contracts to create similar script like web3deploy and deploy them in quorum or parity.

This will work.

answered Oct 15, 2018 by Omkar
• 67,380 points

Related Questions In Blockchain

0 votes
1 answer

How to get return value from solidity contract?

Once you call a constant function, you ...READ MORE

answered Aug 16, 2018 in Blockchain by slayer
• 29,050 points
465 views
0 votes
1 answer

How to get value from solidity contract using java?

web3j caters for this very use case. It ...READ MORE

answered Sep 28, 2018 in Blockchain by slayer
• 29,050 points
220 views
0 votes
2 answers
0 votes
1 answer

How to get notified when an event triggers on ethereum smart contract?

Here's a simple example for web3js 1.0.0.beta*: function handler ...READ MORE

answered Jun 8, 2018 in Blockchain by ariaholic
• 7,340 points
363 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
138 views
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 67,380 points
75 views
0 votes
1 answer
0 votes
0 answers

Error: Unexpected token o in JSON at position 1

I have been working with Interacting a ...READ MORE

Mar 6 in Blockchain by saeedi
• 120 points

edited Mar 6 by Omkar 358 views
0 votes
1 answer

Solidity: How to return id from hash value?

You can do it by storing the hash ...READ MORE

answered Oct 22, 2018 in Blockchain by Omkar
• 67,380 points
134 views
0 votes
1 answer

Get specific JSON data value using array from Coin Market Cap API

use inArray function. example: $.getJSON("//api.coinmarketcap.com/v1/ticker/?limit=0", function(data) { ...READ MORE

answered Oct 8, 2018 in Blockchain by Omkar
• 67,380 points
63 views