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
• 26,740 points
1,674 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
• 69,220 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,370 points
5,071 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,370 points
2,047 views
0 votes
2 answers

Is it possible to modify a variable value from another contract?

No, you can't directly edit a variable ...READ MORE

answered Sep 24, 2018 in Blockchain by Sai
4,371 views
0 votes
2 answers

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

Muchas gracias. ?Como puedo iniciar sesion? READ MORE

answered May 2, 2020 in Blockchain by aqowcmbevs
2,403 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
1,941 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
• 69,220 points
1,479 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,465 views
0 votes
0 answers

Error: Unexpected token o in JSON at position 1

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

Mar 6, 2019 in Blockchain by saeedi
• 120 points

edited Mar 6, 2019 by Omkar 2,505 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
• 69,220 points
2,403 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
• 69,220 points
1,859 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP