web3p / web3.php

A php interface for interacting with the Ethereum blockchain and ecosystem. Native ABI parsing and smart contract interactions.
MIT License
1.15k stars 540 forks source link

Example of loading ABI or resolve constructor aren't able to add functions, and events #314

Open haruu8 opened 1 year ago

haruu8 commented 1 year ago

Please post an example of loading $abi or resolve constructor problem.

I can load $abi but $contract->constructor functions, and events doesn't exist so I got the error below when I try to do estimateGas->('functionName', [params]).

exception: "InvalidArgumentException"
file: "/api/vendor/web3p/web3.php/src/Contract.php"
line: 719
message: "Please make sure the method exists."

code

$abi = file_get_contents(base_path('abi/contracts/SupportTicketV0.sol/SupportTicketV0.json'));
$contract = new Contract('http://localhost:8545', $abi);

$contract->at('0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0')
            ->estimateGas(
                'mint',
                [
                    '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
                ],
                [
                    $fromWalletAddress,
                    $toWalletAddress,
                    $quantity,
                    $tokenURIs,
                ],

Also I checked getFunctions and returned empty array like return $contract->getFunctions();.

I guess $abi must be formatted before loading but I'm not sure how format it. $abi is just generated from yarn hardhat compile.

Thank you.