CRYPTO NEWS

Encode a struct with solidity

Is it possible to encode a struct in Solidity without serializing each variable separately?

Something like:

struct MyStruct {    uint x;    uint y; }  MyStruct storage myStruct = MyStruct({    x: 11,    y: 12 });  bytes memory data = abi.encode(myStruct, (MyStruct)); 

Or in assembly?

Can I store ether and ERC-20 tokens in one contract?

I am trying to create a contract to store ether and two ERC-20 tokens. People will transfer ether and the other two ERC-20 tokens to this contract and when the time comes, the owner of this contract will transfer these ether and ERC-20 tokens back to them. I don’t know how to make this contract.::Listen

I am trying to create a contract to store ether and two ERC-20 tokens. People will transfer ether and the other two ERC-20 tokens to this contract and when the time comes, the owner of this contract will transfer these ether and ERC-20 tokens back to them. I don’t know how to make this contract.

Currently, I can make an ERC-20 token contract and it can only store the ether and this ERC-20 token itself like below.

Suppose this contract can store 3 kinds of tokens. When people transfer these tokens to the contract, how the contract itself knows which token was sent?

contract WalkDogToken is ERC20, ERC20Burnable, Ownable {     constructor() ERC20("WalkDogToken", "WDT") {}      function mint(address to, uint256 amount) public onlyOwner {         _mint(to, amount);     }      function decimals() public view virtual override returns (uint8) {         return 8;     }      receive() external payable {} } 

Encode a struct with solidity

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