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

trouble trying to send data #333

Open
hafizah65 opened this issue Sep 13, 2023 · 1 comment
Open

trouble trying to send data #333

hafizah65 opened this issue Sep 13, 2023 · 1 comment

Comments

@hafizah65
Copy link

i'm trying to send the data but i got the following error. i managed to get an existing data from the blockchain, but sending gives out either "Please make sure you have put all function params and callback"

solidity function

     function addInfo(
 uint256 uniqueKey,
     string memory _userInfo
     ) public {
     uniqueKeyIndexes[uniqueKey].push(uniqueKey);
    userInfo[uniqueKey] = _userInfo;
emit infoAdded(uniqueKey);
    }

php

    $web3 = new Web3(getenv('NODE_PATH') . ':8545'); 
    $abiAddress = 'contract.json'; 
    $contractAbi = json_decode(file_get_contents($abiAddress));

    $contract = new Contract($web3->getProvider(), $contractAbi->abi);

    $senderAddress = 'sender_add';
    $contractAddress = 'contact_add';

    $functionName = 'addInfo';
    $data = [123, $data_bc];

    $privateKey = '123priv';

    $contract->at($contractAddress)->send($functionName, $data, function ($err, $transactionHash) use ($web3, $privateKey) {
        if ($err !== null) {
            echo 'Error: ' . $err->getMessage() . PHP_EOL;
        } else {
            // Sign the transaction
            $signedTransaction = $web3->eth->accounts->signTransaction([
                'data' => $transactionHash,
            ], $privateKey);

            // Send the signed transaction to the network
            $web3->eth->sendRawTransaction($signedTransaction, function ($err, $transactionHash) {
                if ($err !== null) {
                "echo 'Error sending transacton: ' . $err->getMessage() . PHP_EOL;
                } else {
                    echo 'Transaction Hash: ' . Utils::toString($transactionHash) . PHP_EOL;
                }
            });
        }
    }); //FIXME: error here

i'm not exactly sure what i've done wrong. i've tried following #238 and i got "Wrong type of eth_sendTransaction method argument 0"

    $data_new = json_decode($data_bc, true);
    $data_new['from'] = $senderAddress;
    $data_new['privateKey'] = $privateKey;

    $data_new = json_encode($data_new);

    $contract->at($contractAddress)->send($functionName, 5678, $data_new, function ($err, $transres) use (&$done) {
        if ($err) {
            echo 'error: ' . $err->getMessage() . "<br>";
        } else {
            $done = $transres;
        }
    }); //FIXME: Wrong type of eth_sendTransaction method argument 0`
@hafizah65 hafizah65 changed the title error trying to send data trouble trying to send data Sep 13, 2023
@hafizah65
Copy link
Author

update: i change the code and i'm getting "Call to a member function signTransaction() on bool"

   $eth = new Eth($web3->getProvider());
    // Create the transaction object
    $transaction = [
        'from' => $senderAddress,
        'to' => $contractAddress,
        'data' => $contract->getData($functionName, 5678, $data_bc),
        //'data' => '0x'. $contract->getData($functionName, 5678, $data_bc),

    // Sign the transaction
    $signedTransaction = $eth->accounts->signTransaction($transaction, $privateKey); //FIXME
    ];

    // Send the transaction to the network
    $transactionHash = $eth->sendRawTransaction($signedTransaction);

    echo 'Transaction Hash: ' . Utils::toString($transactionHash) . PHP_EOL;

    // Wait for the transaction to be mined
    $receipt = $eth->getTransactionReceipt($transactionHash);
    if ($receipt !== null) {
        echo 'Transaction Mined' . PHP_EOL;
    }

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

1 participant