PHP code example of kadena-php / client
1. Go to this page and download the library: Download kadena-php/client library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kadena-php / client example snippets
$keyPair = KeyFactory::generate();
creationTime: Carbon::now(),
ttl: 7200,
gasLimit: 10000,
chainId: '0',
gasPrice: 1e-8,
sender: ''
$factory = new MetadataFactory();
$metadata = $factory->withOptions([
'chainId' => '1',
])->make();
$publicKey = KeyFactory::publicKeyFromHex('not-a-real-key');
$transferCapability = new Capability(
name: 'coin.transfer',
arguments: [
'address-from',
'address-to',
5
]
);
$signer = new Signer(
publicKey: $publicKey,
capabilities: new CapabilityCollection($transferCapability)
)
$executePayload new ExecutePayload(
code: '(+ 1 2)'
);
$continuePayload = new ContinuePayload(
pactId: 'pact-id',
rollback: false,
step: 0
);
$factory = new CommandFactory();
$factory->withExecutePayload($executePayload)
->withMetadata($metadata)
->withSigners(new SignerCollection($signer))
->withNetworkId('mainnet0')
->withNonce('nonce-string')
->make();
$kpc = new KeyPairCollection($keypair);
$signedCommand = CommandSigner::sign($command, $kpc);
$signedCommand = SignedCommandMapper::fromString($commandString)
$commandString = SignedCommandMapper::toString($signedCommand);
$commandArray = SignedCommandMapper::toArray($signedCommand);
$client = new \Kadena\Client('http://localhost:8888'); // or whatever local config you have
$local = $client->local($signedCommand);
$send = $client->send(new SignedCommandCollection($signedCommand));
$requestKey = $send->first(); // Get a RequestKey from the send response above
$listen = $client->single($requestKey);
$requestKeyCollection = $send; // The send() method above returned a RequestKeyCollection
$poll = $client->poll($requestKeyCollection);
$spv = $client->spv($requestKey, '2');
bash
composer