7

I have something like this in solidity:

struct Bid {
   ...
}
event BidEvent(Bid bid)

but when I try to read this event in Javascript, there's no data inside that I can access — no bid variable, none of the things inside it, nothing at all really.

Does this mean structs can't be put inside events?

2 Answers 2

2

I tried using a struct inside an event and receive compilation errors. You need to pass specific value type variables (address, uint, etc) into the event and then you could use these to access the full Bid struct object when the event gets triggered if you need the entire object.

2

Here is the Zero-Error Solidity Smart Contract code to use struct with event & function parameter :

//SPDX-License-Identifier:MIT
pragma solidity >=0.8.0 <0.9.0;
contract aakash4dev{
    struct datas{
        uint a;
        string b;
    }
    event DataBro(datas dd);
    function putdata(datas memory d) public {
       emit DataBro(d);     
    }
}

put data like this: [4444,"aakash 4 dev"] on RemixIDE aakash4dev

if you use Web3.js instade of RemixIDE use call() function like this: myContract.methods.putdata([1234,"some string"]).call()

web3JS doc: https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html#methods-mymethod-call

if Python: Web3Py docs: https://web3py.readthedocs.io/en/stable/contracts.html#methods

happy codings !! 😃👨‍💻

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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