• Stars
    star
    207
  • Rank 188,940 (Top 4 %)
  • Language
    TypeScript
  • License
    BSD 3-Clause "New...
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JS library for building browser apps & NodeJS services that interact with Loom DAppChains

Loom.js Build Status

JS library for building browser apps & NodeJS services that interact with Loom DAppChains.

Install

NodeJS

# NPM
npm install loom-js
# Yarn
yarn add loom-js

Browser

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/loom.umd.js"></script>

Debugging

loom-js uses the debug package for logging.

  • To inspect the logs when running in the browser set localStorage.debug = '*'
  • To inspect the logs when running in NodeJS set the DEBUG env var to *

See docs for debug package if you wish to filter the log messages.

Development

# build for Node
yarn build
# build for Browser
yarn build:browser
# build for Node while targeting ES2017 (more readable than ES5)
yarn build:dev
# run unit tests on Node & Browser
yarn test
# auto-format source files
yarn format
# run unit tests in Node
yarn test:node
# run unit tests in Electon
yarn test:browser
# run e2e test in Node (local DAppChain node must be running first)
yarn e2e:node
# run e2e test in Electron (local DAppChain node must be running first)
yarn e2e:browser

The e2e test environment can be configured by changing .env.test (see .env.test.example for default values).

Debugging

To debug loom-js while using it another project:

  1. Clone the Git repo from https://github.com/loomnetwork/loom-js
  2. Inside the loom-js repo run:
    yarn link
    yarn build:dev
  3. In your project repo run yarn link loom-js.
  4. Debug your project normally.

yarn build:dev will compile the TypeScript source to target ES2017, which requires a lot less transformation of async/await constructs than the ES5 code released on NPM.

Regenerating Protobufs

Whenever you change src/proto/loom.proto, or src/tests/tests.proto you will need to regenerate the corresponding *_pb.js by running:

yarn proto

The shell must be able to locate the protoc binary, which can be obtained from https://github.com/google/protobuf/releases

Custom Middlewares

LoomProvider takes a custom function that lets you customize what middlewares it runs. For example, we have an experimental nonce caching middleware that has more advanced nonce tracking. You can add it as such:

const setupMiddlewareFn = function(client, privateKey) {
  const publicKey = CryptoUtils.publicKeyFromPrivateKey(privateKey)
  return [new CachedNonceTxMiddleware(publicKey, client), new SignedTxMiddleware(privateKey)]
}

const loomProviderObj = new LoomProvider(client, privateKey, setupMiddlewareFn)

More examples here: https://github.com/loomnetwork/loom-js/blob/master/src/tests/e2e/loom-provider-web3-middlewares-tests.ts

JSON RPC supported calls

LoomProvider combined with Web3 supports the following JSON RPC calls

Current implemented

  • eth_accounts
  • eth_blockNumber
  • eth_call
  • eth_gasPrice
  • eth_getBlockByHash
  • eth_getBlockByNumber
  • eth_getCode
  • eth_getFilterChanges
  • eth_getLogs
  • eth_getTransactionByHash
  • eth_getTransactionReceipt
  • eth_newBlockFilter
  • eth_newFilter
  • eth_newPendingTransactionFilter
  • eth_sendTransaction
  • eth_subscribe
  • eth_uninstallFilter
  • eth_unsubscribe
  • net_version

Should

  • eth_getFilterLogs (Returns an array of all logs matching filter with given id)
  • eth_estimateGas (Currently, it always returns zero)

Maybe

  • net_peerCount (Returns the current ethereum protocol version)
  • eth_syncing (Returns an object with data about the sync status or false)
  • eth_coinbase (Returns the client coinbase address)
  • web3_clientVersion (Returns the current client version)
  • eth_getTransactionCount (Returns the number of transactions sent from an address)
  • eth_getBlockTransactionCountByHash (Returns the number of transactions in a block from a block matching the given block hash)
  • eth_getBlockTransactionCountByNumber (Returns the number of transactions in a block matching the given block number)

Custom Loom provider methods

Sometimes the project requires few functions that aren't provided directly from LoomProvider in this case is possible to add a custom Eth RPC method. You can add it as such:

const loomProviderObj = new LoomProvider(client, privateKey)
loomProviderObj.addCustomMethod('eth_balance', payload => {
  return '0x1'
})

The first param should be the Ethereum RPC call method to add on LoomProvider and the second parameter a callback function with the result

Overwrite Loom provider methods

If the project requires to overwrite a RPC function that already exists on LoomProvider. You can add it as such:

loomProvider.overwriteMethod('eth_estimateGas', payload => {
  return '0x123'
})

The first param should be the Ethereum RPC call method to overwrite on LoomProvider and the second parameter a callback function with the result

License

BSD 3-Clause, see LICENSE file for details.

More Repositories

1

plasma-cash

Plasma Cash Contract & Client. ERC721, ERC20, and ETH compatible
JavaScript
271
star
2

zombie-char-component

Zombie character preview
Vue
242
star
3

