Skip to content
by Unity Nodes
NEAR Protocol

[REDACTED] online hackathon workshop Proximity

about 1:02:42 long

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

About this video

Exploring Chain Signatures and Multi-Chain Protocols with Matt Lockyer from Proximity Labs | DevHub Live Bonus

Register for Online hackathon redacted.devpost.com

Proximity x.com/proximityfi proximity.dev

Live DevRel and Community Support: NEAR Dev Support Channels (Telegram): t.me/neardev DevHub Announcements: t.me/NEARDevHub

Final Submissions Due:October 31th, 2024 Judging Oct 31 - Nov 8th

In this episode of ‪@NEARDevHub‬ Live, Matt Lockyer from Proximity Labs dives deep into the technical capabilities of chain signatures and multi-chain protocols. Matt breaks down how developers can leverage NEAR and other blockchains for cross-chain transactions. If you’re participating in the NEAR protocol [REDACTED] online Hackathon, this session is essential for understanding how to integrate NEAR’s chain abstraction features into your projects. Learn how to build multi-chain applications, use derived accounts, and work with Ethereum and Bitcoin using Chain Signatures.

Key Takeaways: • Chain Signatures allows developers to create and manage derived accounts on multiple blockchains using NEAR, providing flexibility for cross-chain applications. • Developers can use NEAR smart contracts to control transactions on other chains, making multi-chain apps more secure and decentralized. • Chain Signatures enables the deployment and management of smart contracts on Ethereum, Bitcoin, and other EVM-compatible chains through NEAR, eliminating the need for private keys. • By combining chain abstraction with user-friendly features like meta-transactions, developers can onboard users across multiple blockchains with minimal friction. • Proximity Labs is supporting innovative solutions through Redacted Hackathon bounties, encouraging developers to explore DeFi, Bitcoin integration, and other creative multi-chain use cases.

Timestamps 0:00 - Intro and welcome to DevHub Live 1:15 - Redacted Hackathon overview and bounties 2:21 - Matt Lockyer introduction and Chain Signatures overview 6:09 - Deep dive into Chain Signatures architecture 11:22 - Example: Deploying an NFT contract on Ethereum via NEAR 19:02 - Derived accounts and multi-chain protocols explained 25:00 - Generating keys and signatures for multi-chain accounts 36:50 - Advanced use cases and developer tooling for Chain Signatures 50:23 - Trade Signatures: Cross-chain transaction signing with Bitcoin, Ethereum, and NEAR 58:02 - Key ingredients for building with Chain Signatures 1:02:00 - Hackathon tips and signing off

Join NEAR's community: Website: near.org NEAR AI: near.ai Twitter:   / nearprotocol   Blog: near.org/blog Medium:   / nearprotocol   GitHub: github.com/near Dev Docs: docs.near.org #NEAR #nearprotocol #NEARAI

Transcript

10,393 words

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

  1. 0:00

    want what you want

  2. 1:15

    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 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

  3. 1:40

    uh if you haven't signed up already 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 try to

  4. 2:04

    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

  5. 2:25

    um um yeah it's really great to be here um coming in and out of focus but uh yeah um I have a lot to share about chain signatures um it's G 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 test net and the main net are just a little

  6. 2:53

    bit influx um but I have a video that I 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

  7. 3:27

    we do is uh we use chain signatures to 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

  8. 4:00

    different applications of chain signatures and kind of how to build these multi-chain protocols um 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

  9. 4:23

    times now is the concept of actually like using chain signatures on near not just kind of going hour 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 multiple windows here um first I just want to mention

  10. 5:00

    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 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

  11. 5:25

    so um showing some creative uses of near chain abstraction um and then here's the evaluation criteria but we can come back 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

  12. 5:57

    like Bitcoin um using chain signatures so you can you can build interesting protocols you can do lots with defi so just definitely something to check out awesome um so do just want to jump in um so basically I'm just going to 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

  13. 6:27

    just called the chain Sig script so it's under github.com near- examples chain dript um so basically just a general overview of of the vi of the the repo um and there is an accompanying Workshop video off to the side which I I can kind of jump into in a sec it's got some it's actually got some transactions running 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 to go through the source here you can see there's multiple different chains here

  14. 7:01

    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 implemented a while ago were like obviously ethereum Bitcoin Dogecoin um and even xrp so um because chain signatures just produces an ecdsa signature we were able to actually execute transactions on all those other

  15. 7:32

    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 signatures protocol a near basically allows um it allows you to just do a simple near um kind of function call to the chain signature contract and basically get back an ecdsa signature

  16. 8:04

    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 sha 256 or whether it's like a kak uh hash on ethereum all the transaction details get hashed down into to basically uh you know 32 bytes so how do you sign those 32 bytes well that's where the chain signatures uh Team came

  17. 8:38

    in and they basically created this protocol that allows us to use a multi-party 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 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

  18. 9:12

    by some private key and that priv 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 uh the addresses in there's a bit of kind of code and massaging to get to the address but basically the public key and the address are kind of like a onetoone uh there's a

  19. 9:37

    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 so for example if we wanted a public key for an ethereum account we would basically be calling the near chain signatures

  20. 10:07

    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 is just a string so um 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

  21. 10:41

    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 would get would cor would correspond to that dire account and if you took the the hash and the signature and you ran it through a typical what they call like a EC recover or ecdsa uh recovery from ass signed

  22. 11:13

    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 protocol does just want to keep it super simple for people who are hacking on this all the chain signature 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

  23. 11:43

    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 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

  24. 12:14

    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 CH signatures contract uh that's just kind of a requirement it's really easy to get that I've got the account ID of the near account I'm calling from so that was the account ID

  25. 12:38

    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 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 actually the public key as well so um basically was a long- winded way of saying um you know how do I get

  26. 13:08

    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

  27. 13:30

    that final 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 determinist way to generate these derived accounts so I want to just

  28. 14:02

    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

  29. 14:37

    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

  30. 15:06

    let's say you wanted to restrict a user to uh just the ethereum mainnet you might want to do you know ethereum uncore 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

  31. 15:40

    we go back uh 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 test net um Dogecoin 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

  32. 16:10

    generated from the public key but we're really just getting we're really just getting ecdsa key pairs at the end of 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 wherever um you know wherever a chain uses ecdsa and by by the way ed25519 signatures will also be coming to chain signatures uh soon so

  33. 16:40

    there'll be an actual ability to uh to not just specify your path but specify like your key version and then um you'll be able to generate uh ed25519 signatures for for chains you know like salana and other chains 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 would truly understand like how powerful this stuff is and like it's really not limiting

  34. 17:12

    especially as you know these 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 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

  35. 17:43

    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 need to basically use some sort sort of key derivation script which is the one that I showed earlier um is part of this chain Sig uh uh script repo you basically need that to generate these derived accounts offline and really when

  36. 18:12

    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 D like 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

  37. 18:44

    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 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

  38. 19:14

    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 getting signatures so just calling that sign method and basically uh let's just uh cruise down here to calling the NPC

  39. 19:37

    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 near account will call the NPC contract and then it'll return a signature for the derived account so there's really

  40. 20:07

    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 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 on a good track here cool yeah 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

  41. 20:38

    basically um kind of help simplify a lot of things like um if you just type yarn star and then just- EA for example you'll just get an ethereum address a little 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 environment variables I I included like an environment variable

  42. 21:03

    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 ethereum comma 2 for example I'd get a different derived account um you can just run yarn 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

  43. 21:31

    the reason why it's just like these basic commands is because I 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 prefunding 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

  44. 22:01

    send funds from there you could use uh this let's say 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 usually go to me thanks but it's all it's all test net but um but yeah that that's just simplified commands and stuff stuff um and this was just this this goes all the way back to me like in the very beginning kind of just creating some

  45. 22:34

    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 testing the chain signatures um the chain signatures functionality as well like just what can do can we can we

  46. 22:59

    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 a look at that at a later time but um yeah I just I want to go back to uh um I

  47. 23:29

    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 it's basically just the payload which I mentioned was 32 bytes uh the path

  48. 24:02

    variable which is a string so for example ethereum comma 1 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 proposed and sent back to you um one thing that I think

  49. 24:32

    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 that is a very interesting

  50. 25:01

    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 that was ever generated for this account so so um and that that is uh kind of uh

  51. 25:32

    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 the only way to call sign is from the near account with the right path variable for that derived account and

  52. 26:02

    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 if I lose so if I do have I forget my path variable for whatever reason I I lose it uh am I my locked out of that while that those funds are are lost yeah if you lose control over the near account you're calling from or your

  53. 26:32

    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 and it it's just it is a security thing like if you think about it like you don't want you don't want any like

  54. 26:58

    obviously you don't want any 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

  55. 27:25

    computation protocol so the chain signatures nodes themselves they also 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 none and that's the

  56. 27:58

    design of basically an MPC system is that you've got all these nodes and they 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 high level abstract like how does it all work kind of thing um I do want to get into this uh this stuff because this is a really this is the meat and

  57. 28:29

    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 that

  58. 29:02

    derived evm account we're going to deploy an nft contract to it now there's an NFD 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 this ethereum account is through a call to um to the near uh MPC or chain

  59. 29:33

    signatures 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 transaction that we you know that we

  60. 30:03

    composed and hashed when we when we passed 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 it nfts from that ethereum account into other evm accounts as well

  61. 30:32

    like we can say that the owner of the newly Vinted 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 an arbitrum it doesn't matter but the logic for Distributing

  62. 31:03

    these 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 will probably want to get into like the actual cross contract call and kind of take a look at that but y this is really

  63. 31:34

    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 contractor directly from a near account like in this example well you know a near like a a near account kind of uh or what they would call on on

  64. 32:05

    an ebm 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 that I've made um I actually require we we'll just skip down to step

  65. 32:30

    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 and its method but basically I've restricted this near Custom Contract and I'll walk through the logic of how I did that later in in just like two minutes um any near account that calls this Custom Contract and wants to Mint an nft

  66. 33:03

    on the evm account um to to any other evm address they I requir 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 to return that it's going to return that

  67. 33:29

    all the way through to this calling near account which will combine it with the derived 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 of to kind of roll up to the to the gate you know pay one near for entry to get

  68. 34:00

    that to get that evm nft minted right so and it doesn't have to be one near you know I mean the sky is the limit you could do whatever want 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

  69. 34:30

    people are creating um their sort of like their defi examples or their um you know their 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 Min in 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

  70. 35:03

    what we could 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

  71. 35:35

    it's like an ethereum account um and we 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 trans 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 call the NPC contract and mid the nft so you see how there's kind of like

  72. 36:13

    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 address that that my smart contract has control over and if you fund that

  73. 36:37

    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 aover on that other chain um or some Rel layers or something to set like set up to basically make sure that uh you know the transactions are going through the funding was uh definitely completed on the other chain before you

  74. 37:10

    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 tell the user send

  75. 37:38

    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 right like it's sort

  76. 38:10

    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 defi 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

  77. 38:35

    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 does it lead it to that path of having something like that where I can essentially 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

  78. 39:06

    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

  79. 39:45

    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 chain X to chain y kind of scenario and and and we were using chain signatures uh you know deposit into a derived account on chainx then we're going to credit you on some funds on chain y I mean like you can see right away where the sky's the limit now how do we pay for all those near

  80. 40:15

    transactions um to basically execute the signed 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 of um kind of an old older School method is like custom Rel layers 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

  81. 40:40

    hackathon so one of the things we talked about with with David and the other one about J abstraction was the concept 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 onboards somebody with pretty much zero friction

  82. 41:15

    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 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 U just so this is the contract that I mentioned is doing the cross contract

  83. 41:48

    call to the chain signatures contract um right away you can see that there's a sign request and again why are we 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

  84. 42:19

    signatures contract so we're not just going to let anyone uh basically get a signature to Mint an nft uh on on an 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

  85. 42:45

    I want to go through this sign method so this is a custom sign method uh specific to this protocol um and basically it 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

  86. 43:20

    uh the near account that is calling the sign method is using one of the public rlp encoded methods now I I know 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 nft 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

  87. 43:53

    the rlp payload is that the rlp payLo includes uh that mint call so so now I know that this is a public it's a public 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

  88. 44:24

    mint method of the evm contract okay so now 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 mpz contract with now the last thing to check and actually we probably should have done it before we spent gas hashing this so these are kind of reversed uh

  89. 44:57

    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 token in order to continue on and to

  90. 45:21

    basically call the NPC contract so again it's 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 Tes now right or it's pay one near Tesla 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 would put it in uh you know and and really what you're going to

  91. 45:53

    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 evm transaction and eventually uh hash it so that a signature could be created um this is a

  92. 46:26

    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 h basically it's trading one signature for another um and now why would we want to do this well Joe you you you brought up usability and you

  93. 46:58

    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 that executed um by you know by Chain signatures uh and basically we're gonna we're g to have

  94. 47:33

    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 um I'll just jump into it um so 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

  95. 48:04

    a public key for Bitcoin or an address for an evm chain um you 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 evm and near 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

  96. 48:38

    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 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

  97. 49:10

    would uh right now the source Chain's only Bitcoin and evm um but I'll be add 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 right so basically we should be able to recover this owner variable uh in Bitcoin it's going to be a public key from the message in the signature in in the ethereum case is going to be the address but same thing you know public key to address is is deterministic so

  98. 49:43

    what we're gonna do is we're going to require that the owner is a Bitcoin owner or an evm owner uh 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 turn we're going to we're going to turn in or we're going to return basically a uh 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

  99. 50:17

    require method so the recovered PK uh from all of this uh you know signed Bitcoin message parsing and stuff that's going to eventually you know basically recover the the private sorry the public key and then we're 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

  100. 50:50

    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 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 object for us and then we

  101. 51:22

    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 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 DSA get Sig and that's right here

  102. 51:54

    um and just like the previous example uh 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 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 Sig script uh repo and

  103. 52:26

    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 contract verify that signature and then we can take that unsigned transaction and we can encode it hash it and then call the NPC contract and get a

  104. 52:59

    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 set end 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 chains 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

  105. 53:31

    repo is 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 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 sync examples so you're going to want to basically kind of come in here and for example like you're GNA

  106. 54:05

    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 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 and then you need to call the mpz contract so um typically where if you're building

  107. 54:36

    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 number one is how do you derive your accounts right like how do you how do you create these accounts that the user is going to use and I mentioned that before it's in kdf TS so uh basically there's a helper function here uh down at the bottom it's called generate address um and you can see calls to generate address and how to create those

  108. 55:08

    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 from a near the calling near account ID whether that is a external account like just a near client or whether it's an actual near smart contract it's the caller to the NPC contract plus the path the second uh thing to master is calling the sign method right and how to create the different uh the

  109. 55:41

    different payloads and different transactions that you're going to want to construct to call the um the sign 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

  110. 56:13

    like deploying contracts U the base transaction here deploys the contract the data is here and the bytes um calling contracts so making a contract call to an evm chain so it's all here in ethereum.org can see just down at the bottom here's how we call uh basically an external account and we we basically call from one smart contract to another we call the chain signatures contract and with those three ingredients um

  111. 57:10

    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 that's all you need to know awesome yeah 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 is a telegram group that is specifically geared towards chain abstraction that people can jump into

  112. 57:41

    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 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

  113. 58:14

    out yeah um I do want to mention the proximity bounties once more um hacking on uh defi Bitcoin using chain abstraction so combining uh near with the at least one other blockchain um and always looking for Innovative use cases so we 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

  114. 58:45

    smart contract um you know credit some synthetic token or something if you 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 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

  115. 59:16

    the logic is still there like we're we're still signing we're signing unsigned transaction payloads for for evm for example with a bit coin wallet and then we're basically uh we're basically parsing that and figuring out that the 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 a cross

  116. 59:46

    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 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

  117. 1:00:11

    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 Matt I really appreciate your time uh yeah apologies for no live examples um okay like I I know I know the chain signators team is really they're working very very hard on uptime right now and it like they've just been working uh tirelessly on it and I know that uh I

  118. 1:00:37

    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 think the chain signatur 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

  119. 1:01:08

    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 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

  120. 1:01:32

    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 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 the different support channels ask questions uh near devhub

  121. 1:01:55

    and proxy is here to help uh support you in in your building well thank you Matt um again I really appreciate your time and we look 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 man take care all right uh that was great again if you haven't signed up for the hackathon already uh definitely go

  122. 1:02:19

    check it out there are hundreds of thousands of prizes at this point there are tons of different bounties there's something for everybody uh so it's a great opportunity to kind of just 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

  123. 1:02:42

    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 be back with another a redacted Workshop this time with Aurora it's building on top of an evm here on near so there's a lot of great stuff still happening so we will see you tomorrow at 4M UTC for the next Workshop until then take care