User Data
Including additional metadata in your Super Apps
Another powerful component of the Superfluid protocol is the ability to pass in additional user data along with your calls to super agreements. Think of it like metadata that can accompany your streams or IDAs 😎
Before we look at user data, let's take a quick dive into a new element: Context.
Context is used for several key items within the Superfluid protocol such as gas optimization, governance, security, and SuperApp callbacks. One parameter that's also available for use within the context field is userData.
This is from the host interface (ISuperfluid.sol) file inside of our interfaces folder in the Superfluid repo. On line 20, we see userData
.
Whenever you see ctx
being moved around within the protocol, this struct is what's under the hood (it's just compiled down to bytes each time it's passed between functions).
As you can see, userData
is one of the elements that makes up Context
. For the sake of this tutorial, we're going to focus exclusively on userData
for the time being.
Quick Review: How Are Super Agreements Called Again?
To call a function in a Super Agreement, you first need to use abi.encode
to compile a function call to the super agreement you're looking to trigger. Then, you need to pass the agreement type, the bytecode of the previously compiled function call, and userData
to callAgreement
(we'll get to userData next). The whole process looks like this:
Note:
userData
is always passed intocallAgreement
as typebytes
.
Behind the scenes, your userData
variable is appended onto Context
, which is then available to you as a developer in the SuperApp callbacks.
When you execute an operation in the CFA contract for example (and create, update, or delete a flow), you'll have access to the Context that's available after the initial call to the protocol was made. For example, if I pass in userData
when a create a flow into a Super App, I can decode the context
& this user data inside any of the super app callbacks, and re-use or manipulate this data as I please. For example, if I send a transaction where receiver
is a SuperApp, and pass along an encoded string 'hello sir' as userData
:
I can decode the context that's passed into the callback, which will give me the Context struct displayed above. Then, since userData is one of the fields on the struct, we can abi.decode userData get back my value of 'hello sir' on the other side:
In Conclusion
UserData can be any arbitrary piece of data. Think of it as metadata that's associated with anything you do in a Super Agreement.
This metadata could be used for a wide variety of use cases:
You could pass in data to accompany a salary or payment stream - perhaps employee info or product info
You can send a message along with your distribution in an instant distribution agreement
You could even pass in the byte code for another entire smart contract.
We invite you to be creative with this!
Next up: a tutorial on how to leverage UserData within your applications.
Last updated
Was this helpful?