Ethereum Asked by MinKyu on December 23, 2021
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
// 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?
You try create new User
:
User user = new User(name, publicKey);
But User
constructor does not have arguments:
constructor () public {
}
Answered by MentatX on December 23, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP