Encode x Gnosis Chain Hackathon: Introduction to Building on Request Network

Encode x Gnosis Chain Hackathon 2023 · 5 May 2023 · 43:42

David Hunt-Mateo, senior blockchain engineer at the Request Network Foundation, introduces Request Network, a protocol for storing payment details such as payer, payee, amount and due date so businesses can handle invoicing, accounting and tax reporting onchain. The workshop explains how request data lives on IPFS with its hash recorded on Gnosis Chain, how payment proxy contracts work across more than 20 EVM chains, and how to install the request client, create a request and read payments through subgraphs, followed by audience questions.

Speakers

Topics

From Encode x Gnosis Chain Hackathon 2023, hosted by Encode.

Transcript

hi everyone can you hear me if you can please post in the chat um for some reason my camera refuses to turn on but if you can hear me that is good um okay so hi guys welcome back um maharab says he never left um that's awesome um good uh so I just wanted to say a couple of things if you're tuning in right now we're about to start hi Alex um so we've got David from our quest uh

speaking there he is hi David um I've just posted David's Twitter in the chat um and we'll probably also get requests Twitter in there as well hello how are you guys doing well today how are you doing awesome um not too bad I'm not sure why my camera's not working um but uh I think you guys have seen my face enough in the first part of this uh Workshop uh session um awesome so I guess David whenever you're ready you can go ahead and take over the screen sure sounds good I'll just jump right

into it um share let's try this can you see my screen yes we can see your screen all right cool um okay so uh hello everyone I Am David Hunt Mateo uh also known online as as mantis cologne uh and I'm a senior blockchain engineer at the request Network Foundation and briefly I'll I'll introduce my my co-contributors here Alex Alex is our our community manager and um Francisco is the uh protocol lead um and here we're here today to talk a little bit about what request network is

uh describe a little bit about how to use it and hopefully get you guys hacking on on our protocol as as soon as we can um basically what is what is request Network it's it is a protocol for creating a transparent and immutable ecosystem of financial products on top of it um the basic issue with blockchains today is that uh when you create a transaction between two parties you don't have the information about why that payment is occurring or any other sort of metadata that you would want like the the names of the participants or or the addresses or or tax numbers or

whatever other information you would want to add to it um and all of this information is the side of stuff that is necessary for business accounting business compliance and other Financial Services like proving income and being able to borrow um and this is a challenge this is a challenge for businesses these days so what request Network protocol is trying to do is we are creating a a channel for that information to be stored immutably and being able to make it uh uh both composable as well as private to the parties who are are are are needing it um and by by storing this information we

are unlocking uh new new applications for blockchain including the ability to have in income backed loans Insurance fundraising and even further out we we imagine a world where there could be automatic auditing um triple entry accounting and automatic tax reporting um I could briefly talk about what those things are automatic auditing obviously is like the ability to show that your business has the the required assets or the the assets that it says it does um triple entry accounting is the idea that instead of having a an accountant who needs to aggregate all of your your

uh um financial information and then like do a bunch of calculations at the end of each month and uh reconciliation activities all of that can be automated and they are instead reviewing the information rather than inputting it or or calculating it themselves and then finally automatic tax reporting if you've been working in blockchain for any amount of time you probably have already used a tool that that generates tax reports and I think that um our protocol can only make that sort of information better it helps you understand what is income versus what is uh something else maybe like uh capital gains of some sort um so yeah request Network where where uh the basic

idea of how it works is that we are we've created a a standard for storing payment information including like the payee the payer the the due date the currency and the amount and it stores all that sort of stuff in ipfs and then we take a uh the content identifier the hash of that information and we store that on chain uh typically on gnosis chain uh so once the information is stored we also have a series of smart contracts that we use for um um for executing payments on those requests um and the the payment proxy contracts

are deployed to over 20 different evm compatible chains as well as near and once a payment occurs because it goes through our smart contracts events get emitted and then we have a series of sub graphs uh from the graph uh that index the events and then are able to return information about those requests when you query for them and uh some of the things that this enables is you can create invoicing apps you can create payment apps you can create accounting apps um you can create um tax reporting apps um a whole bunch of different stuff

