Skip to content
by Unity Nodes
NEAR DevHub

DevHub Live 23 - Build with Proximity

about 1:02:58 long

Nothing is loaded from YouTube until you press play, and then without tracking cookies.

About this video

Links: https://github.com/near-examples/chai...

Transcript

10,361 words

Captions as YouTube publishes them, usually machine-generated, so product and people names can be misheard.

  1. 0:00

    me what you want what you want what you want want me what you want want what you want what you want what you want what you want

  2. 1:17

    hey welcome to another episode of Dev Hub live we have an extra bonus episode today let me get rid of this Banner in front of my face here we go uh this is a great one if you're building uh on chain abstraction you you know chain signatures we have uh Matt from proximity here today to kind of go through some different stuff uh he's been working on all kinds of really cool Tech around this and I think it's going to be a great session uh if you haven't

  3. 1:42

    signed up already uh at the bottom we have the link for the redacted hackathon uh set up there so you can get started there you still have until October end of October to build there's multiple different bounties you can go in and do uh so a lot of great opportunities here but I want to maximize this time uh you can ask questions if you're watching here live you can ask questions we will

  4. 2:05

    try to address those as best as possible uh but I want to make sure that we have enough time to get through some different things here and have Matt really introduce us to some of the really cool things that can actually happen on here so without any further Ado uh let me bring out Matt lock here to the stage hey Matt thanks for joining us Hey Joe yeah good to see you it's been a while um um yeah it's a really great to be

  5. 2:31

    here um coming in and out of focus but uh yeah um I have a lot to share about chain signatures um it's going to be uh a little bit um kind of anticlimactic we're not going to be doing anything live right now the chain signatures team working tirelessly they're uh upgrading a few things right now so uh the testet and the main net are just a little bit in flux um but I have uh video that I

  6. 3:00

    pre-recorded um about a month ago uh based on something I call my chain Sig script um which is basically like a multi-chain you can execute transactions on any chain um and then I'm going to walk through that um and explain kind of how that works but I'm also going to uh go through the more detailed example or like the more advanced example and that example is really cool um basically what we do is uh we use chain signatures to

  7. 3:33

    deploy uh an nft contract on ethereum and then we call through a near contract uh we call the chain signatures contract and then we basically mint an nft and the reason why you'd want to use chain signatures through a near contract is because this allows you to basically build like a protocol and then um we'll go into like a discussion like maybe you and me we can start that off um about different applications of chain signatures and and kind of how to build

  8. 4:05

    these multi-chain protocols um and regardless it's a great technology it's something that's got me really fired up about uh about near lately and um and there's tons of applications pretty much endless applications no that's awesome and I'm excited that you brought up the part that part because one of the questions that I've heard come up a few times now is the concept of actually

  9. 4:28

    like using chain signatures on near not just kind of going outward so I think that's that's a cool part to kind of touch on as well um let's start however you want to jump into this sure yeah I'm gonna go ahead um I'm just gonna share my screen sure just one sec there we go cool yeah we got m mle Windows here um first I just want to mention that and I'll come back to this in a bit um but proximity is putting up a lot of bounties for the redacted hackthon um so this is all to do with chain abstraction

  10. 5:11

    chain signatures um the requirements is of course interoperability it's all about chain abstraction so you got to use near Plus at least one other blockchain um there's going to be you know some basically some marks for user experience and security and Innovation so um showing some creative use of near chain abstraction um and then here's the evaluation criteria but we can come back

  11. 5:35

    to this later if we have time um the one big thing to notice is that there's $35,000 uh in prizes so uh definitely if you're in the redacted hackathon um something to think about um Defi and Bitcoin are are basically like the the real big things that proximity is looking at um so you can do a lot with chain signatures um including you know leveraging non-smart contract chains like Bitcoin um using chain signatures so you can you can build interesting protocols you can do lots with defi so

  12. 6:06

    just definitely something to check out awesome um so do you just want to jump in um so basically I'm just gonna chat a little bit about uh this repo that that I put together several months ago when chain signatures was just kind of just a a sort of a beginning a beginning technology on near so it it has been around for quite a while um and this is just called the chain script so it's under github.com near- examples

  13. 6:48

    chain-packing so we can like see how this works um but just to jump into the overview it's basically just a command line and I just want go through the source here you can see there's multiple different chains here we actually had um a team from Cosmos um basically make a cosmos contribution so I didn't even do that uh they just recently made a PR so uh thanks to the arai team for doing that um and then other chains that I

  14. 7:18

    implemented a while ago were like obviously ethereum Bitcoin Dogecoin um and even xrp so um because chain signatures just produces an ecdsa sign signature we were able to actually execute transactions on all those other chains so five different chains are basically encompassed uh in this repo um but let's take a a step back and really think about like what is what what is chain signatures in general let's do like the basics so um the chain

  15. 7:50

    signatures protocol in near basically allows um it allows you to just do a simple near um kind ofun function call to the chain signatures contract and basically get back an ecdsa signature for any for any hash or or like payload that you would want to sign so um we all know like on different blockchains ethereum Bitcoin um what what have you you know all the transactions basically get hashed at some point whether it's a

  16. 8:23

    shot 256 or whether it's like a kak hash on ethereum all the transtion action details get hashed down into basically uh you know 32 bytes so how do you sign those 32 bytes well that's where the chain signatures uh Team came in and they basically created this protocol that allows us to use a multiparty uh sort of set of nodes to produce a secure signature for any hash now how do you how do we actually get a hash uh well we basically have to call the near chain signatures contract

  17. 9:00

    um now we're making a signature for a hash but but another question comes up what's the account that we're actually signing for or from right like typically if we if we make a signature it's it's signed by some private key and that key has an accompanying public key and what we know about public private key pairs on chains like Bitcoin and ethereum is that they also uh the public Keys also represent the the addresses in there's a bit of kind of code and massaging to get

  18. 9:33

    to the address but basically the public key and the address are kind of like a onetoone uh there's a onetoone correspondence there so how do we get um how do we get a public key for the uh the chain signatures account that we're that we're going to get the the signature for the hash from well I like to kind of keep this really really simple so um every we call it a derived account on chain signatures so for

  19. 10:02

    example if we wanted a public key for an ethereum account we would basically be calling the near chain signatures account from this near account ID let's say it's you know matt. near we would add a path variable so you could think of this like a hardware offset like um like on a ledger um we have like you know different Hardware offsets off of our device to get different accounts so you can pass in anything you want the path variable is just a string so um

  20. 10:33

    typically if you're looking for an ethereum derived account you'd pass in like ethereum comma one and then you would get basically um a derived account so um the next time you call a sign on the Chain signatures contract and you pass it the hash that you want to sign or or what we call sometimes the payload of 32 bytes you would also pass in the path variable and then the signature you

  21. 10:58

    would get would cor would correspond to that derived account and if you took the the hash and the signature and you ran it through um a typical what they call like a EC recover or ecdsa uh recovery from assigned payload you would basically get the derived accounts uh public key so um so that's basically that's basically kind of like the basics of chain signatures um all the chain signatures prot does just want to keep it super simple

  22. 11:31

    for people who are hacking on this all the chain signatur protocol does really is expose this sign method you you pass in a hash and a path and you basically get a signature for your derived account now a lot a lot of people kind of are are thinking okay well you know how do I actually uh know what my derived account is going to be uh ahead of time right like how do I actually generate that well in um in this repo and in another example repo I'll talk about in a sec we have um a

  23. 12:05

    file called kdf um this there's a lot of there's a lot of code going on here but basically um I've tried to simplify it as much as possible uh by boiling everything down to a generate address uh you know method here where or function where you can just say Okay um I've got the uh there's a few kind of extra bits like I've got the public key of the chain signatures contract uh that's just kind of a requirement it's really easy to get that I've got the account ID of

  24. 12:37

    the near account I'm calling from so that was the account ID we saw before the near account ID I've got the path and then you just tell it which chain you want so you just say I want an ethereum uh address and and this script will go ahead and it'll just generate an ethereum address for you and then uh at the end it'll it'll just return that information it'll return the address and

  25. 13:00

    actually the public key as well so um basically was a longwinded way of saying um you know how do I get my derived account kind of offline or how do I actually get derived account before I call the chain Signature Sign method with my with my hash like and and the reason you'd want to do that is you'd want to fund typically you'd want to fund that derived account or you'd want to know you know you'd want to know which derived account is going to actually uh be called on to to execute that final

  26. 13:32

    sign transaction so the kdf script is what you can do you can call that offline you can generate uh you can generate as many derived accounts as you want um and then it's just it's really comes down to what your what your application is what your protocol is and what you're planning to do with those derived accounts so um yeah so the kdf script uh is is basically just like a deterministic way to generate these derived accounts so I want to just

  27. 14:04

    clarify people something for people um when you say ethereum you're meaning all EVMS you're not differentiating between different l2s or are you um no yeah uh that's a great a great Point um I'm trying I'm trying to actually go go back through these uh these code examples and rename ethereum to evm and stuff because you know it's uh it basically is any evm chain um you bring up a really interesting point though for derived accounts um You probably if you were if you're going to

  28. 14:39

    mainnet with this you know you'd probably want to make sure that one derived uh account on on your kind of multi-chain protocol would not create the same um the same evm address for multiple chains because there could be you know there could be some issues uh where you're on kind of two different l2s with the same address um so that's where this path variable might come in handy like you might want to basically let's say you wanted to restrict a user to uh just the ethereum mainnet you

  29. 15:13

    might want to do you know ethereum underscore mainnet comma one comma two comma three for different derived accounts for mainnet um it's just just an idea um it's uh it's probably kind of prudent to do something like that but uh yeah just just great great brainstorming there um but yeah the derived accounts could actually be used on any evm chain um and also the derived accounts uh remember if we go

  30. 15:44

    back if we go back to this kdf script um what we're really looking at is like we can get ethereum uh I have BTC for BTC mainnet and then I have Bitcoin for for Bitcoin testet um coin xrp Cosmos is here um and really what we're getting is we're just getting entropy and we're basically generating you know the sometimes the addresses have different kind of configurations how they're generated from the public key but we're really just getting we're really just getting ecdsa key pairs at the end of

  31. 16:18

    the day um and so it's like whatever we pass into this path variable will create an ecdsa key pair and then we can use it wherever we want want wherever um you know wherever uh a chain uses uh ecdsa and by by the way uh ed25519 signatures will also be coming to change signatures uh soon so there'll be an actual ability to uh to not just uh specify your path but specify like your key version and then um you'll be able to generate ed25519 signatures for for chains you

  32. 16:57

    know like salana and other chain that use those signatures does that does that kind of answer the question yeah I think I I think so yeah it's you know I want to make sure that people truly understand like how powerful this stuff is and like it's really not limiting especially as you know the next version comes out and you can now go to pretty much once you add in that next key now we're talking about right salana and other CH pretty much everything's encompassed and so now

  33. 17:26

    it's truly an Open Door to build across everything that you can think of in crypto yeah exactly um it's a very it's a very low-level protocol um but because you know because we kind of we kind of cook it up with names like chain abstraction and and chain signatures and derived accounts and stuff it seems more complicated than it is but it's very very simple um you you basically just need two components you need to uh you

  34. 17:59

    need to basically use some sort of key derivation script which is the one that I showed earlier um as part of this chain Sig uh uh script repo you basically need that to generate these derived accounts offline and really when you're generating a derived account there's no magic to whether it's ethereum evm Bitcoin Dogecoin whatever it's basically just an ecdsa uh public key um and then the the account is basically you know like

  35. 18:30

    generated off of that public key now you can generate as many as you want because of this path variable and and the corresponding the call or near account ID and now this this is if you're in the near world you know it makes it makes sense to mention that this is always going to be the predecessor caller to the chain signatures contract combined with this path variable I want to touch on that later because sometimes we're not just calling the chain signatures account from a near account like

  36. 19:02

    directly from a client account sometimes we're calling it from a near smart contract which will change the entire derived accounts uh that that get created so um I'll come back to that point in later but it's basically just those derived accounts how do we derive them we use the script we you know you can add the script to your app or you know if you're running it on a back end you know it can just it can just spit out as many derived accounts as you want um and then it's it comes down to

  37. 19:32

    getting signatures so just calling that sign method and basically uh let's just uh cruise down here to calling the NPC sign method so the near account will call the sign method and it specifies uh the path which is what we saw from the kdf stuff before the payload and the key version for now the key version is just zero but in the future like I mentioned there'll be different key versions like ed2 5019 and other things so um so that's really all there is to it the

  38. 20:02

    near account will call the NPC contract and then it'll return a signature for the derived account so there's really just like those two parts um you know you want to create an account on a different on a different chain right um and then basically you want to sign something for it that's all there is to it did you uh did you want to kind of recap anything there Joe no I I think this is yeah I think we're we're a good track here cool yeah

  39. 20:31

    and and I just wanted to uh I just wanted to mention like um just going back to this example here there there's a bunch of pre-built accounts that can basically um kind of help simplify a lot of things like um if you just type yarn and then just- EA for example you'll just get an ethereum address they'll typo there but um you'll basically get an ethereum address and that'll be based on your your path variable that you specify in your environment um in your

  40. 21:02

    environment variables I I included like an environment variable sample here and here's my MBC path so um basically you just you could change if if I change that ethereum comma 1 to etherium comma 2 for example I'd get a different derived account um so you can just run yarnart ea uh you can um you can run yarnart etx which would which would prompt you to send eth um and then there's a few more configurations like you can set the amount and the two and the reason why it's just like these basic commands is

  41. 21:35

    because it tried to kind of make it um make it kind of like uh you know multi-chain accessible so uh you don't just have to send ethereum you could for example send uh Bitcoin from the derived account um now it does require you to kind of pre-fund the derived account which is why the first step is usually uh figuring out what your derived account address is you would put some funds in there and then if you wanted to use chain signature to send funds from there you could use uh this let's say

  42. 22:07

    it's Bitcoin you could use this yarn start- btx um um command and then you could uh specify an amount or a two there there are default amounts and default kind of destination addresses built in um they're usually going to meet thanks but it's all it's all test net but um but yeah that that's just just simplified commands and stuff um and this was just this this goes all the way back to me like in the very

  43. 22:34

    beginning kind of just creating some basic tooling to kind of see everything we could do with chain signatures and just kind of uh you know push the limits and you could think of it kind of like it's it's a bit of a a script kind of command line tool but it's also kind of it's also a bit for kind of debugging and and testing the chain signatures um the chain signatures functional as well

  44. 22:59

    like just what can we do can we can we deploy an evm contract well sure you know we can use we can use these commands to do it um can we make ethereum contract calls through chain signatures sure we can right so I just wrapped up some of that functionality and and created that there um the evm contract deployment and interactions that's a that's actually a cool place to dig in if you wanna if you want to take

  45. 23:24

    a look at that at a later time but um yeah I just I want to back to um I want to go back to this sign uh method call because it's really just like it's the second component of chain signatures um and so to do this sign call from your near account or from your near contract you're basically just going to pass in this uh request argument um so it is a single uh a single object kind of called request or struct uh in Rust um and then then it's

  46. 23:58

    basically just the payload which I mentioned was 32 bytes uh the path variable which is a string so for example ethereum comma one or Bitcoin comma one and then the key version which right now is just uh is just zero um and then basically that uh once so the MPC nodes will spring into action and then they'll basically um they'll uh they each produce part of your of your signature and then um basically your signatures kind of composed and sent

  47. 24:31

    back to you um one thing that I think people might ask about is uh sorry I I don't want to jump around too much but one thing people might ask about about these derived accounts is that um sure you can get a derived account um but sometimes people get hung up on the fact that yes this is a public key but people think well where's the private key you know it's a public key there's got to be a private public key pair right um and

  48. 25:02

    that is a very interesting question um but in fact there is no uh there is no private key for any of these derived accounts so there's uh you know if you kind of if you kind of mess up with a derived account and you fund it or something or you and you forget let's say you forget your path variable or whatever for whatever reason um there's no there's no seed phrase or private key

  49. 25:27

    that was ever generated for this account so um and that that is uh kind of uh built in by Design um and that's so that when you're doing when you're doing these chain signatures uh when you're building these chain signature protocols with these derived accounts it's so that basically like there's no there's no leakage of like you know another way to execute these transactions so remember like the only way to execute these transactions

  50. 25:56

    the only way to call sign is from the near account with the right path variable for that derived account and that's the only way to generate that that signature um so there's there's never when you derive the accounts there's never going to be a private key um and also so if I lose so if I do have I forget my path variable for whatever reason I I lose it uh am I am I locked out of that while that those funds are are lost

  51. 26:28

    yeah if you lose control over the near account you're calling from or you're if you just mess up and let's say your path variables were randomly generated like it was near account ID plus some sort of seed phrase that that was just the way you designed your protocol let's say you misplaced that seed phrase then yeah the control over the derived account is gone basically right MH and it it's just it is a security thing like if you think about like you don't want you don't want any like obviously you don't want any

  52. 27:01

    near account to be able to say hey ethereum comma one and then access Joe's Joe's funds in his derived account on let's say optimism or something right like you don't want anyone else to be able to do that but also um there this is a really interesting point is how are how these derived accounts are made is that you know I mentioned that that the chain signatures is a is a multi-party computation protocol so the chain signatures nodes themselves they also

  53. 27:33

    produce this public key which is which is part of this derived account calculation um and the we kind of we typically call it the MPC public key or the the near chain signatures contract public key now that public key is the shared public key from all the nodes and then you might be asking well again there's a public key where is the private key there is no and and that's the design of basically an MPC system is that you've got all these nodes and they

  54. 28:06

    produce some shared entropy but not none of the nodes would ever be able to compose the actual private key because if they could it'd be as if if they had a master key to everything right right right so uh that that's just kind of that that's just the general kind of like highle abstract like how does it all work kind of thing um I do want to get get into this uh this stuff because

  55. 28:30

    this is a really this is the meat and potatoes and we about how to build kind of applications and protocols so um if you dive if you dive into this uh chain Sig script example uh later and you kind of dive into the code and stuff you're going to come across uh this ethereum evm contract example now what we're trying to do here is we're basically going to um we're going to get uh the near account to basically call the NPC contract and get a signature for a derived account we're going to take

  56. 29:04

    that derived evm account we're going to deploy an nft contract to it now there's an nft contract deployed to this ethereum derived address now remember the ethereum derived address it is an ethereum account it exists but there's no there's no private key there's no uh there's no way to import it into metamask or whatever the only way to control control this ethereum account is

  57. 29:30

    through a call to um to the near uh MPC or chain signatur contract from the originating near account so how do we actually mint an nft on that ethereum uh that that that nft contract we just deployed on ethereum well we have to call again from the same near account to the NPC contract get a signature for the mint transaction and then uh what we do is for the derived AVM account we take that signature combine it with the mint

  58. 30:03

    transaction that we you know that we composed and hashed when we when we pass the payload to the NPC contract and then we broadcast it to for example sapoia testnet and an nft will be minted so what's really cool here is that we basically can deploy uh you know we can deploy an ethereum account put a little bit of funds in it make it an nft contract and then we can just start minting nfts from that ethereum account into other evm accounts as well like we

  59. 30:34

    can say that the owner of the newly minted nft should be this address or that address and um and we can do this all from uh basically from near calls right so uh what what that what that means is basically the application Logic for Distributing these nfts on on an evm chain so for example on it could be on ethereum it could be on optimism it could be on arbitrum it doesn't matter but the logic for Distributing these

  60. 31:05

    nfts uh comes from basically a a near account or a near smart contract and that's that's the last part I wanted to get to which is you can actually call the near um the near chain signatures contract from your own uh near contract so this is going to involve and and we'll dive into the code after this because I think some people probably want to get into like the actual cross contract call and kind of take a look at

  61. 31:33

    that but yeah this is really where uh chain signatures kind of shines is that we can actually create a custom near contract and then we can uh call the near chain signatures contract from that contract and we can get back uh the signature and then return that to the client now why would we want to call why wouldn't we just want to call the chain signatures um contract directly from a near account like in this example well you know a near like a a near account kind of uh or

  62. 32:06

    what they would call on on an evm chain like an externally owned account it's kind of it's kind of basic right there's no there's no logic there's no rules to it there's no there's no code right um but if we can call the MPC contract from our own custom contract we can enforce a lot of different kind of rules and logic so in the example I've made um I actually require we we'll just skip down

  63. 32:31

    to step two here I require that if you're calling the near Custom Contract from any near account and I I specify that because you can call the custom contract as itself you know like like a near contract owner could call itself right in its method but basically I've restricted this near Custom Contract and I'll walk through the logic of how I did that later uh in in just like two minutes um any near account that calls this Custom Contract and wants to Mint

  64. 33:03

    an nft on the evm account um to to any other evm address they I required that they have to pay one near so there's actually like a bit of logic there basically says okay if you want to Mint an nft over on ethereum I'm gonna actually ask you to pay one near token to do that and then the near uh the near Custom Contract will call the NPC contract and get that signature for the M transaction now it's going to return that it's going to return that all the way through to this calling near account which will combine it with the derived

  65. 33:37

    evm account where we know the nft contract is residing and then the mint transaction can be broadcasted and executed and the nft can actually be minted to the to the user so let's think about this for a second right like we're creating an application that basically requires uh you know near users to kind to kind of roll up to the to the gate you know pay one near for entry to get that to get that evm nft minted right so and it doesn't have to be one near you

  66. 34:07

    know I mean the sky is the limit you could do whatever now we're describing an example where uh where near near accounts have to kind of come up with the funds to pay for this nft but there is there is another interesting way to do this and I I personally have not created an example like this but it's the way that a lot of people are creating um their sort of like their defi examples or their um you know their

  67. 34:41

    multi-chain examples uh by basically uh Sid stepping well that's not the right word we're we're trying to come up with a way where where the I guess the currency the currency to me let's say the currency to M doesn't always have to be near it doesn't have to be near accounts paying one near so how would you kind of change this example well in the near Custom Contract what we could

  68. 35:06

    be looking for is we could be looking for uh generating a derived account where uh where we're looking for an input or a payment into that derived account right so what uh what a relayer or some like let's assume the user has no idea or no knowledge of near a relayer or someone that's looking at that that derived account that the Custom Contract made let's say that's just a deposit it's a deposit account for making a payment right so let's say it's like an ethereum account um and

  69. 35:40

    we're the the requirement was to actually pay uh you know 0.01 eth or whatever to to Mint an nft so what we could do is we could actually watch a derived ethereum address and then uh once the payment is made we we could transfer that payment out of that ethereum account and into basically like a holding account for that protocol and we would know that that that payment's been made and then we could

  70. 36:11

    call the NPC contract and M the nft so you see how there's kind of like different ways to flip it like right we don't have to use the derived account the derived account doesn't always have to be used as like the last step it could be used like as a funding step as well so that's how a lot of people are kind of thinking about chain signatures they're saying hey fund this derived

  71. 36:34

    address that that my smart contract has control over and if you fund that address I will credit you this token or this other thing on this other chain so you can kind of see how it starts the the possibilities start to get really wild right um yeah now in order to do some of that stuff safely and security like securely you need to have like kind of like approver on that other chain um or some relays or something to set like set up to basically make sure that uh

  72. 37:06

    you know the transactions are going through the funding was uh definitely completed on the other chain before you would kind of spring your Custom Contract into action does that make sense yeah so is that logic that's handling well two two parts of this one that logic is handling offchain or both or either or I guess um well you would you basically uh your protocol would create this derived account um let's say you were funding it with Bitcoin or ethereum or whatever and then you would tell you you know you

  73. 37:38

    tell the user send X amount to this address now the the protocol itself controls that address through chain signatures right so once the funds are deposited into that account obviously you know the user can't move them but but it's controlled by Chain signatures so it's controlled by the the smart contract logic of the contract that created the derived address right so you're basically kind of telling people it you could think of it kind of like a it's a bit of a Lo it's like a lockup

  74. 38:11

    right like it's sort of like send send funds to this lockup and then if you want to go ahead and and mint the nft or if you want to go ahead and and uh leverage those funds in a dii protocol or something uh you can go ahead and do that with this synthetic token that I'm going to credit you because you because you deposited funds into that chain signatures derived account does that make sense got it yeah so then from

  75. 38:37

    there if I mean is this essentially if you're taking this approach so on near we have the concept of meta transactions is this kind of like a chain abstracted way of thinking of like meta transactions like does it lead to that sorry let me phrase it lead it to that path of having something like that where I can entially take on that cost for my user um yeah that's actually that's an interesting point um it so it doesn't have anything directly to do with meta

  76. 39:08

    transactions however um there are ways to basically combine meta transactions um with that kind of a design like I mentioned that you know the user coming from let's just say chain X you know yeah they have no knowledge of near and so they're just going to deposit into they're just going to deposit into a derived account on chainx and and then after some amount of time you know the the protocol is going to basically credit them you know some token or some some gas or something to

  77. 39:47

    to basically be able to sort of continue on with the protocol on uh near as the application logic but if if this was a multi-chain like a chainx chain y kind of scenario and and we were using chain signatures uh you know deposit into a derived account on chain X then we're going to credit you on some funds on chain y I mean like you can see right away where the sky is the limit now how do we pay for all those near transactions um to basically execute the

  78. 40:20

    sign calls to the NPC contract that's a great question and meta transactions is one way to accomplish that and then the other way is sort of um kind of an old older School method is like custom relay and things like that right for that particular protocol yeah I think and what I want to highlight to viewers if you're doing the hackathon so one of the things we talked about with with David and the other one about chain abstraction was the concept

  79. 40:51

    of like you could pair you know near account abstraction with this and now you have that easy onboarding for users now we can also take it a step further combine a concept like a meta transaction and start to kind of fund parts of this and now from a user experience you could build a really interesting product that onboard somebody with pretty much zero friction but now you're able to leverage multiple chains in your product and then at some point maybe you know funding maybe comes from someplace else whatever El but you

  80. 41:26

    you have that ability to leverage those near already made infrastructure pieces to this protocol as well yeah yeah no exactly and I I'm going to touch on something else uh in just a moment um I just want to quickly I'll quickly Buzz through this contract um just so this is the contract that I mentioned is doing the cross contract call to the chain signatures contract um right away you can see that there's a sign request and again why why are we

  81. 41:57

    calling the chain signatures contract from a custom near contract it's because we want to build in some sort of application logic even the most basic uh logic which is which is you know some cost okay we're going to require that this costs one near token um we're just going to build in some logic and then and then we're going to call the chain signatures contract so we're not just going to let anyone uh basically get a signature to Mint an nft uh on on an

  82. 42:29

    ethereum contract for example we're not just going to let any near contract or sorry any near account do that we're going to make them all call through our near smart contract and that smart contract is going to require them to basically uh have paid one near token so I want to go through this sign method so this is a custom sign method uh specific to this protocol um and basically it

  83. 42:56

    takes in uh it doesn't take in the the full hash of the ethereum transaction it takes in What's called the rlp encoded payload um now the reason it takes in this payload is because as as a as a sort of a very very very basic protocol um we want to inspect something about this payload and what we want to inspect is if the user uh the near account that is calling the sign method is using one of the public rlp encoded method names now I I know

  84. 43:31

    this gets a little bit a little bit kind of um cryptic but basically this is just the the hash of the mint function call to an ethereum uh NF contract or or an evm nft contract so this is just really when you make a mint function call this is just the mint method um so the reason why I have that is uh because what I'm searching for in the rlp p p is that the rlp payload includes uh that mint call so so now I know that this is a public it's a public

  85. 44:06

    account and they're trying to call one of the public methods so I basically said okay this is a public method call um if it's not a public method call I require that this is the owner of the contract calling but that's not really that important um but basically so we've passed this public uh this public Check Yes they're they're trying to call the method of the evm contract okay so now

  86. 44:30

    this ethereum account what do we do we actually hash the rlp encoded payload so in ethereum it's a it's a kak 256 hash so we basically decode the hex rlp payload and we hash it so we decode that into bytes and then we hash those bytes and what we get is we get the payload that we're going to call the MPC contract with now the last thing to check and actually we probably should have done it before we spent gas hashing

  87. 44:56

    this so so these are kind of reversed uh it's a little bit of mistake on my part but you know this should be after this but what we are going to check is we're going to check the uh the attached deposit and we're going to make sure that the deposit is greater than or equal to the cost and I just put a funny you know pay the piper here um basically if you're not the owner of the contract I'm requiring that you pay me one near

  88. 45:21

    token in order to continue on and to basically call the MPC contract so again very very simple it's a bit uh it's I wouldn't I wouldn't say it's contrived you know it's pay one near token and mint an nft on an ethereum test right or it's pay one near Tes token but uh basically it just it shows how to kind of like think about these cross contract calls where you would kind of put in your application logic maybe how you

  89. 45:51

    would put it in uh you know and and really what you're going to want to do is you're going to want to inspect the payloads that the um that the user is going to eventually kind of get hashed and signed right so um some level of of of transaction construction would need to kind of happen in the ethereum uh or sorry in the near contract in order to um in order to kind of construct that

  90. 46:21

    evm transaction and eventually uh hash it so that a signature could be created um this is a perfect time to actually jump into another example that we've been working on um this is still a bit in development um but it's it's something I can kind of go over um very briefly um so this is a something I call uh trade signatures and it it is a bit of a joke but it's basically it's trading one

  91. 46:52

    signature for another um and now why would we want to do this well Joe you you know you brought up usability and you brought up this frictionless onboarding so really what we'd love to do sometimes is we'd love to have the user basically show up with their metamask or their Bitcoin wallet or whatever wallet from whatever chain and we'd love them to be able to sign a a transaction payload and um and then have

  92. 47:26

    that executed um by you know by Chain signatures uh and basically we're going to we're going to have them sign a payload in their wallet and then we're going to take that signature we're going to verify that they actually signed that payload to get that thing done on that other chain and then through chain signatures we're going to execute that so let me just show you the contract here really quick

  93. 47:55

    um I'm just jump into it um so there's a method here called trade signature and basically what we pass in is we pass in an owner and this could be a public key for Bitcoin or an address for an evm chain um we get a message and a signature and the message is the payload of the transaction that was signed so this payload is is usually destined for uh we're only working with three chains here for the destination chain Bitcoin

  94. 48:25

    evm and NE here um so the payload is basically like it's a partially signed Bitcoin transaction or it's a it's a very basic ethereum transaction um you know two value args things like that or it's a near transaction and uh it's like an unsigned near transaction so when this message payload comes in it's basically stringified Json of the entire transaction um and the user has already signed this in their wallet for example like in the okx wallet you can sign for

  95. 49:00

    Bitcoin or for an evm chain um and then what we do is we also pass in the signature so uh these using these three components the first step is that we would uh right now the source chains only Bitcoin and evm um but I'll be adding near soon but basically we will require that the owner uh the owner the message and the signature all kind of let's say just to simplify it add up right so basically we should be able to recover this owner variable uh in

  96. 49:34

    Bitcoin it's going to be a public key from the message and the signature in in the ethereum case it's going to be the address but same thing you know public key to address is is deterministic so what we're gonna do is we're going to require that the owner is a Bitcoin owner or an evm owner depending on what your Source chain is and then we're going to pass in the um uh the message and we're going to

  97. 50:00

    turn we're going to we're going to turn in or we're going to return basically a a signature for that destination chain um so just jump into like what one of these looks like is um uh we'll go back into um let's just look at Bitcoin owner so here's the require method so the recovered PK uh from all of this uh you know signed Bitcoin message parsing stuff that's going to eventually you know basically recover the the private sorry the public key and then we're

  98. 50:34

    going to make sure that that recovered PK equals the PK that we passed in so that owner is the the public key um if we signed an evm let's say we signed an evm payload with our Bitcoin wallet um then the next thing to do is to actually get an evm transaction from that payload so uh this is where we're using actually a library uh that proximity is developing called the Omni Library um and this is a transaction Builder um so

  99. 51:07

    basically you can see on this get transaction method we just have to call evm transaction from Json and then pass in a Json payload and the Omni library is actually going to uh parse it into an evm transaction um object for us and then we can actually just simply call uh build for signing and then we can do and that that will create the rlp encoded evm transaction and then we can just cash it and that gives us the payload and then uh in this in this

  100. 51:39

    particular um uh like rust contract I I basically put the chain signatures call under ecdsa here uh just to just to signify that one signature type and we just call ecdsa get Sig and that's right here um and just like the previous example where I was doing a cross contract call you can see that there's um there's a cross contract call to the MPC contract so this is where we're going to return uh we're going to call sign and return the signature so it's pretty cool stuff um

  101. 52:16

    this near trade signatures repo still very much in development but uh you know I'm working really hard kind of getting this uh getting this up to speed um as much as the chain script repo and kind of testing it and everything but uh but basically um it it this this repo basically demonstrates uh one of the coolest things which is that we can sign from other wallets a basically an unsigned transaction payload and then we can actually throw it into a near smart

  102. 52:49

    contract verify that signature and then we can take that unsigned transaction and we can encode it hash it and then call the MPC contract and get a signature for a destination chain which I think's pretty powerful stuff yeah I mean a lot of a lot of applications that can really come out of that so in this didn't end up using my video Joe yeah no no this was awesome but I I do want to say that this Workshop video here it's a it's it's like a tight 23 minute video and it goes through at least for the chain Sig

  103. 53:25

    script example I mean it goes through everything so if you want a walkth through of that code again and and what that uh what this repo's uh capable of then yeah you can check out the workshop video it's on the repo itself awesome awesome so from a a hackathon standpoint uh anyone can come in Fork these repos and start building on top of that right yeah I think like these repos are probably not they're like they're

  104. 53:54

    forkable but they're it's probably better to just kind of use them as uh as uh basically they're kind of like kitchen syn examples so you're going to want to basically kind of come in here and for example like you're GNA want to just go into the near contract for the cross contract call so you need to know two things right like how do I make a c like how do I how do I uh have some

  105. 54:18

    logic like how do I take in for example if you're doing evm stuff maybe you're taking in the rlp encoded uh evm transaction how do I figure out whether they're calling a particular method um and then you need to call the mpz contract so um typically where if you're building if you're building on chain signatures um I'll go over the the three key ingredients that you need to master basically to build on chain signatures

  106. 54:47

    number one is how do you deriv your accounts right like how do you how do you create these accounts that the user is going to use and I me men that before it's in kdf.org address um and you can see calls to generate address and how to create those derived accounts for different chains so that's that's step one um Master how to create derived accounts and just understanding that they're always coming

  107. 55:20

    from a near the calling near account ID whether that is a external account like just near client or whether it's an actual near smart contract it's the caller to the NPC contract plus the path the second thing to master is calling the sign method right and how to create the different uh the different payloads and different transactions that you're going to want to construct to call the um the sign

  108. 55:50

    method now building transactions for different chains can be kind of tedious but as you can see here there's like five different chains with examples on how to build transactions including especially if you're building some evm stuff the ethereum um file in the chaining script basically has everything you'd need to create transactions for for an evm chain you know you can deploy

  109. 56:15

    like deploying contracts uh the base transaction here deploys the contract the data is here and the bytes um calling contracts so making a contract call to VM chain so it's all here in ethereum.org how do you make those cross contract calls right and that was again uh that's under the near contracts here um and you can see just down at the bottom here's how we call uh basically an external account and we we basically call from

  110. 57:05

    one smart contract to another we call the chain signatures contract and with those three ingredients um derived accounts calling the sign method of the MPC contract and constructing your your destination chain uh transaction hashes um and then basically doing those cross contract calls inside your own near smart contract that's all you need to it's all you need to know awesome yeah

  111. 57:29

    no I I mean uh really great opportunity to to get involved in this you know I think it's great I'm going to share here too there's a telegram group that is specifically geared towards chain abstraction that people can jump into ask questions uh also the near Dev telegram group you can always ask questions there as well but uh this you know this is something that while it's it's new I think like you said there is just a lot of possibilities it's here it's working um and so people should

  112. 58:01

    absolutely check it out and uh in redacted hackathon you can stack bounties so you can do something with chain abstraction and tie it into something else and go for multiple bounties so uh it's worth a shot checking out yeah um I do want to mention the proximity bounties once more um hacking on Def Bitcoin using chain abstraction so combined ing uh near with at least one other blockchain um and always looking for Innovative use cases so we

  113. 58:33

    mentioned a few different ways to kind of set this up um you can obviously have uh you know near application logic controlling derived accounts or you can fund derived accounts uh from other chains and then have uh have the near smart contract um you know credit some synthetic token or something if you're doing defi um you can work with meta transactions to cover those near gas costs or you can work with kind of your own relayer setup on the back end um and

  114. 59:01

    then the last thing uh would basically be um this user this user experience stuff with the trade signatures example repo I was showing I mean it may not be kind of uh fully fully cleaned up and and ready ready for prime time but all the logic is still there like we're we're still signing we're signing unsigned transaction payloads for for M for example with a Bitcoin wallet and then we're basically uh we're basically parsing that and figuring out that the

  115. 59:33

    owner uh we're verifying the owner inside a near contract so we're verifying the ownership there and then we're uh we're using the Omni library to encode hash those transactions and then call the NPC contract with the cross contract call and get the signature so there's a lot going on there and there's a lot to uh there's a lot you can just kind of beg borrow and steal from those

  116. 59:57

    repos and and totally uh you know that's what that's what our role is here is like our role is here to just create these example repos create this base code and to educate and stuff so uh feel free to kind of grab those code Snippets like I said it's just a kitchen sink just grab those pieces of code and just go nuts and and make something really really cool for the reducted hackathon yeah awesome yeah no I this was great

  117. 1:00:22

    Matt I really appreciate your time uh yeah apologies for five examples um that's okay like I I know I know the chain signators team is really they're working very very hard on up time right now and it like they've just been working uh tirelessly on it and I know that uh I know that we're very very close to just uh extremely robust uh like protocol and uptime and speeds and and cost efficiency as well for these signatures so what I'm really excited about is that um you know I think I

  118. 1:00:54

    think the chain signators team is building like kind of the right solution for the future here um for multi-chain um protocols and I think that it's going to be fast cost effective I think the user experience is going to be excellent um it's already if you're if you're hacking in the hackathon and you're using the chain signatures um uh you know it's already kind of magic um it

  119. 1:01:19

    feels cool every time every time I use it it feels really cool uh to be able to you know to call a contract have that you know have that signature generated return to the client broadcast that transaction and see it on an Explorer it just feels so cool there's a few other videos uh that I'll I'll I'll share in the telegram channels and stuff like that where I'm doing this kind of

  120. 1:01:42

    you know sign with a Bitcoin wallet execute on ethereum kind of stuff um there's a few other videos I'll share as well awesome that yeah that that that's great and again people can always pop into any different support channels ask questions uh near devhub and proximities here to help support you in in your building well thank you Matt um again I really appreciate your time and we look

  121. 1:02:06

    forward to seeing you again soon yeah I'm excited to see what people hack on the the hackathon thanks again for the time Joe awesome thank you take care mat take care all right uh that was great again if you haven't signed up for the hackathon already uh definitely go check it out there are hundreds of thousands of prizes at this point there are tons of different bound there's something for everybody uh so it's a great opportunity to kind of just

  122. 1:02:30

    dive in even if you're not a near developer it's a great opportunity to kind of jump in and see what's uh capable here on near as well as again some of these great different both AI chain signatures and just Standard Building on uh an L1 is all available to you uh this was a special bonus episode we still have devhub live tomorrow uh at our normal time 4M UTC uh so we will will be back with another redacted

  123. 1:02:58

    Workshop this time with Aurora it's building on top of an evm here on near so there a lot of great stuff still happening so we will see you tomorrow at 4M UTC for the next Workshop until then take care