-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Observation in passing buffer values to contractCall #786
Comments
I tried to document / improve the use When a contract function that takes a buffer as an arguments, it's called hex string starting with I think it could lead to confusion that So I introduced a new function
The |
Thank you! I think that makes things clearer, and in the end knowing the hex string is the expected result was the part I didn't understand. When I saw the Clarity type was With the changes above, both passing the hex string directly and using This is valid and works, but it is unclear why the values are hex strings and that the contract is expecting a buff: Tx.contractCall(
"stacking-action",
"stack-stx",
[
types.uint(amount),
types.principal(pool.address),
"0x01",
"0x13effebe0ea4bb45e35694f5a15bb5b96e851afb",
types.none(),
],
admin.address
) This would be the new version, much cleaner: Tx.contractCall(
"stacking-action",
"stack-stx",
[
types.uint(amount),
types.principal(pool.address),
types.stringToBuff("0x01"),
types.stringToBuff("0x13effebe0ea4bb45e35694f5a15bb5b96e851afb"),
types.none(),
],
admin.address
) The pattern used here may be helpful with this issue in micro-stacks too, the more consistent we can make everything the better! |
@whoabuddy
If you look at the So [
types.uint(10),
types.principal("ST98...FG"),
types.stringToBuff("0x01"),
types.stringToBuff("0x13effebe0ea4bb45e35694f5a15bb5b96e851afb"),
types.none(),
] Could be [
"u10",
"'ST98...FG", // notice the extra `'`
"0x01",
"0x13effebe0ea4bb45e35694f5a15bb5b96e851afb",
"none",
] It would have the exact same effect. But I agree that working with buff can be confusing so the least we can do is add some docs and easy to use helpers 👍 |
This started with testing a simple Clarity contract that can stack its own STX through pool delegation.
The related test simulates the deposit and stacking functions, but there was a discrepancy in understanding how to pass the correct buffer value.
In the end this is resolved, but documenting it here because the result was unexpected.
The Short Story
I had no idea I needed to pass the hex string for tx options related to Clarity buffers, and it took quite a while to figure out.
The Long Story
There were two function parameters that needed to be (buff 1) and (buff 20) to represent the pox address in delegate-stx.
The hex values were each stored in a constant:
My first instinct was to use
types.buff()
on the function arguments since it's normally required to match the Clarity type.This resulted to mismatched buffer sizes and appears to be the cause for the error in reported in Discord. @hugocaillard that is now fixed (although the print errors remain).
It's also inconsistent with how makeContractCall() operates here (not sure for stacks.js version), which expects a Clarity buffer as part of the tx options.
Not sure what the fix would be but wanted to at least document the struggle to figure it out!
Relevant TX:
https://explorer.stacks.co/txid/0xdbbecf8113b530bd12ca67c425cc1c27a0bf7916ded65e106cf0ecc8fb28c75a?chain=mainnet
The text was updated successfully, but these errors were encountered: