waves / client
用于与 Waves 区块链平台交互的 PHP 客户端库
v1.0.4
2024-08-15 14:30 UTC
Requires
- php: >=7.4
- deemru/abcode: ^1.0
- deemru/waveskit: ^1.0
- waves/protobuf: ^1.4
Requires (Dev)
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^9.5
README
用于与 Waves 区块链平台交互的 PHP 客户端库。
安装
composer require waves/client
使用
查看 example.php
获取完整的代码示例。
- 新建账户
$account = PrivateKey::fromSeed( 'your mnemonic seed phrase' ); $sender = $account->publicKey(); echo 'address = ' . $sender->address()->toString() . PHP_EOL;
- 节点基础
$nodeChainId = $node->chainId(); echo 'node chainId = ' . $nodeChainId->asString() . PHP_EOL; $nodeVersion = $node->getVersion(); echo 'node version = ' . $nodeVersion . PHP_EOL; $nodeHeight = $node->getHeight(); echo 'node height = ' . $nodeHeight . PHP_EOL;
- 转账交易
$amount = Amount::of( 1 ); // 0.00000001 Waves $recipient = Recipient::fromAddressOrAlias( 'test' ); // from alias $recipient = Recipient::fromAddressOrAlias( '3N9WtaPoD1tMrDZRG26wA142Byd35tLhnLU' ); // from address $transferTx = TransferTransaction::build( $sender, $recipient, $amount ); $transferTxSigned = $transferTx->addProof( $account ); $transferTxBroadcasted = $node->broadcast( $transferTxSigned ); $transferTxConfirmed = $node->waitForTransaction( $transferTxBroadcasted->id() );
- DApp 调用交易
$dApp = Recipient::fromAddressOrAlias( '3N7uoMNjqNt1jf9q9f9BSr7ASk1QtzJABEY' ); $functionCall = FunctionCall::as( 'retransmit', [ Arg::as( Arg::STRING, Value::as( $sender->address()->toString() ) ), Arg::as( Arg::INTEGER, Value::as( 1 ) ), Arg::as( Arg::BINARY, Value::as( hash( 'sha256', $sender->address()->toString(), true ) ) ), Arg::as( Arg::BOOLEAN, Value::as( true ) ), ] ); $payments = [ Amount::of( 1000 ), ]; $invokeTx = InvokeScriptTransaction::build( $sender, $dApp, $functionCall, $payments ); $invokeTxSigned = $invokeTx->addProof( $account ); $invokeTxBroadcasted = $node->broadcast( $invokeTxSigned ); $invokeTxConfirmed = $node->waitForTransaction( $invokeTxBroadcasted->id() );
要求
- PHP >= 7.4