laravel-ethereum icon indicating copy to clipboard operation
laravel-ethereum copied to clipboard

How to create transaction

Open truongthaison opened this issue 6 years ago • 1 comments

Hi,

i use method: personal_sendTransaction, but i get error:-32602 "invalid argument 0: json: cannot unmarshal non-string into Go struct field SendTxArgs.value of type *hexutil.Big"

I try with GuzzleHttp

$client = new Client();
$parameters = [
			'method' => 'personal_sendTransaction',
			'params' => [
				[
					'from'  => '0x59c779xxx',
					'to'    => '0xac3f9786xxxx',
					'value' => 0000000
				],
				'xxxxxx'
			],
			'id' => 1
		];
$response = $client->request('POST', 'my_ip:port', ['json' => $parameters]);

But, not run.

please help me

truongthaison avatar Jun 18 '18 12:06 truongthaison

@Vagabondtq

I managed to create a transaction, I had to import some other classes to help me with that.

Here the code that I'm using.

$from = '0x64ADaa845975244Cb794a22032abF03746e1708d';
$to = '0xE946DD64D861c20a81fdaF43bFfE225Ee0C755De';
$value = 10;
$transaction = new EthereumTransaction($from, $to, $this->parseQuantity($value));
return Ethereum::eth_sendTransaction($transaction);

Parse Quantity Function

/**
 * @param $value
 * @return string
 */
private function parseQuantity($value)
{
    $converter = new Converter();
    return '0x' . BC::dechex($converter->toWei($value));
}

Hope that I helped.

Kind regards.

amandiobm avatar Sep 18 '18 18:09 amandiobm