Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External contracts #76

Merged
merged 7 commits into from
Mar 14, 2018
Merged

External contracts #76

merged 7 commits into from
Mar 14, 2018

Conversation

onbjerg
Copy link
Contributor

@onbjerg onbjerg commented Mar 14, 2018

This PR allows you to interact with external contracts (i.e. contracts that are assumed to not be an Aragon app), such as tokens.

It allows you to perform calls and filter for events, but provides no automatic caching or convenience functions.

Usage-ish

const token = app.external(address, jsonInterface)

// A call
// Returns an Observable that emits a single value (the return value, a Web3 `Result` object)
token.symbol()

// Events
// Returns an Observable that emits Web3-structured events over time
token.events()

Note that you need to supply (at least a partial) JSON interface to interact with the contract.

Example

As a minimum viable example for getting the symbol of a token (conforming to Human Standard Token) and setting the app identifier to be that symbol, this would suffice:

const Aragon = require('@aragon/client')

const app = new Aragon()
const token = app.external('0xdeadbeef', [
  {
    'constant': true,
    'inputs': [],
    'name': 'symbol',
    'outputs': [
      {
        'name': 'symbol',
        'type': 'string'
      }
    ],
    'payable': false,
    'type': 'function'
  }
])

token.symbol().subscribe(
  ({ symbol }) => app.identify(symbol)
)

Improvements

Some future improvements could include

  • Transactions to external contracts, possibly with "universal transaction pathing"
  • Convenience functions, such as an integration with store (see brief explanation in Allow calls to arbitrary contracts #75)

Closes #41 and partially adresses #43

@onbjerg onbjerg added the enhancement New feature or request label Mar 14, 2018
@onbjerg onbjerg requested review from bpierre and sohkai March 14, 2018 10:12
@onbjerg
Copy link
Contributor Author

onbjerg commented Mar 14, 2018

Tested locally and working, need a go from either one of you @bpierre @sohkai

Copy link
Contributor

@sohkai sohkai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️❤️❤️ so excited to have this ❤️❤️❤️

* @return {Object}
*/
external (address, jsonInterface) {
let contract = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be const?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's something I missed while iterating a bit

[
address,
jsonInterface.filter(
(item) => item.type === 'event'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! I had no idea you could put in partial ABIs and everything would just work.

const callMethods = jsonInterface.filter(
(item) => item.type === 'function' && item.constant
)
for (let methodABI of callMethods) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do find it slightly odd this isn't a forEach or reduce

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be a forEach, probably also a reduce but would feel a bit weird with reduce imo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants