Home > Mobile >  WEB3.PHP Contract Call
WEB3.PHP Contract Call

Time:01-25

I am using this PHP library enter image description here

And here's the code:

$contract->at('0x10ED43C718714eb63d5aA57B78B54704E256024E')->call('quote', [
    '25000000000000000000',
    '[0x8C851d1a123Ff703BD1f9dabe631b69902Df5f97, 0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56]',
], function($err, $result) {
    print_r($result);
});

I get the following error. Tried to send the parameters as dictionary with param name. Couldn't figure out how should be done.

InvalidArgumentException
Please make sure you have put all function params and callback.

CodePudding user response:

  1. Your snippet tries to encode the second param as an array but you're passing a string.
  2. The number of $params is dynamic in the PHP code, don't wrap them in an array.
$contract->at('0x10ED43C718714eb63d5aA57B78B54704E256024E')->call(
    // function name
    'getAmountsOut',

    // note the removed array wrapper

    // first param
    '25000000000000000000',

    // second param
    [
        '0x8C851d1a123Ff703BD1f9dabe631b69902Df5f97',
        '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56'
    ],

    // callback
    function($err, $result) {
        print_r($result);
    }
);
  • Related