https://github.com/wavesplatform/waves-php
PHP library for interacting with the Waves blockchain.
https://github.com/wavesplatform/waves-php
Last synced: 8 months ago
JSON representation
PHP library for interacting with the Waves blockchain.
- Host: GitHub
- URL: https://github.com/wavesplatform/waves-php
- Owner: wavesplatform
- License: mit
- Created: 2022-07-29T10:20:34.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-15T14:36:01.000Z (over 1 year ago)
- Last Synced: 2024-12-02T18:59:42.879Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 73.2 KB
- Stars: 7
- Watchers: 7
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Waves-PHP
[](https://packagist.org/packages/waves/client)
[](https://packagist.org/packages/waves/client)
[](https://app.codecov.io/gh/wavesplatform/waves-php)
[](https://github.com/wavesplatform/waves-php/blob/main/.github/workflows/phpstan.yml#L35)
[](https://github.com/wavesplatform/waves-php/actions/workflows/codecov.yml)
[](https://github.com/wavesplatform/waves-php/actions/workflows/phpstan.yml)
[](https://github.com/wavesplatform/waves-php/actions/workflows/phpunit.yml)
PHP client library for interacting with Waves blockchain platform.
## Installation
```bash
composer require waves/client
```
## Usage
See [`example.php`](example.php) for full code examples.
- New account:
```php
$account = PrivateKey::fromSeed( 'your mnemonic seed phrase' );
$sender = $account->publicKey();
echo 'address = ' . $sender->address()->toString() . PHP_EOL;
```
- Node basics:
```php
$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;
```
- Transfer transaction:
```php
$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 invocation transaction:
```php
$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() );
```
## Requirements
- [PHP](http://php.net) >= 7.4