Go-Ethereum

Ethereum-PHP 呼叫帶參數的合約函式

  • April 25, 2018

我不是乙太坊部分的作者,但必須使用 php 連接。選擇 Ethereum-PHP 包 ( https://github.com/digitaldonkey/ethereum-php )。已連接乙太坊和智能合約,但無法成功執行帶參數的智能合約功能。我有 Schema 契約和功能測試():

function test(uint value) public returns(uint) {
return value*2;
}

和 ABI:

...
{"constant":false,"inputs":[{"name":"value","type":"uint256"}],
"name":"test","outputs":
[{"name":"","type":"uint256"}],
"payable":false,"stateMutability":"nonpayable","type":"function"}
...

現在在php中我有:

 $eth = new Ethereum('https://kovan.infura.io/<unique address>');
 $schemaContract = new SmartContract($abi, '<contract address>', $eth);

 // Call a function with result : 2
 $result = $schemaContract->test(1)->Val();

我無法收到結果。不知道具體如何實現這一點。嘗試了許多不同的選項,例如:

$result = $schemaContract->test(1);
$result = $schemaContract->test('1');
$result = $schemaContract->test(1);
$result = $schemaContract->__call('test',1);

但總是收到一些錯誤消息。

我究竟做錯了什麼?

最好的問候,結核病

檢查我發現的單元測試

public function testSimpleContract()
{
   $number = 2;
   $result = $this->contract->multiplyWithSeven(
       new EthQ($number, ['abi'=> 'uint256'])
   );
   $this->assertEquals($number*7, $result->val());
}

如果你這樣做,它可能會起作用

$result = $schemaContract->test(
   new EthQ(1, ['abi' => 'uint256'])
);
echo $result->val();

引用自:https://ethereum.stackexchange.com/questions/46709