contract = new Contract('http://localhost:8545', $this->testAbi); // $this->contract = new Contract($this->web3->provider, $this->testAbi); $this->contract->eth->accounts(function ($err, $accounts) { if ($err === null) { if (isset($accounts->result)) { $this->accounts = $accounts->result; return; } } }); } /** * testDeploy * * @return void */ public function testDeploy() { $contract = $this->contract; if (!isset($this->accounts[0])) { $account = '0x407d73d8a49eeb85d32cf465507dd71d507100c1'; } else { $account = $this->accounts[0]; } $contract->bytecode($this->testBytecode)->new(1000000, 'Game Token', 1, 'GT', [ 'from' => $account, 'gas' => '0x200b20' ], function ($err, $result) use ($contract) { if ($err !== null) { // infura api gg return $this->assertTrue($err !== null); } if ($result->result) { echo "\nTransaction has made:) id: " . $result->result . "\n"; } $transactionId = $result->result; $this->assertTrue((preg_match('/^0x[a-f0-9]{64}$/', $transactionId) === 1)); $contract->eth->getTransactionReceipt($transactionId, function ($err, $transaction) { if ($err !== null) { return $this->fail($err); } if ($transaction->result) { $this->contractAddress = $transaction->result->contractAddress; echo "\nTransaction has mind:) block number: " . $transaction->result->blockNumber . "\n"; } }); }); } /** * testSend * * @return void */ public function testSend() { $contract = $this->contract; if (!isset($this->accounts[0])) { $fromAccount = '0x407d73d8a49eeb85d32cf465507dd71d507100c1'; } else { $fromAccount = $this->accounts[0]; } if (!isset($this->accounts[1])) { $toAccount = '0x407d73d8a49eeb85d32cf465507dd71d507100c2'; } else { $toAccount = $this->accounts[1]; } $contract->bytecode($this->testBytecode)->new(1000000, 'Game Token', 1, 'GT', [ 'from' => $fromAccount, 'gas' => '0x200b20' ], function ($err, $result) use ($contract) { if ($err !== null) { // infura api gg return $this->assertTrue($err !== null); } if ($result->result) { echo "\nTransaction has made:) id: " . $result->result . "\n"; } $transactionId = $result->result; $this->assertTrue((preg_match('/^0x[a-f0-9]{64}$/', $transactionId) === 1)); $contract->eth->getTransactionReceipt($transactionId, function ($err, $transaction) { if ($err !== null) { return $this->fail($err); } if ($transaction->result) { $this->contractAddress = $transaction->result->contractAddress; echo "\nTransaction has mind:) block number: " . $transaction->result->blockNumber . "\n"; } }); }); $contract->at($this->contractAddress)->send('transfer', $toAccount, 16, [ 'from' => $fromAccount, 'gas' => '0x200b20' ], function ($err, $result) use ($contract, $fromAccount, $toAccount) { if ($err !== null) { // infura api gg return $this->assertTrue($err !== null); } if ($result->result) { echo "\nTransaction has made:) id: " . $result->result . "\n"; } $transactionId = $result->result; $this->assertTrue((preg_match('/^0x[a-f0-9]{64}$/', $transactionId) === 1)); $contract->eth->getTransactionReceipt($transactionId, function ($err, $transaction) use ($fromAccount, $toAccount) { if ($err !== null) { return $this->fail($err); } if ($transaction->result) { $topics = $transaction->result->logs[0]->topics; echo "\nTransaction has mind:) block number: " . $transaction->result->blockNumber . "\n"; // validate topics $this->assertEquals(Ethabi::encodeEventSignature($this->contract->events['Transfer']), $topics[0]); $this->assertEquals('0x' . IntegerFormatter::format($fromAccount), $topics[1]); $this->assertEquals('0x' . IntegerFormatter::format($toAccount), $topics[2]); } }); }); } }