【问题标题】:how to update the value of variable of struct with mapping in solidity如何使用可靠映射更新结构变量的值
【发布时间】:2022-01-04 06:26:06
【问题描述】:

我想在与data1映射后使用setter函数更新“金额”的值

pragma solidity ^0.8.0;

合约 acc_data{

struct person{

    string name;
    uint age;
    address add;
    uint amount;
}
 
person public p1;
mapping(address=>person) public data1;



function map()public{
      data1[p1.add]=p1;

}


function structsetter()public {
    p1.name="rohit";
    p1.age=22;
    p1.add=0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;
    p1.amount=0;
 }    

 function setter() public {

     p1.amount=7;
     } 

【问题讨论】:

    标签: mapping blockchain ethereum solidity smartcontracts


    【解决方案1】:

    你可以这样做:

     function setter() public {
       data1[p1.add].amount=7;
     } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-13
      • 2018-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-19
      • 1970-01-01
      相关资源
      最近更新 更多