across the the financial Spectrum which uh brings me back to my original Point by by creating this shared data layer we are creating a transparent and immutable ecosystem of financial products on top of it um so I will Dive Right into some of our our quick stock our documentation here um we are working on a quick start but in the meantime we've got a couple of guides uh that we can show you uh the first one is how to create a request uh basically we have a actually you know what before I do that I'm going to rearrange my topics just real quick because I realize I need to talk about

installation first okay so uh the way that you interact with the request network is using our request client Library um the request client Library it's it's written in typescript but you should be able to access it as both a UMD uh module or a common JS module whatever your project is set up to do um I've got some instructions here on screen that allows you to install the request client as well as a accompanying package called web3 Signature which most dapps are probably going to use um you'll notice some weird uh versioning information at the end here

uh the honest truth is that we we have an automated release process for our packages and we haven't done an official like numbered release in a while so uh the best way to get the latest code is to actually just use this special uh string with the next in it and the one eight nine two that will give you the latest version of the of the code um basically it's you import it the same way that you would any other um any other client Library you can see this line right here Imports the request Network and the line after it Imports the web3 signature provider

and once you have it imported you can instantiate those objects using the the following code snippet um the first thing you'll do is create the signature provider and hand it the um the injected wallet so that's going to be a window.etherium and then you're going to create a request client and you're going to pass it the um the URL of the of the request Gateway that you're using along with the signature provider and just some notes about this the the URL this is a a request node Gateway that's maintained by the request Network Foundation this is

this is maintained by us uh so that Builders can quickly get up and running with the network um the the idea is that once a project has reached a certain maturity point they would eventually want to run their own request node on the network but um I'll leave that as a a future topic if if any of you decide to continue building with us after after the hackathon um some other alternatives to to describe here is that the idea uh of of the the gnosis chain uh Gateway is that we also have a Gourley Gateway if you want to create test net requests

um these are these are requests that are used uh created using testnet funds and then typically would be for paying on test Nets um that's an option that you could use um and if you want to manage your own private keys outside of a wallet we also have a EPK ethereum private key signature package which would be the analog of the uh the web 3 signature package that's also an option another thing that I want to note at this point is that um you can create requests on gnosis chain or on Gorly but that doesn't mean that the payment must occur on gnosis chain um we have our payment proxy contracts deployed to over 20 different evm

compatible chains as well as near we also support near as of very recently um so so payments can still occur on any of those different chains in a variety of you know native coins erc20 coins or um with a variety of other Payment Processing features that I'll get into later foreign so with that I'm going to jump back to the quick start that I was originally talking about we're going to want to figure out how to create a request right so in order to create the request uh there's a guide here that I'm showing on screen that'll show you how to create in particular a

an erc20 request and um admittedly this guide this guide is um is using a few different things from what the installation talks about uh this one's using the EPK signature provider so it's going to have the ethereum private Keys managed outside of a wallet um it's also got the uh this this particular guide is using uh mock storage instead of the the Gorly or sorry instead of the gnosis chain Gateway but um either one would work if if you're if you're just trying to understand how the library Works using mock storage can be nice because it stores all of the

requests in local memory on your machine without actually having to go out and ping ipfs to create so it's a lot faster to to iterate but keep in mind that all the requests that you create in that way will be deleted as soon as the script finishes foreign okay so I mean basically you import it very similarly to what I showed on the on the installation guide um you can create a couple of identity objects that describes the the type of of identity the ethereum address and then provides the actual address and then you have a signature provider that has the private key that's going to be signing the the requests and you create the net request Network instance

giving it both the signature provider as well as telling it to use the mock storage um so uh with that I'll talk a little bit about what the information a request contains you can see that there's there's just a few Fields here the the currency the expected amount the payee identity and the payer identity um this is this is very Bare Bones obviously uh the the core protocol only requires these these four fields but we have the ability to add additional content into any given request and that content can be

