HansPeterLoft
HansPeterLoft

Reputation: 519

PHP array in callback smart contract web3.php

I try to read out a smart contract with web3.php, which works fine now, but I always only can read out a function, that returns a single value. When I call a function that returns for example a uint8 array, then I cannot call the elements of the array with ..[index].

Web3.php: (https://github.com/sc0Vu/web3.php)

That is my callback function:

$contract->at($contractAddress)->call($functionName, function ($err, $result) use ($contract) {
    if ($err !== null) {
        echo "error";
        throw $err;
    }

    if ($result) {
        $supply = $result;
        echo $supply;
    }
});

Has anyone an idea how I can receive an array in a callback in php?

Upvotes: 1

Views: 1608

Answers (1)

Benjamin
Benjamin

Reputation: 1

You can see the answer in the author github "https://github.com/sc0Vu/web3.php".

$newAccount = '';

$web3->personal->newAccount('123456', function ($err, $account) use (&$newAccount) {
    if ($err !== null) {
        echo 'Error: ' . $err->getMessage();
        return;
    }
    $newAccount = $account;
    echo 'New account: ' . $account . PHP_EOL;
});

Upvotes: -1

Related Questions