Skip to content

wudameinv/aelf-sdk.php

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AElf-sdk.php

AElf php SDK

$ composer require AElf/AElf-sdk

Usage

Basic usage

Examples

You can also see full examples in ./example;

  1. Create a new instance of AElf, connect to an AElf chain node.

    <?php
    
    require_once 'vendor/autoload.php';
    use AElf\AElf;
    $url = '127.0.0.1:8000';
    $AElf = new AElf($url);
  2. Create or load a wallet with AElf.wallet;

    use use AElf\AElfECDSA\AElfECDSA;
    // create a new wallet
    $AElfECDSA = new AElfECDSA();
    // load a wallet by private key
    $private_key = 'be3abe5c1439899ac2efd0001e15715fd989a3ae11f09e1cb95d320cd4993e2a';
    $AElfECDSA->setPrivateKey($private_key);
    // To obtain the public key
    $public_key = $AElfECDSA->getUncompressedPubKey();
  3. Get a system contract address, take AElf.ContractNames.Token as an example

    $tokenContractName = 'AElf.ContractNames.Token';

$tokenContractAddress = $AElf->getContractAddressByName($private_key,hex2bin(hash('sha256',$tokenContractName))); 4. Get a contract instance by contract addressphp $tokenContractName = 'AElf.ContractNames.Token';

$tokenContract = $AElf->getTransactionResults($tokenContractAddress);
```
  1. How to use contract instance

    A contract instance consists of several contract methods and methods can be called in two ways: read-only and send transaction

    $params = hex2bin(hash('sha256','AElf.ContractNames.Vote'));
    $transactionObj  = $this->AElf->generateTransaction($this->address,$AElf->getGenesisContractAddress(),'GetContractAddressByName',$params);
    $signature = $AElf->signTransaction($private_key,$transactionObj);
    $transactionObj->setSignature(hex2bin($signature));
    $executeTransactionDtoObj =['RawTransaction'=>bin2hex($transaction->serializeToString())];
    $result =  $AElf->sendTransaction($executeTransactionDtoObj);
    print_r($result);

Test

This module contains tests for all services provided by AElf. You can see how to properly use services provided by AElf here.

You need to firstly set necessary parameters to make sure tests can run successfully.

  1. Set baseUrl to your target url.

    $url = "Http://127.0.0.1:8001";

    ?>

  2. Give a valid privateKey of a node.

    $this->private_key = 'be3abe5c1439899ac2efd0001e15715fd989a3ae11f09e1cb95d320cd4993e2a';

Note

You need to run a local or remote AElf node to run the unit test successfully. If you're not familiar with how to run a node or multiple nodes, please see Running a node / Running multiple nodes for more information.

About

AElf php SDK

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 99.4%
  • Other 0.6%