um um it could be arbitrary or or defined by the application that you're creating uh we also have um data formats pre-built data formats available in our repository for creating things like invoices and an invoice is going to contain a whole bunch of other information like line items amounts discounts uh tax percentages it's going to have information about the payer like their their address or their business number or their vat number tax number um there's a whole bunch of different fields for all that sort of stuff so um I could I could drop some links later of of how to find those data formats the uh the primary way that you're going

to create requests is probably going to be using our our proxy contracts for payment um technically we support a different address based payment mechanism but I won't get into it today because nobody uses it um basically the the way that you create request is you just have to prepare the creation parameters you specify the the payment Network that you're using basically that's going to be the chain the currency and any of the payment features that you're going to be using whether it's a native token an erc20 token or if you're going to be using conversion escrow or or doing any sort of swaps as part of the payment you're going to provide the request

information that's that's the contents of the request and then you're going to provide the the signer the payee that that is creating the request and then you just call create request on on your request Network instance it's uh basically as simple as that once the once it returns you'll have a request object that contains the um a description of of all of the the the things that you passed into it along with any sort of uh event information that have occurred on the request uh briefly I'll talk about the some of the events that could occur is like uh if if a payment has occurred that

that'll be that'll be returned um if if you it technically has the ability to increase or decrease the amount those are other actions that can occur on the on the protocol or if you want to um if the payer wants to approve the the request and show that they are are accepting it as valid and not spam they have the ability to do that uh oh finally the the pay the payee the the creator of the request also has the ability to cancel it if they want um I will I will get into balance checking in a future section so I'm going to jump back to the Quick Start

um the next thing that I want to talk about is retrieving our Quest um excuse me when you're retrieving a request you're going to be be making calls on that same request Network object that that request client object that we created earlier um and some of the functions that you could use are the from request ID function uh this one is is is going to retrieve a specific request by ID and the request ID is something that would be passed back to you when you create the request um or if you know all of the all of the parameters of a request including the request info the signer the payment

Network any topics or content data that you passed into it you have the ability to compute what a request ID would have been so then you can use that ID to look up any uh uh query query the network for the current status of that request and you can see in this is usage usage example just below once you have queried the request by ID you can oh shoot I think it's in a later section I updated one of these uh or maybe I didn't one second maybe I haven't refreshed I was working on the docs just before this

okay here it is here it is that's the line I was looking for um so once you have the request you can call the get data function on it and that will return the actual data stored within the request object in a in a format that's much easier to parse so the request data that you're going to get is going to be stuff like the the currency any metadata about the request the current balance so that's going to be how much has been paid against that request you're going to get the content data that's the extra stuff that I talked about earlier like the line items or the addresses and stuff like that you're going to get information about the currency what chain it's on the erc20 address if there is one and other parameters

um and then you're going to find out whether or not the request is pending meaning whether it's been accepted by the payer or not okay uh the that's how you look it up by ID um there's also instructions here for if you want to look up all of the requests for a given ethereum address that's also an option you call the uh the from identity function and so when you when you're calling this you would pass in the um the address of the the of the the ethereum address that you're using and it's going to return back to you an array of requests uh from which you can you can then call the get data function on each one of them okay so that's uh that's pretty much all

I want to say about retrieval I'm going to jump over back to my Quick Start I'm going to go over to the payment processing um parts of the part of the presentation when you want to pay a request this is something that the payer would have the access to do um there's a bunch of different ways that you could pay it um and I I kind of alluded to it earlier our payment processing networks support a variety of different features like you can you can pay in the native token on whatever chain you're on so for ethereum that would be eth for polygon that would be Mech um you can also pay in uh any of the

erc20 tokens that exists on those Networks um so that would be like your usdc usdt or any other other token that that has been created Rec for example Rec is an erc20 that exists on ethereum uh that's the native that's that's the protocol token for request Network by the way um we also have the ability to do conversion and and conversion is a feature where um the request is denominated in a currency other other than the one that it's actually paid in this is useful for accounting where most accounting systems denominate all of their payments and requests and invoices in USD or some other Fiat token

uh so what our conversion network does is it it integrates um chain link oracles uh price feeds so that you can determine the the exact amount of a particular currency to be paid at the moment of payment based on an underlying USD amount so I could in in layman's terms basically I would send a request for 500 in USD uh but I want to be paid in usdc So at the moment of payment it's going to go out and check the usdc um price Oracle and I'm going to be uh guaranteed to receive exactly 500 worth of usdc even if usdc is slightly above or below the

one dollar Peg at that exact moment um some of the other features we support is escrow you're able to Escrow the funds um this is useful for a lot of like um I mean you guys probably know what what escrow is escrow is great for Freelancers if you want to have proof of of uh payment before work gets started and have those funds locked up into an escrow that's super useful and um the other one that we support is being able to swap swap to pay that's the idea where you are the the um the request issuer the payee they want to get paid in say usdc but

the payer only wants to pay in die um what a swap to pay does is that at the moment of payment it's actually going to go out and swap the die into usdc and then pay the usdc to the uh the payee obviously there's a little bit of slippage that's involved in that we have our um we use a an aggregation service to to make sure that all those swaps occur uh with the with the lowest amount of slippage possible um yeah that's I'll I'll leave it at that for now this this guide here has some information about how to pay the request um for for any of those given networks that I talked about uh the the payment the payment methods that I talked about

all of them are going to have a pay request function so when you create the request you specify which payment method you want and then when you pay it you just call the pay request function and it takes care of all the logic uh behind the scenes to make that occur um I'm going to real briefly talk about our payment detection stuff jump back to our Quick Start if you want to detect the payment basically we 've we've got a series of different um subgraphs sorry not different Subs yes we've got a single payment subgraph definition that we've deployed to

multiple different evm chains um and we've got a link to it here in the detective payment guide if you jump over to that it's going to have examples down here at the bottom of how to interact with it basically there's there's this idea of a payment object inside the subgraph and for each payment you can look up the transaction hash the gas price at the moment of payment the contract that it was emitted from so that's going to inform you which which payment extension you're using you're using escrow is going to be a separate contract from the erc20s Arc 20s is going to be separate from the Native tokens that's what that's used for it's going to tell you the block the amount the

amount in crypto so this is this is going to be like the the underlying USD amount if you're using conversion and then the amount in crypto is going to be the actual amount of of tokens that is exchanged um it's going to tell you information about any fees that were taken out at the time of payment uh it's going to tell you about the the payment reference the request ID uh the two in the from address as well as the uh the currency that's being paid in so yeah if you want to know more about the payment detection definitely jump over to our payment subgraph um repository and it'll tell you all about it [Music]

um yeah that's uh that's pretty much all I want to say about payment detection uh so with what am I doing on time I think I have another some more minutes I've lost track of the time um but I have a demo for you guys real quick there's there's a um we have a an application uh adapt that we call request create at the URL shown on screen and it's a it's a simple dap that showcases how some of these features can be used together of the request Network uh basically it gives you the ability to create requests and then view all of the

requests that you've created in the past so I've got my test account here you can see that I have created several requests in the past um all of them are in different different tokens and different chains some of them are still awaiting payment some of them are still in progress actually you know what I'm not I'm not sure why it's showing up like that um interesting I'll have to take a look at that it's a it's it's supposed to show if if stuff is paid already some of these I know are already paid but um I think that there are our production

version of this app might not be as up-to-date as our staging version is but um so from the dashboard here you can um you can click into any of the requests and actually see uh more information about it and you can share a link to that request um if it's if it's unpaid you can share the link to the payer to give them a notification that that you're requesting payment um I'm gonna real quickly go go through the entire flow so the first thing I want to do is I'm going to copy and paste my my Bob Bob wallet address because that's who I want to request funds from I'm going to request from

