Adding multichain ethereum balances

Proposing to add access to all chain native balances in the token script for the current wallet.

Proposed structure:

web3.eth.walletBalance = <balance of chain of holder token>

then

web3.eth_xxx.walletBalance = <balance of chain xxx> ...

eg. for a token on main net:

web3.eth.walletBalance = 12.3;
web3.eth_1.walletBalance = 12.3;   //Main net
web3.eth_4.walletBalance = 3.4;     //Rinkeby
web3.eth_5.walletBalance = 7.5;     //Goerli
web3.eth_42.walletBalance = 27.4; //Kovan
web3.eth_99.walletBalance = 1.2;   //POA
web3.eth_100.walletBalance = 2.4; //xDai

Since we are think of adding an eth_N namespace to web3 (hence web3.eth_N) on top of tokens (web3.tokens), it looks like we should consider going with a new higher level namespace e.g.

tokenScript.eth_1.walletBalance

//We added this to support the door entry token a while back:
tokenScript.personal.sign

//We have these:
tokenScript.tokens.data.currentInstance
tokenScript.tokens.dataChanged

//We haven't designed this yet:
tokenScript.tokens.attributeTypes

There are a few problems with shoving it into web3.

  1. Branding and API organisation: it just isn't part of web3
  2. web3js is designed to be bring-your-own. dapps are supposed to provide their own web3js and only read web3.currentProvider (ethereum) to get the basic hooks, for signing messages etc in place.
    1. So code like these will be necessary to use TokenScript if we ever ship web3 support together with TokenScript:

      const provider = web3.currentProvider
      const tokenScript = web3.tokenScript //additional step to access tokenScript API
      window.web3 = BringMyOwnVersionOfWeb3()
      //Use tokenScript.tokens.data.currentInstace etc. Might as well let them have it (`tokenScript`)
      
    2. TokenScript isn't designed to be bring-your-own, so it's a mismatch in the web3 namespace

    3. If we want TokenScript to be bring-your-own, then we should design it that way :slight_smile:

And it's a good time now because we have settled on a name: TokenScript.

Yes, we should be thinking about this now.

Fundamentally I view Tokenscript as a tool for tokenisation. Tokenisation serves 2 purposes, as in the design paper:

𝑎) it creates a frictionless market. 𝑏) it creates an integrated web (web3‡)

So we are part of web3 in a bigger sense but not part of the web3js project. I see you meant that project specifically.

I'm pliant like water. One of the motivation† ½ years ago to name it under web3 is to be part of web3js project eventually. At that time that they do not see the need for supporting Tokens, I was hoping that they eventually realise they need to support tokens as we fill in the banks. But you are right that they have a different BYO model in how they see the web should be built which doesn't scale and is underdesigned. I'll just go with whichever camp that gives us more opportunity/space for growth. If being a standalone project achieves that then I'm pliant.

There were two words floating in 2017 that could have become the keyword for the blockchain-based Internet: Tokenisation and web3. I bet on Tokenisation and talked more about Tokenisation than web3 in the first months of designing TokenScript. 2018 saw the founding of web3 foundation and 2019 saw the founding of web3 Australia. Joining two dots in the plot it seems web3 is becoming louder. It remains to be seen which one will be the battle-cry of blockchain-led innovation. Tokenisation is closer to how it truly is, but we don't want to be the group chanting truth when others are chanting victory. Tim Berners-Lee didn't say he is the inventor of hypertext; he said he's the inventor of the web;)


† the other motivation was shortening the learning curve by copying the callback pattern.

‡ The way we see the future web, web3, is different than how Vitalik envisioned it at the time Ethereum was designed. Vitalik envisioned a decentralised web, where the component of the web is decentralised - web3 served by Ethereum, Whisper serves the communication protocol and Swarm serves the cloud. He meant a web pretty similar to the one we have nowadays with the technology components replaced by the decentralised versions. TokenScript design paper envisions a web whose usage and functions are decentralised, where the component being Token, which itself is not a communication layer, storage layer, but an integration/interoperability layer. This enables the web to do things we couldn't do before, for example, a car token can integrate insurance services without anyone owning a platform to allow them to be integrated, and book token which allows publishers and devices to compete with their own merit instead of rent-seeking from a central controller (Amazon in this case).

Forgot to mentioned 1 more point related to API organisation:

With the introduction of window.ethereum described in https://metamask.github.io/metamask-docs/API_Reference/Ethereum_Provider, it looks like window.web3 is considered legacy and deemed to be not available in the longer term. It comes from EIP1193