types/value length mismatch (argument="tuple", value='myAddress' #6321
Replies: 1 comment 1 reply
-
|
Hi. This repo is for the Remix Web Framework https://remix.run It looks like you're looking for the Remix Ethereum IDE repo https://github.com/ethereum/remix-project |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm not sure this is the right place to ask this question, but I'm desperate, sorry for the incoveniencie if it's not.
I'm having some problem with the arguments of a function written in solidity and called in JavaScript. I'm using the Remix ballot default example, except I removed the first require in it. It looks like this:
function giveRightToVote(address voter) public { require( !voters[voter].voted, "The voter already voted." ); require(voters[voter].weight == 0); voters[voter].weight = 1;}As far as I'm understanding, I should give it an address so it can give permission to that address. This is the JavaScript code that calls that function:
const permission = async () => { const ethereumAddress = web3.utils.toChecksumAddress(account); const gasEstimate = await window.contract.methods.giveRightToVote(ethereumAddress).estimateGas({ from: account }); const result = await window.contract.methods.giveRightToVote(ethereumAddress).send({ gas: gasEstimate, from: account}); document.getElementById("permissionArea").innerHTML = "Permiso para votar obtenido"; /** await window.contract.methods.giveRightToVote(account).send({ from: account }); document.getElementById("permissionArea").innerHTML = "Permiso para votar obtenido"; */ }The last commented part was the original code. I have changed it a lot trying to make it work. I kind of guess the problem is the argument account. I have tried using [account] which has worked in another function, but I seem to not be able to figure out how it wants the parameters. I know the account is right, I get it like this:
const accounts = await ethereum.request({method: "eth_requestAccounts"}); account = accounts[0];And when I print it it's the right address. The full error reads:
Error: types/value length mismatch (argument="tuple", value=["0x40bCba26F1ED151Fa34232E3CFf55d9C2867bCf1"], code=INVALID_ARGUMENT, version=abi/5.7.0)This is not the only function that shows this same problem, in fact, I can't send any argument to the solidity functions. I have this vote function that only requires a integer (uint) as an argument. If I just send 0 for example it gives me the error I just addressed. But if I make a javascript Uint8Array and send the complete array like this:
let numero = new Uint8Array(1); number[0]=selectedCandidate; const gasEstimate = await window.contract.methods.vote(number).estimateGas({ from: account }); await window.contract.methods.vote(numero).send({ gas: gasEstimate, from: account });It shows a different error:
MetaMask - RPC Error: Internal JSON-RPC error. {code: -32603, message: 'Internal JSON-RPC error.', data: {…}} inpage.js:1And
Uncaught (in promise) Error: Internal JSON-RPC error. web3.min.js:2 { "message": "VM Exception while processing transaction: revert", "stack": "RuntimeError: VM Exception while processing transaction: revert\n at exactimate (C:\\Users\\pc\\AppData\\Local\\Programs\\Ganache\\resources\\static\\node\\node_modules\\ganache\\dist\\node\\1.js:2:182136)", "code": -32000, "name": "RuntimeError", "data": { "hash": null, "programCounter": 130, "result": "0x", "reason": null, "message": "revert" } }I'm still confused that it wants a tuple when the smart contract only takes one argument; any idea what problem I just run into?
PD: I'm using ganache as the blockchain emulator (localhost:7545) and lite-server as the web server (localhost:3000); also the Smart Contract works in remix, but not when I call it with javascript.
Beta Was this translation helpful? Give feedback.
All reactions