them uh 350 die uh these are some of the currencies that this the app is supporting right now so Dai is an erc20 on top of ethereum and I'm going to ask for a reason this is just some metadata that I'm attaching to the request made me die um so then I would want to create the request and from there it's going to request a or it's going to prompt me to sign the message and we can see inside the message here it's it's got all the the parameters that I described earlier the currency the network the type it's an erc20 transfer the

expected amount uh and a bunch of other stuff I'm not going to go too far into it I'm going to go ahead and sign this we're going to wait for the request to be created voila so it has brought me to this this new page where I can copy the link and I could send this link to the payer so um I know that the pair was the Bob account I'm going to just paste this here oh I just realized I created this as a payment for uh on ethereum as a real request I probably should have done a

test request because I'm not going to actually pay 350 die right now um one second I should have done this on Gourley there we go um I'm just going to real quickly create another one and that's the wrong thing I need my I need my Bob account and I've just made another mistake I

realized I was attached to my Bob account and then I requested funds from my Bob account at the same time that's fine we'll we'll figure it out um it'll be it'll be a payment to itself I think it'll still work okay so I have the link now I can copy and paste that over to my other tab it's still creating the request in ipfs so once that's complete I should be able to pay it there we go so the request has been created in ipfs and a hash of it has been stored on gnosis chain

or sorry in this case it'd be stored on Gourley but um now I should have the option to pay it I click a single button it figures out the payment Network that I'm using I have a pop-up here that's going to describe what's about to happen I'm going to transfer one FAU token over to itself I'm going to bump up the fee just so I don't have to wait as long and I'm going to confirm it and then we can see that the request becomes pending we're waiting for it to be um accepted on chain as a valid transaction and in a separate tab I can open up the Gorly transaction uh viewer and we can see that the progress

excellent it looks like it's been confirmed in just a few more seconds it'll hopefully be indexed on and there it is we can see that it's sent one faucet token from Bob and then it also sent it to Bob so kind of a pointless transaction but uh you get the idea that's how it would work um okay so just uh just a quick closing thought uh the only other thing that I wanted to tell you guys is that we have a uh we have a standing grant program at request network uh outside of outside of this hackathon so if if you guys are interested um in building with us just know that um we have additional grants available to

uh Builders who are building on our protocol after after the hackathon ends um if you're interested in building with us we'd love to hear from you uh that's that's all the information I've got awesome thank you so much David um yeah really awesome great to um have a very uh good overview of how to uh yeah use request um yeah so we've got some questions um okay let's go through them first so um Nas asks how request does automatic tax report right okay so so for tax reporting

um one of the things that's that's a little bit difficult to to assess is like which transactions are Income versus um some other type of payment um so that's really kind of what what the request network is is is aimed at doing it's a it's a lower level primitive that would allow you to build an automatic um tax reporting tool but all of the tax reporting logic that would all have to be part of the the application that's built on top of it the protocol doesn't itself um provide that sort of uh information do you get what I'm saying it uh yeah awesome cool

um next question from nas uh how how do you do the conflict resolution for escrow did you answer this sure so the the escrow contracts um basically at any time either either party the payer or the payee has the ability to freeze the funds inside of the escrow and that's done via a smart contract call um once the funds gets they get Frozen um a timer starts and um I think if the if the payer freezes it there's I don't remember the exact time frames but I think it's longer for if the if the um

the payer freezes it if the payee freezes it if there's a there's a short shorter time period and um during that Frozen time um I believe that uh um I think at the end the the the payment will still go through to the payer but um The Hope is that during that Frozen time the payer and the payee can come to some sort of resolution on their own um and if they can't come to a resolution then the the the time out the the time that it the funds are locked

acts as kind of the punishment for for either party um for for reneging on on the on the contract reneging on the on the payment agreement does that kind of make sense I think so I think I will uh see if NASA has any other questions I'm just watching the chat um any docks I guess docs uh docs for the for the escrow I'm assuming um yeah yes yeah so there are there is documentation for our smart contracts um I gotta jump over the to the GitHub real quick for the smart contracts you're gonna want to go straight into the

