Solidity
Remix - 將 bytesX 傳遞給函式
使用 Remix,我無法將一組字節傳遞
["0xee", "0xff", "0xgg", "0xhh", "0xii"]
給我的函式function foo(bytes5 input) { // Do something }
我已經嘗試過所有這些格式:
["0xee", "0xff", "0xgg", "0xhh", "0xii"] ["0xeeffgghhii"] ["0xee0xff0xgg0xhh0xii"] "0xeeffgghhii" "0xee0xff0xgg0xhh0xii" [["0xee"], ["0xff"], ["0xgg"], ["0xhh"], ["0xii"]] "0xee", "0xff", "0xgg", "0xhh", "0xii"
IDE 總是引發相同的錯誤或(合法地)說參數的數量與我的函式不匹配:
錯誤編碼參數:錯誤:無效的 bytes5 值(arg="",type=“object”,value=undefined)
如您所見,我已經嘗試了此處和此處建議的解決方案,我該怎麼做?
提前致謝!
字節集必須是十六進制的,
0xgg
,0xhh
並且0xii
不是十六進製字節。試試這個:
input : ["0xee", "0xff", "0xff", "0xff"] function foo(bytes5 input) public view returns (bytes5) { return input; } output: 0: bytes5: 0xeeffffff00
如果你想要更隨意的東西:
input : ["0x00","0xaa", "0xff"] function foo(bytes memory input) public view returns (bytes memory) { return input; } output: 0: bytes: 0x00aaff