diff --git a/src/Utils.php b/src/Utils.php index 44e309c..c2a10e4 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -11,6 +11,7 @@ namespace Web3; +use RuntimeException; use InvalidArgumentException; use stdClass; use kornrunner\Keccak; @@ -214,6 +215,22 @@ class Utils return '0x' . $hash; } + /** + * toString + * + * @param mixed $value + * @return string + */ + public function toString($value) + { + try { + $value = (string) $value; + } catch (\Exception $e) { + throw new RuntimeException('Cannot transform value to string!'); + } + return $value; + } + /** * toWei * Change number from unit to wei.