request Network Repository inside the packages slash smart contracts and then I think that there is ah this is this is going to bring you straight to the actual contracts themselves um I think that there's a one second um X no that's not what it wants

I apologize there um there is documentation it's just it's kind of buried I think I think there's there's a few different places you would want to look you'd want to look at the payment processor uh package you would want to look at the the payment detection package and you would want to look at the Smart contract package and there's there's a couple of different escrow contracts for that awesome cool yeah um yeah if there's any specific links as well that you'd like to share feel free to drop them in the Discord later David or just pass them on to me

um okay but yeah NASA's saying no problem um yeah um I think there were a few more questions um one more from nas uh during the demo your request takes a while to generate I guess because you store it on ipfs um is it not just filling up ipfs with unnecessary data um just want to hear your view on this and logic behind it sure um so the the purpose of of storing that stuff on ipfs is to create a um a shared medium of exchange so that uh uh so that multiple parties are able to read the same data um but we also create the the content

identifiable hash the CID uh or sorry the content identifier which is a hash of the data um the time that it takes to to create the request is both the time it takes to to store the data in ipfs and also the amount of time it takes to take that hash the CID and store it on chain either on gnosis chain or on um Gourley uh so that's that's kind of what where that time delay comes from and I'd say that most of the delay is from the blockchain transactions I think the ipfs stuff tends to be pretty quick cool I hit the answer and um the the the topic of filling up ipfs with useless

data um technically the the request Network actually uses its own like um uh separate but still public version of ipfs so it it separates the the request data out from the main ipfs um and that was partially done as a a performance um uh for for performance reasons to to increase the speed of data lookup and data right um so as far as bloating the main ipfs I our our requests are not are not bloating the main ipfs at all awesome

they're coming in chat but NASA's thank you for clarifying um okay uh one more question then the questions tab uh can't you ask any plans for sepolia um yes we do plan for sepolia uh it's it's on my to-do list we uh obviously Gourley is going end of end of life at the end of this year ideally I would like to deploy to sepolia well before that but um it's uh We've we've just got to do it sometime in the next six months yeah work in progress awesome um cool Jade asked sorry about that uh Jade asks is there a startup script to call the ipfs can we connect to the IPS ipfs node um

um yeah I think when when you're creating the request um I think when you're creating the request Network object you have the ability to specify ipfs options um where's the best way to see that um when you are constructing the request Network you have the uh it's kind of buried a little bit here I'll show you um sorry this is all right hectic um inside the here I'll bring I'll bring this back so I'm inside the code for the

okay here we go um inside request Network packages request client API requestnetwork.ts that file this is the file that defines the request Network object um and basically when you're when you're creating the request Network object you have the ability to pass into it the um where is it oh it's it's going to be it's not this one I'm sorry it's in yes there is there I I let I would love to talk more about it after after uh after the um the presentation chain

sorry about that are there any other questions um no I think I think that's pretty much it and that kind of actually perfectly takes us to time um yeah thank you everyone so much for all of your questions and stuff um especially the ones that really get David thinking um yeah uh so I guess just a few little housekeeping things to wrap up um to everyone in the audience make sure you've signed up for this hackathon if you haven't already um and more importantly actually I would say that you've joined our Discord group uh and our part um have joined the specific hackathon channel so that you

can get all of the up-to-date information as well as being able to contact all of our sponsors um directly in their sponsored zones um David thank you so much again um Happy Star Wars day um and yes it's a yeah um yeah I hope you have a wonderful rest of your day thank you so much for speaking um and to everyone who's come along today and joined us for both the first and the second half thank you so much um and stay tuned for the recordings if you want to uh go over go over go over everything

um but yeah any final words David uh if you have any other questions about request Network I'm happy to help awesome okay well uh with that I guess we will end it there so um oh you're very welcome Alex um yeah I hope see you guys very very soon see you guys [Music]

Related talks