connect
connect copied to clipboard
Invalid Buffer provided in SmartBufferOptions
I'm running the following method:
const options = {
contractAddress: "SPPEYAEM28YFZ2SJWTZRFK1B6MAZV09PB0TQPDR",
contractName: "swag-1000",
functionName: "claim-swag",
sponsored: true, // this is a sponsored transactions
functionArgs: [],
appDetails: {
name: "Bitcoin NFT on Stacks",
icon: window.location.origin + "/hiro-icon-black.png",
},
network, // set to mainnet
onFinish: (data) => {
console.log("Stacks Transaction:", data.stacksTransaction);
console.log("Raw transaction:", data.txRaw);
},
};
await openContractCall(options);
And I receive an error after confirming the transaction inside the web wallet:
[Connect] Error during transaction request Error: Invalid Buffer provided in SmartBufferOptions.
- @stacks/connect: 6.0.0
- Stacks Web Wallet: 2.11.1
@agraebe want the UserX team to look into this or prefer to handle on the Splat side?
We would have only Tintash to look at this in the short term and there's no context on connect and the web wallet. I'd prefer the UserX team to take a look
This kind of error usually happens when a wrong type of value is passed to a clarity function
The method isn't taking any arguments (also left the args array empty in the code) 🤔
@agraebe Sounds good re: UserX taking it. Is this a blocker for docs / sample app work? Any particular urgency?
we decoupled the sample nft app from the docs updates, so the urgency is a bit lower. but, this issue should be triaged to really understand the urgency - it might prevent sponsored txs for many users (unless something is very particular about my usage).
If I'd have to call it without more info, I'd say medium prio
@aulneau I presume this one will take some investigation to diagnose?
@agraebe mind providing the Clarity code you're trying to use here so we can cross-check?
sure, here it is: https://explorer.stacks.co/txid/0x7246cfb663ddd90041781919961a131938d34345879d708ed7d855039c70b84d?chain=mainnet
@agraebe Hey dude, I found it is something wrong with one of the @stacks/connect package's dependencies. smart-buffer. If you take a look at stacks.js source code in file bufferReader.ts. line 54
constructor(options?: SmartBufferOptions | Buffer) {
if (Buffer.isBuffer(options)) {
this.smartBuffer = new SmartBuffer({ buff: options });
} else {
this.smartBuffer = new SmartBuffer(options);
}
}
This new SmartBuffer({ buff: options }); is the source of error. Inside smart-buffer package: smartbuffer.ts, line 54
if (options.buff instanceof Buffer) {
this._buff = options.buff;
this.length = options.buff.length;
} else {
throw new Error(ERRORS.INVALID_SMARTBUFFER_BUFFER);
}
This means if the buff is not an instance of Buffer, the error occurred. I modified this to :
if (Buffer.isBuffer(options.buff)) {
this._buff = options.buff;
this.length = options.buff.length;
} else {
throw new Error(ERRORS.INVALID_SMARTBUFFER_BUFFER);
}
Same to the bufferReader.ts, same way to judge. Then, build smart-buffer, replace it locally in my front-end app. It works as expected. Here is what I got:
{
"txId": "d04fc5bed4f59d034b1bff1e3232424fc83a7675a827249f7a97ae08fd6b2a0c",
"txRaw": "0x80800000000400cdac2df59d961d5f411e4d6a59efe0c5a69d43ae000000000000001a00000000000000b30001a53d40f36f07bd364d9389d85a6b89c921f367a03c393ab799eb941ead8088033c6b714f1cd432b4286f9e86edb2b1f078f0390b342a7b7e6c21a1dcbdbb951f030200000000021acdac2df59d961d5f411e4d6a59efe0c5a69d43ae086b762d73746f7265097365742d76616c75650000000202000000046e616d6502000000055469676572",
"stacksTransaction": { ... }
}
Hope this will help.
Have submitted a PR that fixes the issue @hecool108 found. Awaiting release.
The library hasn't been updated in 2 years now, so I think it's unlikely this'll be fixed. We needed this for the MiamiCoin UI so we forked it and made the changes ourselves. It's fixed in @syvita/smart-buffer
4.2.0
Feel free to replace it!
Thanks, @SyAsteria, so that means I need to wait for @stacks/connect to use @syvita/smart-buffer instead of smart-buffer, and release a new version, right?
you can use yarn resolutions to force your application to resolve to a specific version, so you could do something like this in your package.json
"resolutions": {
"smart-buffer": "npm:@syvita/[email protected]"
}
@aulneau Thanks!
if i get time, i'll put in a PR that changes this. currently we're using forks of both connect & stacks.js to (@syvita/connect & @syvita/transactions respectively) which have fixes. repos are open source so all y'all have to do is copy the commits from the forks to the 1st party ones :)
I don’t think this particular issue was caused by the smart-buffer because I was able to successfully execute the contract the same way using the code provided. The same contract deployed here (with the same trait implementation but on testnet) https://explorer.stacks.co/txid/0x8383bc382c32873e025bd50a25eb0bed9d212c80fad9334c1abf34a5f4981ad2?chain=testnet We can still add the buffer check fix of @SyAsteria if he opens a PR. If he doesn’t have time I will add it.
I went ahead and merged your change into smart-buffer and published as 4.2.0.
@SyAsteria might you have time to prepare the PR this week, or should @beguene take it?
I'll add it to my todo. Should be done by EOW.
connect
switched away from the node types a while back, should be resolved now