diff --git a/src/Methods/EthClient.php b/src/Methods/EthClient.php index 0368d19..75be518 100644 --- a/src/Methods/EthClient.php +++ b/src/Methods/EthClient.php @@ -59,12 +59,12 @@ public function hashRate(): int return hexdec($response->getRpcResult()); } - public function gasPrice(): Wei + public function gasPrice(): ?Wei { $response = $this->client->send( $this->client->request(73, 'eth_gasPrice', []) ); - return new Wei(hexdec($response->getRpcResult())); + return ($response->getRpcResult()) ? new Wei(hexdec($response->getRpcResult())) : null; } /** @@ -90,12 +90,12 @@ public function blockNumber(): int return hexdec($response->getRpcResult()); } - public function getBalance(Address $address, BlockNumber $blockNumber): Wei + public function getBalance(Address $address, BlockNumber $blockNumber): ?Wei { $response = $this->client->send( $this->client->request(1, 'eth_getBalance', [$address->toString(), $blockNumber->toString()]) ); - return new Wei(\Phlib\base_convert($response->getRpcResult(), 16, 10)); + return ($response->getRpcResult()) ? new Wei(\Phlib\base_convert($response->getRpcResult(), 16, 10)) : null; } public function getStorageAt(Address $address, int $quantity, BlockNumber $blockNumber): string @@ -164,20 +164,20 @@ public function sign(Address $address, string $msgToSign) return $response->getRpcResult(); } - public function sendTransaction(Transaction $transaction): TransactionHash + public function sendTransaction(Transaction $transaction): ?TransactionHash { $response = $this->client->send( $this->client->request(1, 'eth_sendTransaction', [$transaction->toArray()]) ); - return new TransactionHash($response->getRpcResult()); + return ($response->getRpcResult()) ? new TransactionHash($response->getRpcResult()) : null; } - public function sendRawTransaction(string $data): TransactionHash + public function sendRawTransaction(string $data): ?TransactionHash { $response = $this->client->send( $this->client->request(1, 'eth_sendRawTransaction', [$data]) ); - return new TransactionHash($response->getRpcResult()); + return ($response->getRpcResult()) ? new TransactionHash($response->getRpcResult()) : null; } public function call(Transaction $transaction, BlockNumber $blockNumber): string diff --git a/src/Methods/PersonalClient.php b/src/Methods/PersonalClient.php index e449b7b..1ee8ef7 100644 --- a/src/Methods/PersonalClient.php +++ b/src/Methods/PersonalClient.php @@ -28,13 +28,13 @@ public function listAccounts(): array return $addresses; } - public function newAccount(string $password): Address + public function newAccount(string $password): ?Address { $response = $this->client->send( $this->client->request(67, 'personal_newAccount', [$password]) ); - return new Address($response->getRpcResult()); + return ($response->getRpcResult()) ? new Address($response->getRpcResult()) : null; } public function unlockAccount(Address $address, string $password, int $duration): bool @@ -46,12 +46,12 @@ public function unlockAccount(Address $address, string $password, int $duration) return empty($result) ? false : true; } - public function sendTransaction(Transaction $transaction, string $password): TransactionHash + public function sendTransaction(Transaction $transaction, string $password): ?TransactionHash { $response = $this->client->send( $this->client->request(1, 'personal_sendTransaction', [$transaction->toArray(), $password]) ); - return new TransactionHash($response->getRpcResult()); + return ($response->getRpcResult()) ? new TransactionHash($response->getRpcResult()) : null; } public function sign(string $message, Address $address, string $password): string @@ -62,11 +62,11 @@ public function sign(string $message, Address $address, string $password): strin return $response->getRpcResult(); } - public function ecRecover(string $message, string $signature): TransactionHash + public function ecRecover(string $message, string $signature): ?TransactionHash { $response = $this->client->send( $this->client->request(1, 'personal_ecRecover', [$message, $signature]) ); - return new Address($response->getRpcResult()); + return ($response->getRpcResult()) ? new Address($response->getRpcResult()) : null; } }