« SDKBOX Home

ETHWallet Plugin

Overview

ETHWallet is a js plugin which implement ether pay function. this plugin can make your app support ether pay.(just support Cocos Creator js for now)

Sample Project

A demo project on github

Integration

you can run follow cmd to integrate EthWallet, make sure you have installed SDKBox Installer

$ sdkbox import ethwallet -p `path/to/build/jsb-xxx`

Usage

Import

there have two way to import EthWallet to your project:

const ETHWallet = require('../sdkbox/ethwallet/ethwallet');
const ethwallet = new ETHWallet();
const ethwallet = new ETHWallet();

Initialize

you must set provider to init ETHWallet. provider is a ether node, you can use Infura or Etherscan or your own self ether node.

const PROVIDER_URL = 'https://ropsten.infura.io/L3BRNAgKihyPmcyI1ESe';
ethwallet.init(PROVIDER_URL);

Load Address

create or load a user address.

EthWallet will create a new address at first time or user address not exist.

Params:

Return:

const pw = 'password';
const acc = ethwallet.newAccountIf(pw);

Check Balance

ethwallet.getBalance(function(result){
    self.log(JSON.stringify(result));
}, this.acc.address);

API


ETHWallet Initialize

Params:

ETHWallet.init(providerURL)

set ETHWallet trans Gas max limit value, default is 21000

ETHWallet.setGasLimit(valueInWei)

create or load ETHWallet user pay address

Param:

ETHWallet.newAccountIf(password)

remit user pay address to developer's address

Params:

ETHWallet.remit(cb, address, valueInWei, privateKey)

check balance of address

Params:

ETHWallet.getBalance(cb, address)

Manual integration

cp follow files, which is under pakcage path, to asset/sdkbox/ethwallet

plugin/lib/a-ethwallet-polyfill-fore-cocos.js,

plugin/lib/a-ethwallet-polyfill-fore-cocos.js.meta,

plugin/lib/ethwallet.js,

plugin/lib/ethwallet.js.meta

invoke ETHWallet in your project, like follow:

const ETHWallet = require('../sdkbox/ethwallet/ethwallet');
const ethwallet = new ETHWallet();

Note

you can check your transaction by search it on https://etherscan.io/.