2

I'm using Chrome with Metamask extension. When I change the account, eth.coinbase value is always set to current one, so I can do the assign in JS code:

web3.eth.defaultAccount = web3.eth.coinbase;

But when I create a Web3 object in C# code and connect to the same node, coinbase value is always the same. Selected account address does exist in eth.accounts array, always with index greater than 0. Is there any way to get selected account address using Nethereum?

0

NEthereum doesn't work the same way. You will need to pass in the wallet address to the CallAsync (or simular), like below...

This is probably what you're doing now...

    Contracts.Function myFunctionName = contract.GetFunction("YourFunctionName");
    bool value = await myFunctionName.CallAsync<bool>(i);

This is what you should be doing...

    Contracts.Function myFunctionName = contract.GetFunction("YourFunctionName");
    bool value = await myFunctionName.CallAsync<bool>(from: address, gas: new HexBigInteger(0), value: new HexBigInteger(0), functionInput: i);

This assumes you have a function that checks the wallet address for something based on i as an index (returning true or false);

There is no gas cost for checking information from the Blockchain.

  • Now I understand: whenever I need to call some function or send transaction using NEthereum, I need to read coinbase from web3 object injected by Metamask, pass it to the server and then use this address in the invocation as you wrote. NEthereum is server-side framework and has absolutely any realtion to the browser and Metamask. – choosen_onee Jul 30 '18 at 22:13

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.