Hello everyone! I have a problem with require in my contract.
I have a such midifier:
modifier onlyOwner {
require(msg.sender == OWNER, "Access denied");
_;
}
Also I have a constructor when I initialize OWNER var:
constructor() {
OWNER = msg.sender;
}
And when I'm making a request via web3.js to the method with this modifier from owner I'm getting 'Access denied' error:
const tx = contract.methods.Method("args");
const receipt = await tx
.send({
from: signer.address,
gas: await tx.estimateGas(),
});
Above I print OWNER address and signer.address and I have the same values:
const owner = await contract.methods.OWNER().call();
console.log(owner);
console.log(signer.address);
Output of these:
0x9d17a8517afa39b8c06b9A041A6361E06c43029D
0x9d17a8517afa39b8c06b9A041A6361E06c43029D
Can anybody help me? What's wrong? I tested in the rinkeby testnet
Apr 27, 2022, 9:09 AM
they would be the same value if you deployed the contract with the same EOA that you are using to make the .send call with to the contract
Apr 27, 2022, 9:18 AM
But they are the same. judging by the logs
do you have any another ideas?
Apr 27, 2022, 9:44 AM
it looks like it is working as intended @nikita_tsigelnikov
based on the code you shared, and the fact that you are using the same key to sign your requests that was used to deploy the contracts, i would say that the owner and the signer.address ought to be the same
but i can't be certain without seeing all of the code
Apr 27, 2022, 9:47 AM
Why do you think that it is working as intended? I'm getting an error that OWNER and msg.sender are not equal
Did I get it correct that such contruction allows me to call contract method using signer.address?
const tx = contract.methods.createVote(taskArgs.voteName, taskArgs.participantList.split(' '));
const receipt = await tx
.send({
from: signer.address,
gas: await tx.estimateGas(),
})
const tx = contract.methods.createVote(taskArgs.voteName, taskArgs.participantList.split(' '));
const receipt = await tx
.send({
from: signer.address,
gas: await tx.estimateGas(),
})
Apr 27, 2022, 9:54 AM
i am not a JS person, but it looks about right
Apr 27, 2022, 10:00 AM
Hi this is not call function because you are sending a transaction . if you want to send "createVote" function, you can do it such as below :
contract.methods.createVote(...).send(from: signer.address)
Apr 27, 2022, 10:08 AM
I guess I use exactly the same approach
Apr 27, 2022, 10:12 AM
can you share the solidity function that owner modifier was used in it .
Apr 27, 2022, 10:47 AM
Hmmm. Not sure sorry. I usually just use blogs for the individual thing I'm looking to create
Apr 27, 2022, 10:57 AM
yes sure
This is quite simple code I guess
Apr 27, 2022, 10:59 AM
in wich function you used modifier ?
Apr 27, 2022, 10:59 AM
Okay. I do emit in this modifier and I've got this address
address: '0xdE8e8F3e4092520d7A6529F90573230A5D251dC8'
This is address is not owner address.
But why web3.js make call from another address? I pass needed address to the send args:
.send({
from: signer.address,
gas: await tx.estimateGas(),
})
address: '0xdE8e8F3e4092520d7A6529F90573230A5D251dC8'
This is address is not owner address.
But why web3.js make call from another address? I pass needed address to the send args:
.send({
from: signer.address,
gas: await tx.estimateGas(),
})
Apr 27, 2022, 11:04 AM
Test it by this structure please
Apr 27, 2022, 11:11 AM
let me try
Apr 27, 2022, 11:14 AM
that could be some default ?
Apr 27, 2022, 11:19 AM
thanks! Seems like it works now!
Apr 27, 2022, 11:23 AM
🌹🌹🌹
Apr 27, 2022, 11:27 AM