You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attempting to consume a String in a contract function, ExW3 seems to handle encoding improperly, causing variables to mix and or set improperly in the contracts state.
Smart Contract Example:
pragma solidity >=0.4.22 <0.9.0;
contract Tester {
address public currentAddr;
uint256 public currentInt;
string public sym;
function setOnlyStringBefore(string memory _sym, address new_addr, uint256 new_int) public {
currentAddr = new_addr;
currentInt = new_int;
sym = _sym;
}
function setOnlyStringAfter(address new_addr, uint256 new_int, string memory _sym) public {
currentAddr = new_addr;
currentInt = new_int;
sym = _sym;
}
function setOnlyAddrAndInt(address new_addr, uint256 new_int) public {
currentAddr = new_addr;
currentInt = new_int;
}
}
Scenario 1
(Function setOnlyStringBefore) - string is set before address and uint256 in smart contract function parameters
however you can see in the above .currentAddr() and .currentInt() that the addr is set as a hex encoded value of 10 and the int is set as a BigNumber conversion of the address.
Note: This function is successful when called directly from truffle
When attempting to consume a String in a contract function, ExW3 seems to handle encoding improperly, causing variables to mix and or set improperly in the contracts state.
Smart Contract Example:
Scenario 1
(Function setOnlyStringBefore) -
string
is set beforeaddress
anduint256
in smart contract function parametersUsing ExW3 ->
ExW3.Contract.send(:Tester, :setOnlyStringBefore, ["name", "0x0255bff90b8787f06cf13ab325997cbf3b139c1d", 10], %{from: @contracts_owner, gas: 6000000})
{:ok, "0x1c6ac0864e8e6418cfc743200ee74ad06bb2442bd5842fd73c2d12bb835db0dc"}
In Truffle ->
truffle(k8s)> let test = await Tester.deployed()
truffle(k8s)> test.sym()
truffle(k8s)> test.currentAddr()
'0x0000000000000000000000000000000000000060'
truffle(k8s)> test.currentInt()
<BN: 255bff90b8787f06cf13ab325997cbf3b139c1d>
Note: The transaction is successful but the
sym
is set as a byte array and theaddress
anduint256
values are swapped. They are passed in as[name, new_addr, new_int]
and the function consumes them as
(string memory _sym, address new_addr, uint256 new_int)
however you can see in the above
.currentAddr()
and.currentInt()
that the addr is set as a hex encoded value of 10 and the int is set as a BigNumber conversion of the address.Note: This function is successful when called directly from truffle
truffle(k8s)> test.sym()
'Name'
truffle(k8s)> test.currentAddr()
'0xfe5e669eD4C62A7D4621A604BcC1029171814046'
truffle(k8s)> test.currentInt()
<BN: a>
Scenerio 2
### (Function setOnlyStringAfter) -
string
is set afteraddress
anduint256
in smart contract function parametersExW3.Contract.send(:Tester, :setOnlyStringAfter, [10, "0x0255bff90b8787f06cf13ab325997cbf3b139c1d", "name"], %{from: @contracts_owner, gas: 6000000})
{:ok, "0xcb1e0f29d7a0fa5bc7822c2d9302b12cc5a22b02a52323d3ac3bad1a01b64634"}
In Truffle ->
truffle(k8s)> let test = await Tester.deployed()
truffle(k8s)> test.sym()
''
//// <--- Value never got setNote: The transaction status is 'false', meaning that the transaction has failed for some reason.
Note: The function call is successful when called from Truffle
The text was updated successfully, but these errors were encountered: