Coder Social home page Coder Social logo

aelf-sdk.php's Introduction

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.

aelf-sdk.php's People

Contributors

wudameinv avatar heqiaoyu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.