I am developing a game smart contract and it has 20 numerical settings. like time, fee, difficulty etc

I want to

  • access these values using identifier throughout contract

  • get all these values from frontend in group.

    hopefully web3js gives me a json object settings.time

  • set values individually

  • use minimum gas in setter

I'd like to know what is the best practice in variable declaration, getter, setter methods, access from frontend.

My thought follows

  1. declare individual member variables
pragma solidity >=0.5.0;

contract SomeGame {
uint setting_time;
uint setting_fee;
  1. use string to uint mapping
mapping(string => uint) settings;
// settings['time']
  1. use both enum and array
enum GameSettings {time, fee};
uint[20] settings;
// settings[GameSettings.time]

I use truffle suite, ganache v2.0.2-beta.0, solidity 0.5.0, injected web3js of Metamask

Truffle v5.0.12 (core: 5.0.12)

Node v10.15.3

Thanks in advance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.