Giter Site home page Giter Site logo

ethereum-sdk's Introduction

ethereum-sdk

Init.

const client = require('/index');
client.config.serverURL = "https://rinkeby.infura.io/B4rowWld8aRhqdqUUcKF";
client.config.contracts = require('../conf/contracts');

Config.

ethereum server url.

client.config.serverURL 

ethereum contracts config.

{
  "Token": {
    "address": "0x6062b12c40be844603858dd14902b35175227925",
    "abi": [{
      "constant": true,
      "inputs": [],
      "name": "name",
      "outputs": [{
        "name": "",
        "type": "string"
      }],
      "payable": false,
      "stateMutability": "view",
      "type": "function"
    },{
        ...
    }]
  },
  ...
}

Using.

contract

invoke method.

/**
 * @param contract : contract name[string].
 * @param method : contract method name[string].
 * @param params : method params [array].
 * @param value : value.
 * @param gasLimit : gasLimit.
 * @param id : id.
 * @param sender : contract method caller[string],The sender is public key when the method type is called;The sender is private key when the method type is send.
 */
invoke: async function ({
    contract: 'Token',
    method: 'transferFrom',
    params: ["0xc66cd3deec506713d653681c7663f2c4fe96fb3f", "0x7ebef78f23fe5cac4d5c5d7ad76008129fa5bfd8", 5],
    gasLimit: 60000,
    value: 0,
    sender: '0xec8eab91f6dc1ddb8c9d25f03f4d7db88fa34ccc8c79abc0a15a7959da9b8a85',
    id: 10002
})

call contract.

// call Token [name]
client.invoke({
    contract: 'Token',
    method: 'name',
    sender: '0xc66cd3deec506713d653681c7663f2c4fe96fb3f'
}).then(function (data) {
    console.log(data);
});

send contract.

// send Token [approve]
client.invoke({
    contract: 'Token',
    method: 'approve',
    params:["0x7ebef78f23fe5cac4d5c5d7ad76008129fa5bfd8",999],
    gasLimit: 46000,
    sender: '605297a0025b7b6bff5b7d219e78cd4f7c4dce928e86069d64c99a47547aa1e9'
}).then(function (data) {
    console.log(data);
});

transfer

transfer method

/**
 * @param to : to account.
 * @param value : value[wei].
 * @param gasLimit : gasLimit.
 * @param id : id.
 * @param sender : contract method caller[string],The sender is public key when the method type is called;The sender is private key when the method type is send.
 */
transfer: async function ({
    to: "0x7ebef78f23fe5cac4d5c5d7ad76008129fa5bfd8",
    value: 1,
    sender: '0x605297a0025b7b6bff5b7d219e78cd4f7c4dce928e86069d64c99a47547aa1e9',
    gasLimit: 60000,
    id: 'transfer001'
})

transfer 1 wei

client.transfer({
    to: "0x7ebef78f23fe5cac4d5c5d7ad76008129fa5bfd8",
    value: 1,
    sender: '0x605297a0025b7b6bff5b7d219e78cd4f7c4dce928e86069d64c99a47547aa1e9',
    gasLimit: 60000,
    id: 'transfer001'
}).then(function (data) {
    console.log(data);
});

web3

You must initialize before use.

client.init();
or
client.reset();

gasPrice.

var gasPrice =  client.web3.eth.getGasPrice();

ethereum-sdk's People

Watchers

hello 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.