CRYPTO NEWS

Passing Struct as an argument in call

I am trying to pass a struct as an argument while calling the function of another contract:

pragma solidity ^0.4.24; pragma experimental ABIEncoderV2;  library Test {    struct TStruct {     int x;     int y;   }    }  contract A {    function SetStruct (Test.TStruct sin) public returns (int) {     data = 10;     Test.TStruct memory s;     s.x = sin.x;     s.y = sin.y;     return s.x;   } }  contract B {   address public BAddr;    function TalkToA () public {     BAddr = new A();     Test.TStruct memory sin = Test.TStruct(10, 5);     BAddr.call(bytes4(keccak256("SetStruct((int256,int256))")), sin);   } } 

Invoking SetStruct directly from Remix causes it to correctly execute. However, when I deploy contract B, the call to SetStruct does not go through. What is the correct way of passing a struct as a parameter in a call invocation?

How to verify MetaMask account holder is the real owner of the address?

I’m making a dapp that will make calls to a Node.js server. I expect the user to have MetaMask installed and I want to verify that he is the real owner of the current address on MetaMask (i.e. accounts[0]). This is the user flow I am trying to implement: User loads up my dapp frontend::Listen

I’m making a dapp that will make calls to a Node.js server. I expect the user to have MetaMask installed and I want to verify that he is the real owner of the current address on MetaMask (i.e. accounts[0]).

This is the user flow I am trying to implement:

  1. User loads up my dapp frontend in his browser.
  2. The browser gets accounts[0] from Web3/MetaMask.
  3. The frontend requests some data specific to accounts[0] from my Node.js API.
  4. On the Node.js server, I need to verify that the request is coming from someone who actually owns the private keys to the address accounts[0]. If this is valid, then I respond with the specific data.

I spent a long time looking at different signing functions with Web3, and I ended up very confused. There is:

  • web3.eth.sign – there’s no recover counterpart to this and MetaMask doesn’t pop up asking the user to sign something.
  • web3.eth.personal.sign – this one requires a password, I don’t want to ask the user to enter his password, shouldn’t MetaMask do this?
  • web3.eth.accounts.sign – this seems more like a hashing function than what I need.

I have a feeling that none of the three above functions are what I need. Can someone provide some guidance on how to approach this?

Passing Struct as an argument in call

Shopping cart
There are no products in the cart!
Continue shopping
0