Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught InvalidArgumentException: Please make sure you have put all function params and callback. #349

Open
ttmartinks opened this issue Mar 28, 2024 · 1 comment

Comments

@ttmartinks
Copy link

Hello everyone.
I have a problem that i dont solving. I can't call addBlock function by passing a parameter.
Error: Uncaught InvalidArgumentException: Please make sure you have put all function params and callback.

// Appeler la fonction addBlock du contrat pour ajouter le nouveau checksum
$contract->send('addBlock', [$new_checksum], [
'from' => '0x2d1CC832643188351fC408552D089FE692aFd14a', //accountadress
'gas' => '3000000', // Limite de gaz
'gasPrice' => '20000000000', // Prix du gaz
'value' => '0', // Montant à envoyer
'nonce' => '1', // Nombre d'utilisation de la clé privée
], function($err, $transactionHash) {
if ($err !== null) {
echo 'Erreur : ' . $err->getMessage();
} else {
echo 'Transaction envoyée avec succès, hash : ' . $transactionHash;
}
});
My solidity contract: // SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract Sasoma {
struct Block {
bytes32 previousHash;
string checksum; // Changement du type de checksum de int à string
bytes32 hash;
}

Block[] public blocks;

function calculateHash(bytes memory _data) internal pure returns (bytes32) {
    return sha256(_data);
}

constructor(string memory _firstChecksum) {
    bytes32 firstPreviousHash = bytes32(0);
    bytes32 firstHash = calculateHash(abi.encodePacked(firstPreviousHash, _firstChecksum));
    blocks.push(Block(firstPreviousHash, _firstChecksum, firstHash));
}

function addBlock(string memory _checksum) public {
    bytes32 previousHash = blocks[blocks.length - 1].hash;
    bytes32 newHash = calculateHash(abi.encodePacked(previousHash, _checksum));
    blocks.push(Block(previousHash, _checksum, newHash));
}

function getBlock(uint index) external view returns (bytes32, string memory, bytes32) {
    require(index < blocks.length, "Index out of range");
    Block memory blockData = blocks[index];
    return (blockData.previousHash, blockData.checksum, blockData.hash);
}

function getLastBlock() external view returns (bytes32, string memory, bytes32) {
    require(blocks.length > 0, "No blocks available");
    Block memory lastBlock = blocks[blocks.length - 1];
    return (lastBlock.previousHash, lastBlock.checksum, lastBlock.hash);
}

}

php: // Appeler la fonction addBlock du contrat pour ajouter le nouveau checksum
$contract->send('addBlock', [$new_checksum], [
'from' => '0x2d1CC832643188351fC408552D089FE692aFd14a', //accountadress
'gas' => '3000000', // Limite de gaz
'gasPrice' => '20000000000', // Prix du gaz
'value' => '0', // Montant à envoyer
'nonce' => '1', // Nombre d'utilisation de la clé privée
], function($err, $transactionHash) {
if ($err !== null) {
echo 'Erreur : ' . $err->getMessage();
} else {
echo 'Transaction envoyée avec succès, hash : ' . $transactionHash;
}
});

Thanks you for helping me !

@aerory
Copy link

aerory commented Mar 31, 2024

Hi brother, have you solved the issue above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants