npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

uport-contracts-js

v1.0.0

Published

Promise-based contract objects used by the uport system. For Node and the browser.

Downloads

4

Readme

uport-contracts-js

Promise-based contract objects used by the uport system. For Node and the browser.

If you would instead like to see the solidity contract code that is used by this library, or a 'bare bones' library that does not require Web3, see uport-contracts instead.

Install

NPM

$ npm install uport-contracts-js

EASY MODE: download the dist.js and in your HTML file

<html>
  <head> <script type="text/javascript" src="dist.js"></script> </head>
  <body> This page has global access to "Uport" (or "window.Uport") </body>
</html>

Initialization

First, set up a new web3 provider instance. Then require("uport-contracts-js") and create the Uport contract-objects with this provider

const Web3  = require('web3')
const Uport = require('uport-contracts-js')

var uport   = new Uport(new Web3.providers.HttpProvider('https://kovan.infura.io/'))

you've now have a uport object which has all other contract objects nested in it. These objects are truffle abstraction objects. For instance

uport.Proxy            // Truffle 'contract abstraction object'
uport.IdentityFactory  // Truffle 'contract abstraction object'
uport.RegistryV3       // Truffle 'contract abstraction object'

Background

A Truffle 'contract abstraction' object is basically a class based on the definition of the ethereum contract, but it is not tied to a specific instance or deployment of the contract. (See Truffle's Contract Abstraction API) for the full feature set.

The Truffle contract abstraction object can be used to deploy or follow an (already deployed) instance of the contract. This creates a Truffle 'contract instance' which can read and write to the contract using promise-based functions corresponding to their solidity functions. See Contract Instance API

Singleton Contracts

The uport variable from above exposes all our contract abstractions (using CapitalizedCamelCase)

Furthermore, after calling the deployed function, it will initialize contract instances of only the contracts which are "singleton contracts" (lowercaseCamelCase). For instance the identity factory and uPort Registry (registryV3) are contracts which uPort has deployed onto the ethereum blockchain. These contracts exist at a specific address and are intended to be shared by the community. I call these "singleton contracts". The proxy contract is not a singleton contract because each user is intended to have a separate deployment (instance) of it.

uport.deployed().then(function(){
  // Now the uport object is decorated with contract instances. Notice the lowercaseCamelCase
  console.log(uport.proxy)            // undefined
  console.log(uport.identityFactory)  // Truffle 'contract instance object'
  console.log(uport.registryV3)       // Truffle 'contract instance object'
})

The above function unfortunately is async, but if you specify a network_id you can execute it synchronously.

uport.deployed(3)         // ropsten network_id == 3
uport.registryV3.address  // '0x5ef80c8db9ca50c85ba4ddf9910ed3854da293d8'
                          // ^^ magically knows the registryV3 address!

Usage

Reading a Contract

Reading the uPort registry

uport.registryV3.get.call('uPortProfileIPFS1220', '0xb08e78b8E17dC2874818d7F49055aBf08Ee9977D', '0xb08e78b8E17dC2874818d7F49055aBf08Ee9977D').then(function(attestationsAddress){
  console.log(attestationsAddress) // -> 0xb0f288f8efa511962e11e37488db0d2bcc7a5f304b1d4f3977eb0ec65814a52c
})

You can see some real data (0xb0f2...) from the blockchain. More info on how to actually interpret this data coming soon.

Writing to/Deploying a Contract

If the provider is coming from Metamask, Mist, or Parity, you will be able to write and deploy contracts as well.

Writing to the uPort registry

uport.registryV3.set(
  'uPortProfileIPFS1220',
  web3.eth.coinbase,
  0x273EF783620B49D707885F6BBBCF1214CD0BC20D481FF31B00F67B612A5A53DD
).then(function(result){ /*Truffle result object */ })

Creating a Uport Account

uport.identityFactory.CreateProxyWithControllerAndRecovery(
  web3.eth.coinbase,                             //userkey (controls account)
  [web3.eth.accounts[1], web3.eth.accounts[2]],  //delegates (for account recovery)
  259200,                                        //timeLock (3 days for account recovery)
  5                                              //shortTimeLock (5 sec. effectively none)
).then(function(result){
  console.log(result)                     // -> Truffle result object
  console.log(result.logs[0].args.proxy)  // -> Your new account address!
})

API

Everything nested in the uport object follows the truffle-contract API. The contract instance objects have promise-based functions corresponding to all their solidity function names. Therefore its useful to view the solidity contract code which is held here.

More to follow