Coder Social home page Coder Social logo

universal-dapp's Introduction

Universal ÐApp

Demo: http://d11e9.github.com/universal-dapp

A Universal Interface for contracts on the Ethereum blockchain. Best used in conjunction with a contract compiler like browser-solidity or in cases where you already have an ABI and/or bytecode for an existing contract

##How to use

Include the source and its dependencies in your html.

<script src="lib/ethereumjs-vm.js"></script>
<script src="lib/web3.min.js"></script>
<script src="src/universal-dapp.js"></script>

For the Universal-Universal Dapp which has input for ABI and Bytecode you can do the following:

<script>
    $(function(){
        var dApp = new UniversalDApp([]);
        $('body').append( dApp.render() )
    });
</script>

If you'd like to use a universal DApp for a specific set of contracts, either already in the blockchain or in the form of compiled bytecode and ABI, you can do the following:

<script>
    $(function(){
        var dApp = new UniversalDApp([{
            name: "{{name}}",
            interface: "{{json abi interface}}",
            bytecode: "{{compiled bytecode}}"
        }]);
        $('body').append( dApp.render() )
    });
</script>

Or if you just need an interface for an existing contract you can provide its address directly. In the example below we omit the bytecode property wich prevents the uDApp from creating new contracts.

<script>
    $(function(){
        var dApp = new UniversalDApp([{
            name: "{{name}}",
            interface: "{{json abi interface}}",
            address: {{address hex}}
        }]);
        $('body').append( dApp.render() )
    });
</script>

Connecting to a running Node

By default Universal DApp looks to see if there is already an existsing web3.currentProvider and will use that if available. If there is no current provider and vm is false then it will create a new HttpProvider (RPC) and connect to the http://host:port provided in options, defaulting to http://localhost:8545.

<script>

    // perhaps we already have an IPC provider like so
    web2.setProvider( new web3.providers.IpcProvider( './my/ipc/path/geth.ipc') )

    // relying on an existent currentProvider
    $(function(){
        var dApp = new UniversalDApp([{
            name: "{{name}}",
            interface: "{{json abi interface}}",
            address: {{address hex}},
            host: {{ie: localhost}},
            port: {{ie: 8545}}
        }]);
        $('body').append( dApp.render() )
    });
</script>

or

<script>
    // specifing a rpc host and port.
    $(function(){
        var dApp = new UniversalDApp([{
            name: "{{name}}",
            interface: "{{json abi interface}}",
            address: {{address hex}},
            host: {{ie: localhost}},
            port: {{ie: 8545}}
        }]);
        $('body').append( dApp.render() )
    });
</script>

###Example

Check out the gh-pages branch index.html for a full working example.

##Acknowledgements

In its initial form this project was a direct copy/paste of parts of chriseth's browser based Solidty compiler.

##Caveats

Currently works exclusively inside of a JavaScript Ethereum VM (ethereumjs-vm) by wanderer.

There is alpha support for web3.js connections to a local Ethereum Node, to deploy and interact with contracts live on the Ethereum Blockchain.

universal-dapp's People

Contributors

d11e9 avatar axic avatar nmushegian avatar

Watchers

 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.