issues
search
web3p
/
ethereum-tx
Ethereum transaction library in PHP.
https://www.web3p.xyz/ethereumtx.html
MIT License
183
stars
63
forks
source link
不知道为什么,代币转账失败
#43
Closed
tianheng2017
closed
3 years ago
tianheng2017
commented
3 years ago
....................... ....................... /**
@notes 获取data
@param array $data 数据
@return $this */ public function getTransactionData(array $data): self { try { if (in_array($data['symbol'], ['BNB', 'ETH'])) { return $this; } $num = bcmul($data['value'], pow(10, $this->decimals)); $num2hex = Utils::toHex($num, true); $contractAbi = new Contract($this->provider, $this->abi); $this->data = '0x'.$contractAbi->at($this->contract)->getData($this->transfer, $data['to'], $num2hex); return $this; } catch (\Exception $e) { throw new Exception($e->getMessage()); } } /**
@notes 离线签名
@param array $data 数据
@return $this */ public function signed(array $data): self { try { $transaction = new Transaction([ 'nonce' => $this->nonce, 'from' => $data['from'], 'to' => $this->contract ?: $data['to'], 'gas' => Utils::toHex($this->contract ? $this->contract_gas : $this->gas, true), 'gasPrice' => $this->gasPrice, 'value' => $this->contract ? '0x' : Utils::toHex(Utils::toWei((string)$data['value'], 'ether'), true), 'chainId' => $this->chainId, 'data' => $data['data'], ]); $this->sign = $transaction->sign($data['private_key']); return $this; } catch (\Exception $e) { throw new Exception($e->getMessage()); } } ....................... .......................
....................... ....................... /**