go-loom

Go package for building plugins and Go Smart Contracts for Loom DAppChains
Go
190
star
4

erc721x

ERC721x is an extension of ERC721 that adds support for multi-fungible tokens and batch transfers, while being fully backward-compatible.
Solidity
169
star
5

loomchain

Loom DAppChain Engine
Go
166
star
6

solidityx-js

SolidtyX is an opinionated version of Solidity.
JavaScript
124
star
7

unity-sdk

Loom DAppChain SDK for Unity3d
C#
121
star
8

truffle-dappchain-example

Example of Truffle configured with Loom Truffle Provider
JavaScript
92
star
9

solidity-social-example

Super simple social network interaction, where users can post and comment on posts
JavaScript
67
star
10

plasma-paper

Plasma Cash: Towards Improved Plasma Constructions.
TeX
50
star
11

EthDeploy

Ethdeploy is a platform for spinning up cloud based blockchains. Unrelated to dAppChains
JavaScript
43
star
12

plasma-cli

All In One stateful Plasma-Cash client, browser compatible
TypeScript
42
star
13

Etherboy

Etherboy in Blockchain world. A sample blockchain game that runs on a DAppchain.
C#
36
star
14

loom-sdk-documentation

Loom SDK Documentation Website
Shell
36
star
15

ethdeploy-client

EthDeploy - Client for deploying apps on the Ethdeploy private blockchain hosting
Go
31
star
16

transfer-gateway-example

Loom SDK Transfer Gateway ERC721 Example
JavaScript
31
star
17

loom-truffle-provider

Adapter that allows Truffle Suite to communicate with Loom DappChain
TypeScript
29
star
18

dashboard

Loom Basechain Gateway, wallet and DPoS UI / dashboard
Vue
28
star
19

tiles-chain

JavaScript
19
star
20

vue-block-explorer

Vue component for inspecting Loom DAppChains
TypeScript
18
star
21

blockscout

Elixir
18
star
22

soliditycookbook.com

CSS
18
star
23

weave-blueprint

Example Go Smart Contract project for Loom Blockchain
Go
18
star
24

loom-examples

Loom Examples
JavaScript
17
star
25

zb_game_mode

ZombiebBattleGround Game Modes in Solidity. For Extending the gameplay with custom game modes
Solidity
16
star
26

cocos-sdk

Cocos2d clientside integration
JavaScript
15
star
27

token-gateway-example

JavaScript
15
star
28

ethcontract

Ethutils for creating Ethereum Contracts in Golang. Related set of helpers
Go
15
star
29

phaser-sdk-demo

JavaScript
15
star
30

spores

Loom Network's all-in-one package to connect your client to your DApp on EthDeploy
JavaScript
14
star
31

etherboy-core

Etherboy Game Smart Contract for Loom DAppChain
Go
13
star
32

loom-js-samples

Sample code demonstrating usage of https://github.com/loomnetwork/loom-js
JavaScript
10
star
33

mamamerkle

Sparse Merkle Trees implementation
Go
10
star
34

unity-evm-blackjack

Unity Blackjack Demo of Loom SDK with EVM contracts
C#
8
star
35

solidityx.org

Python
7
star
36

unity3d-identity

Unity3d package for managing identities on Loom DAppChains
C#
5
star
37

Node.js-prototype

Node.js prototype
JavaScript
5
star
38

solidity-transfer-gateway

Transfer Gateway Solidity contracts for Ethereum & TRON
Go
4
star
39

loom-provider-json-rpc-proxy

Small proxy that proxies HTTP JSON RPC calls to Loomchain/EVM using LoomProvider under the hood
TypeScript
4
star
40

loom-identity-js

JS library for managing identities on Loom DAppChains.
TypeScript
4
star
41

loom-playbooks

Automation resources for Developers
4
star
42

loom-token

This repo contains smart contracts for the new LOOM ERC20 token, token swap, and staking system.
TypeScript
4
star
43

gamechain

Go
3
star
44

zombie-battleground-api

Public Api Docs for getting Zombie Battleground data, such as cards and matches
3
star
45

unity-tiles-chain-evm

C#
3
star
46

loom-cli

DPoS / Transfer Gateway CLI
TypeScript
3
star
47

homebrew-client

homebrew for osx for loom client
Ruby
3
star
48

loom-unity-project-template

C#
3
star
49

TimeLock

JavaScript
2
star
50

plasma-indexer

Syncs Go Smart Contract events from a Loom DAppChain to a MySQL DB
Go
2
star
51

go-transfer-gateway

Transfer Gateway Go contracts & Oracles
Go
2
star
52

dc-translations

DelegateCall i18N
1
star
53

truffle-loom-builder

Experimental Truffle built tool for easy integration with Loom
JavaScript
1
star
54

unity-sdk-docs

CSS
1
star
55

e2e

Test utility for Loom SDK
Go
1
star
56

zkloom-examples

Examples of deploying and interacting with contracts on zkLoom
TypeScript
1
star