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
{{ message }}
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.
I have a method in my contract that expects a bytes32 parameter. I've seen how this is done in Issue #57 and Issue #63 but haven't been able to make it work.
I have a sha string that I turn to bytes32 like this: let sha:Data = self.sha!.data(using: .utf8)![0..<32]
self.sha is a string like this: "4621c5cb24cca81ab0329089464ad54cd10e071bd21e86a237666228c6d2c04f"
I also have the bytes32 in a string representation from the server that looks like this: "b\'F!\\xc5\\xcb$\\xcc\\xa8\\x1a\\xb02\\x90\\x89FJ\\xd5L\\xd1\\x0e\\x07\\x1b\\xd2\\x1e\\x86\\xa27fb(\\xc6\\xd2\\xc0O\'"
However, the constructed Data (for bytes32) in swift comes out looking like this: [52, 54, 50, 49, 99, 53, 99, 98, 50, 52, 99, 99, 97, 56, 49, 97, 98, 48, 51, 50, 57, 48, 56, 57, 52, 54, 52, 97, 100, 53, 52, 99]
As you can see the bytes32 created in swift is fairly different from the one my server provides in string representation.
Finally, I add it as the parameters for my function call like so: let parameters = [sha] as [AnyObject]
Is there something I'm missing? The transactionIntermediate is getting created correctly so at least the parameter is good. I'm always getting 'revert' from my contract...
Any help is greatly appreciated.
Thanks,
The text was updated successfully, but these errors were encountered:
A library takes care of parameter serialization for you. If you want to pass a hex string as "bytes32" parameter then you just need to prepend it with "0x" prefix, so passing
let hexData = "0x" + self.sha!
let parameters = [hexData] as [AnyObject]
should be enough for you. Just in case if you want to pass utf8 encoding of arbitrary string as bytes32 - just leave is without prefix, conversion will be handled automatically too.
Hi,
I have a method in my contract that expects a bytes32 parameter. I've seen how this is done in Issue #57 and Issue #63 but haven't been able to make it work.
I have a sha string that I turn to bytes32 like this:
let sha:Data = self.sha!.data(using: .utf8)![0..<32]
self.sha is a string like this:
"4621c5cb24cca81ab0329089464ad54cd10e071bd21e86a237666228c6d2c04f"
I also have the bytes32 in a string representation from the server that looks like this:
"b\'F!\\xc5\\xcb$\\xcc\\xa8\\x1a\\xb02\\x90\\x89FJ\\xd5L\\xd1\\x0e\\x07\\x1b\\xd2\\x1e\\x86\\xa27fb(\\xc6\\xd2\\xc0O\'"
However, the constructed Data (for bytes32) in swift comes out looking like this:
[52, 54, 50, 49, 99, 53, 99, 98, 50, 52, 99, 99, 97, 56, 49, 97, 98, 48, 51, 50, 57, 48, 56, 57, 52, 54, 52, 97, 100, 53, 52, 99]
As you can see the bytes32 created in swift is fairly different from the one my server provides in string representation.
Finally, I add it as the parameters for my function call like so:
let parameters = [sha] as [AnyObject]
Is there something I'm missing? The transactionIntermediate is getting created correctly so at least the parameter is good. I'm always getting 'revert' from my contract...
Any help is greatly appreciated.
Thanks,
The text was updated successfully, but these errors were encountered: