1

In Mix I can JS reference contracts with contracts['name']. How do I reference the user accounts?

1

You have web3.js available in Mix-IDE, so in the JS console you can use functions like

web3.eth.accounts

as usual.

The only other JS object that Mix exposes is contracts, as you can see in at official wiki page

Note that Mix exposes the following objects into the global window context:

  • web3 - Ethereum JavaScript API

  • contracts - A collection of contract objects. A key to the collection is the contract name. A value is an object with the following properties:

    • contract - Contract object instance (created as in web3.eth.contract)
    • address - Contract address from the last deployed state (see below)
    • interface - Contract ABI

Check the JavaScript API Reference for further information.

|improve this answer|||||
  • I was thinking more of how Mix must somewhere have a {name:address} object so I could reference something like user[name] instead of having to write up a separate registry. – o0ragman0o May 31 '16 at 11:33
  • I see, but just consider that name/address associations are configurations you can find in the .mix JSON file, they are for the IDE and they are not intended to be used as a reference in your ÐApp code. In any case, I usually use an account.js file where I store my name/address associations, and then I load that file every time. – Giuseppe Bertone Jun 1 '16 at 12:56
0

in your .mix json there is effectively the name of the users so a way to access them would be through that json, under the "states" key:

"states": [
                {
                        "accounts": [
                                {
                                        "address": "38f388fadf4a6a35c61c3f88194ec5ae162c8944",
                                        "balance": {
                                                "unit": 10,
                                                "value": "1"
                                        },
                                        "name": "user1",
                                        "secret": "cb73d9408c4720e230387d956eb0f829d8a4dd2c1055f96257167e14e7169074"
                                },
                                {
                                        "address": "3146577c741c31cc0b6479e5bef092bb8fe697d3",
                                        "balance": {
                                                "unit": 10,
                                                "value": "1"
                                        },
                                        "name": "bruce",
                                        "secret": "eebff1dce9aee5b5c056b4f61587f2861a8525e6fe3edf4584f38b41625a92cf"
                                },
                                {
                                        "address": "5833ebb3c3bedb9cce26db8b6b7290253d575b4e",
                                        "balance": {
                                                "unit": 10,
                                                "value": "1"
                                        },
                                        "name": "client2",
                                        "secret": "996e9abacf39a84154dcfaf9e5b3327c1c3fd5d15479a881c9f97fe7b6026adc"
                                },
                                {
                                        "address": "6d2f207b43241f609d2881bd3acbea70e2bcd698",
                                        "balance": {
                                                "unit": 10,
                                                "value": "1"
                                        },
                                        "name": "client1",
                                        "secret": "856124598b54a0c75f60e5d40c50c4dfba38034f4dca4d95e22fda6e1ce2802d"
                                }
                        ],
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.