1

This is my smart contract:

contract Bank {
  mapping(bytes32 => State) internal states;
  bytes32[] internal possibleStates;

  struct State {
    // a boolean to check if the state is actually created
    bool hasBeenCreated;
    // a mapping of functions that can be executed when in this state
    mapping(bytes4 => bool) allowedFunctions;
    // a list of all the roles that have been configured for this state
    bytes32[] allowedRoles;
    // a list of all the preconditions that have been configured for this state
    function(bytes32, bytes32) internal view[] preConditions;
    // a list of callbacks to execute before the state transition completes
    function(bytes32, bytes32) internal[] callbacks;
    // a list of states that can be transitioned to
    bytes32[] nextStates;
    // function that executes logic and then does a StateTransition
    bytes4 preFunction;
  }

 
  function createState(bytes32 stateName) public {
    states[stateName].hasBeenCreated = true;
  }
}

But when I try to use the function createStake in Remix with the following values: "test" or "test, test" or ["test"] or ["test", "test"]

Nothing works I always have the following error message: Error encoding arguments: Error: invalid arrayify value (argument="value", value="test, test", code=INVALID_ARGUMENT, version=bytes/5.4.0)

Can someone explain me why? Thanks!

2 Answers 2

4

The text has to be in hexadecimal and occupy 64 hex characters. To convert "test" you can type in the remix console

> web3.utils.padLeft(web3.utils.asciiToHex("test"), 64)

0x00000000000000000000000000000000000000000000000000000000686f6c61

Then you can type 0x00000000000000000000000000000000000000000000000000000000686f6c61 as parameter when calling function createState.

1

Ismael's answer is the best

I've made an online tool to do the same

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.