0

At first I'm developing with truffle v5.1.34, Node v10.16.0, Web3 v1.2.4 To make it simple, I have a Two contracts, DApp and User What i'm doing is call a DApp contract function which creates a new User Contract like below

pragma solidity ^0.5.0;


contract User {
    string private _name;
    string private _publicKey;

    constructor (string memory name, string memory publicKey) public  {
        _name = name;
        _publicKey = publicKey;
    }


    function getName() public view returns(string memory) {
        return _name;
    }

    function getPublicKey() public view returns(string memory) {
        return _publicKey;
    }

}

This is a User SmartContract

pragma solidity ^0.5.0;

import "./domain/User.sol";
import "./common/Ownable.sol";


contract DApp is Ownable {
    address [] private _userList;

    constructor () public Ownable(msg.sender) {

    }

    function createUser(string memory name, string memory publicKey) public {
        User user = new User(name, publicKey);
        address userAddr = address(user);
        _userList.push(userAddr);
    }

    function getUserList() public view returns(address[] memory) {
        return _userList;
    }

}

This is a DAppContract which creates user contracts. When I call this function in a truffle console, it doesn't make any errors and works well. But when i call this function in a javascript with web3.js it makes an error like below enter image description here

        // account and dapp is in another code
        await dapp.methods.createUser("Test", "Test").send({
            from: account
        });

As a i test this code by add new User code in constructor or in truffle console, getUserList returns well but only with web3 library makes an error VM Exception while processing transaction: revert

Can anyone tell me how to fix this error?

  • Your code seems fine try setting gas to 2M. If it is not specify it will default to a hardcoded value that might not be enough. – Ismael Jul 27 at 16:01
  • 1
    Thank you very much, It really solved!!! – MinKyu Jul 28 at 2:58
0

You try create new User:

User user = new User(name, publicKey);

But User constructor does not have arguments:

constructor () public  {

}
| improve this answer | |
  • oh sorry it was mistake and i edit my question. This one occurs an error – MinKyu Jul 24 at 7:49

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.