Skip to content

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

@ttmartinks

Description

@ttmartinks

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 !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions