EOSIO / eosjs

General purpose library for the EOSIO blockchain.
http://eosio.github.io/eosjs
MIT License
1.43k stars 463 forks source link

need a sample eosjs hello word code #164

Closed alzozov closed 6 years ago

alzozov commented 6 years ago

I have tried different code samples of eosjs to ping contract on latest eos 1.0.1 but non of them worked.

Will be very thankful if somebody can share working eosjs code to call sample action of following contract.

#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>

class hello : public eosio::contract {
  public:

    hello(account_name self)
      :eosio::contract(self)
    {}

    /// @abi action
    void ping(account_name author) {

      eosio::print("pong1");

    }

};

EOSIO_ABI(hello, (ping)) 
lingyiliu016 commented 6 years ago

let EOS = require('eosjs')

eos = EOS.Localnet({ chainId:"a4fe43c897279a677025624555f3835b949f995f87923c97f0392dcff835bfd0", keyProvider:['5KcHE3HF4zAecKWFxBiizG3KBPpkBxbbMDAn1HPeHQZecy69bZy','5KQVzEFg4PbDNtCbdhbfgwfaqQYPNzhjna3ZCm5AzrFZCpeoccg'], httpEndpoint:'http://127.0.0.1:8888' })

eos.contract('child.acnt').then((contract) => { contract.ping("child.acnt",{authorization:['child.acnt']}).then((res) => { console.log(res) }) })

alzozov commented 6 years ago

@lingyiliu016 thanks!

ghost commented 6 years ago

useful~thanks!