Skip to content
by Unity Nodes
NEAR DevHub

Walkthrough of signing Ethereum transactions from NEAR

about 1:09:06 long

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

About this video

In this walkthrough we look at how to use NEAR's chain signatures technology to sign transactions on Ethereum from a NEAR account

Docs: docs.near.org Repo: https://github.com/near-examples/near... Developer support: t.me/neardev

Transcript

8,756 words

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

  1. 0:02

    hello how's it going so today we I'm joined by U FD and we're just going to be going over a bit about chain signatures on the lead up to redacted and he's looking to build something with chain signatures and he's a a bit of a novice to chain signatures uh he says he knows like a higher level understanding but hasn't got into the code um yet do you want to introduce yourself and and talk about what you're what you're planning to build in redacted and what your like understanding of chain

  2. 0:41

    signatures and chain abstraction is so far yeah hi uh I'm after um yeah so what we are where I'm coming from I'm a long time NE ecosystem member and I've started to build like I guess a year ago and I'm quite fluid in reading and smart contracts and rusto near and uh due to uh me um having a limited uh experience in um developing I uh have a tough time uh getting into uh new areas myself that's why I'm thankful for uh getting some help with chain signatures diving into

  3. 1:24

    them and we would like to create something that is like order book cross chain uh uh where people could basically swap tokens uh regardless of the chain there on for example near for E without any bridging just one person creating an order and the other person sending the counterpart and receiving what was deposited and then yeah that's that's the end goal that's what I would find pretty exciting about chain signatures being able to create uh a centralized

  4. 1:59

    exchange experience but without any funds being locked up in some uh yeah some place that you have no control over yeah I think this use case is like one of the most maybe not common but the thing that comes to you first when thinking about chain signatures and it's whilst it's something you might think of quite early it's a really cool use case and hopefully we can learn how you can do that today so I'm just going to share

  5. 2:38

    my let's see I'll share my entire screen and let's see how we go maybe we'll get the the infinite mirror ah there we go and then I will think I should still be sharing my screen now yeah so we'll go ahead and dive into this repo can you see my screen yes awesome and we'll go into near dos as well so this is just the basic near multi-chain example um that is a basis for a lot of what people will be doing with chain signatures and we'll come over here to the the documentation and

  6. 3:25

    if you go into um chain abstraction servic and chain signatures because chain signatures is one of the products that allows us to implement chain abstraction basically um and what's what's your understanding of how chain signatures is working at the moment yeah so on High level it's uh for me very superficially a near account controls accounts and other chains that can be derived through derivation path so some combination of letters and

  7. 4:04

    numbers and that uh always create the same public address and then um you can sign arbitrary messages through uh an MPC contract that or multiple MPC contracts where the private key is split between all of them and they together create the signature for this arbitrary message um but I don't know how exactly that works um but that's my understanding of the overview basically yeah it's a pretty good understanding I I would say that that's mostly like all the understanding you

  8. 4:45

    need to know about chin signatures to go ahead and Implement something like you're wanting to I think to go a bit into more about how the MPC contract Works uh like you said instead of having a private key to sign something the private key is sort of sharded between multiple nodes multiple MPC nodes and then these come together to sign the message that you want to sign um and this uh and it works through like

  9. 5:20

    threshold cryptography threshold signatur so you have like n of M nodes to sign this transaction so you'll have like five out of 10 nodes or whatever that need to sign it for it to be successful uh and I have just a question in terms of how do we uh decide or where is the chain that we want red Dr with um defined because especially on ethereum you have a lot of layer choose and this is ethereum as well so I was a bit confused of how through the derivation

  10. 5:56

    path it determines what chain we are on or is the derivation part just doesn't doesn't it need to be ethereum one ethereum 2 could it be an arbitrary uh um combination of letters and numbers uh it's just uh standardization so that every first ethereum uh account of a certain new account is qu ethereum one to have uh the wallets for example always talk to the same wallets at first yeah good question so the public key and then just the address

  11. 6:34

    of the um account you're going to be sending transactions from uh on like ethereum or Bitcoin or or some Layer Two will be um first it will be based upon the public key of the NPC contract NPC Service Plus what account you were calling it from so if py vortex. n or py vortex. testet calls it then it's going to be different than um uh like I spice. n or ip. testet my my other account calling it so it separates the addresses from one person to another like you were saying before

  12. 7:22

    and then you have the option to add in some metadata um or an an additional like derivation path and that can either be nothing like an empty string or anything you want it to be for example you can see we have ethereum one or ethereum 2 here um and at the moment there's a lot of wallets building in the space and they're coming up and we're all trying to decide on how these derivation paths

  13. 7:56

    should be structured so for example if you have a multi-chain wallet then you want to clearly Define which account um you're actually going to be using so you don't have to store these derivation paths on chain so everyone could say we're all for for our main ethereum count we're all going to be using ethereum one and then we're all going to be using um arbitrum one or whatever but right

  14. 8:28

    now there's not set standards um I believe these are coming so you can just really use whatever derivation path you want okay cool yeah I just remember using a Bitcoin wallet and there's the option create new wallet in the private key that you have input and I did this with two different wallets and uh creating a new wallet wasn't creating the same address and therefore I wasn't

  15. 8:53

    able to access my second wallet on the other uh wallet if you understand the issue so yes I'm looking forward to for the wallets having the same standardization process there right yeah I um so we'll we'll look at a implementing chain signatures now so this is in the documentation in it talks about the steps to sign a transaction and and send it to the network so the first one is you need to derive the address of the account that you're going

  16. 9:28

    to be using um on say ethereum we'll we'll probably just use the example of ethereum today uh then next is creating the transaction that you want to be signed and this can either be done in your front end uh which we'll look at uh in today or you could create the transaction in a near spart contract so you can only perform certain actions right um then when requesting the signature this is when you get the contract to actually sign the

  17. 10:07

    transaction um and have the the service sign the transaction and uh you you just basically send this transaction send the transaction payload to the the contract then reconstructing the signature basically once you've got the signature from the contract you get it back in your front end or uh and then in step five you broadcast that to um the target chain because when you when you're signing the transaction it doesn't necessarily mean it's being sent because

  18. 10:46

    signing and sending is um a different process you could technically sign a transaction and not send it and then uh send it like a later point um which is a bit of a a security issue and you need to like index what transactions are being sent but that's a bit later down the line so yeah we'll we'll dive into this example here um it split up into the different sections but it leads to this near multi-chain Library which you can just

  19. 11:24

    see in N examples so let's go ahead and clone this does this support layer tws already or is everything at the moment just for ethereum main that and Bitcoin so because chain signatures is basically like chain agnostic semi so you don't need to like integrate a new um a new chain as long as it using the same Keys uh like the same public key types which is ecdsa then it will be

  20. 12:05

    automatically um accepted and we Define the destination chain then the example yeah but yeah this example is just ethereum and Bitcoin so you'll need to change some things if you want to uh interact with like arbitrum or some other chain that uses like ecdsa so I'm I'm using WSL here get clone this example let's enter it oh bad spelling I need my glasses on install everything let's let's enter it first so there's been

  21. 13:00

    I don't know what's happened there oh I think it's because I got halfway through installing everything but yeah there's the signing service the signing contract specified in this example has had some congestion issues recently so we'll actually swap to a different one and this will be good to show you how you can swap anyway uh MPC contract near and this should come up here we go so this is the repo of the

  22. 13:38

    contract that you actually use to sign things you don't need to really look into this too much but it's useful to understand how it works um and we'll get into this later and this is like the interface of how to interact with it uh and here's some examples and this is the example Le in the contract but we'll SW swap over to this one let's enter in okay so let's let's take a look at this repo how is it structured we just have a

  23. 14:19

    basic I think this is nextjs or something project um so we have our package and our source fold what we're going to care about right and we have some pages we have our app we have our CSS whatever um we have some Global context which will just have like a wallet and sign account ID this is pretty standard for a near project you go into another example like the guest book and it's basically set up the same uh but what we really care about here is the um so we have like

  24. 14:59

    more front end stuff for ethereum and Bitcoin and the navigation bar but what we really care about is this services and we'll look at ethereum um this is basically you'll use all these functions to perform everything you need to like those five steps and these are split up into different functions so we'll look at deriving an address so we see here that we have this function derive address it takes the account ID your n account ID and some

  25. 15:42

    derivation path and from there it will figure out your the public key and then the address of the account you're going to sign the transaction for so we'll look at that fun in the code and like I said I wanted to swap to a different signing service um and you'll see here we have public key and we await some function call which takes our account ID and derivation path and then this big long complicated function which is defined in this kdf

  26. 16:24

    file um and this has um a public key of the MPC contract defined in it and from there we get we use this to get the public key we want um but we have the where are we I think it's in app yeah this is where the NPC contract is defined so we'll swap that out for Dev feel free to jump in with any questions if you have and then we're going have to foll you on my uh on my computer but I think I I got it so there um the MPC

  27. 17:11

    contract is one contract but it calls other contracts that have part of the private key stored or can derive part of the private keys not other contracts it's like an offchain service okay uh but yeah we need to change this root public key because we're changing uh the MPC contract so we'll have to figure out what it is uh we can do that by going to near blocks test net and let's insert our

  28. 17:54

    contract go to contract contract method so what is this going to give public key this looks like a function that will give it um so I'm going to see what the public key is near contract call function it should be a view function this account and uh public key function was called you shouldn't need to do this um if you don't need to swap NPC contract and it should have empty arguments test net aha

  29. 18:38

    here we have the public key of the NPC contract let's go ahead and change that so now we'll be able to interact properly with the other one um so the address was B1 sign minus death test instead of minus test yeah yeah this is like the latest version but um at the moment the production one's being a bit slow so you can swap over to this one if it's having any issues um and you could even have it in your code that says hey let's try get a signature from here if it doesn't work

  30. 19:20

    let's swap to this other sign in service um so yeah this this spit is pretty simple it just takes the public key of the uh NPC contract the NPC service and uh derives a public key uh for you and this is going to be like ether well this will be um um just like a a public key I think it's yeah it's this key type uh and then you can change this key type basically uh if you if you were going to use like a a chain with a different key um and then once we've got the

  31. 20:07

    public key we get the address from that which is specific to ethereum um so if we look in here yeah it has some ethereum specifics and then there's a different function for Bitcoin because if we look in this Bitcoin file it uses this UNC press hex point to BTC address instead of eth address but basically you don't need to understand how these things are working just copy it and Fork it like I would strongly suggest that

  32. 20:45

    you just fought this repo as your starting point so we had the we know how did they derive the address now any questions about that no good cool uh so let's see what the next step was so we've derived the foreign address rating the transaction okay so let's go back to our code in this example we can create an transaction to just send uh ethereum from one person to another or we can create a transaction to call some

  33. 21:32

    contract on ethereum and this is the function to do so uh I think it's is it called create payload or create trans yeah create payload so a payload is more of like a compressed version of a transaction and this is what the NPC contract requires it doesn't require the whole transaction um so this is how we're constructing a transaction for ethereum we have our nons which is basically like

  34. 22:11

    which number transaction is it so we don't like repeat the same transaction uh we have our gas limit of how much gas we are willing to spend on this transaction Max fee per gas I think this is like like how much we are willing to spend per gas I don't know too much about ethereum um and something similar here if you want it to be a priority transaction and we just get this nons from uh some ethereum

  35. 22:51

    utility uh this is like ethereum specific so you'd have a different one for Bitcoin or some other chain and we just get this from quering gas price on ethereum as well um then two who are we sending this transaction to we just we're just going to input that so this can be a person or a contract data data will be what's like actions are we performing so we'll go into that a bit later so you can have just empty data if you want to just send a

  36. 23:30

    transaction value how much ethereum are we sending we're going to enter that and chain um like what specific ethereum chain are we sending to and I think this is where is chain ID let have a look uh it's defined in here so we're send they get to sepolia which has this chain ID um okay so let's that is basically how we're creating the how did you how did you get from uh this train ID to the actual chain ID number in the other file what was that sorry how how did you

  37. 24:25

    figure out the chain ID that was hardcoded so I believe you can just search that up like seia I was wondering um what the path was uh for you to figure out the hard to get to the hardcoded uh chain ID like this one no um you you saw chain this the chain ID and I wanted to figure out how you got where this value oh how I found out where it was yeah yeah because I when I click on it uh with control then I only get to export class ethereum uh and then there's a Constructor and I

  38. 25:08

    don't get to the other ethereum Cloud so I can find this the next time I see it in another file yeah for sure so I just saw uh it was part of the class right and then yeah it's part of the Constructor so when you're creating the class that will be specifi uh when you're creating the object of the class that'll be specified and I just knew from interacting with this library that that was created in the ethereum component okay okay so this is this is

  39. 25:40

    where we're creating it um the eth object which will do like eth dot uh create payload um in our component and we specify the RPC and the chain ID we we'll look a bit more at the if we change if we change the uh the chain ID we also have to change the RPC I suppose because it's a different chain then yes I would believe so um so yeah there's different rpcs here so if we go to like ethereum main chain ID

  40. 26:28

    chain list this is a useful website maybe it has it here oh yeah so we can get the rpcs for ethereum main night if that's what you're doing oh it's this website seemed to to broke my Google give it a minute any questions fores there we go um just on the website so I can interchange it as well yeah so back to creating the transaction so we specify the transaction data which is made up of all of this and then we get the transaction

  41. 27:18

    by just using this this function which is some external function in another Library um but again you don't need to know uh too much about how the iners of these functions are working unless you're going to change a lot you can just sort of use create payload um and then we get the payload from the transaction there's a thing here where we're storing the transaction because basically to pull the transaction back

  42. 27:57

    together the end we need to have one the transaction and two the the signed transaction hash and then we'll merge them together which we can actually broadcast to the network um so this create payload is outputting the transaction and the payload and we can you could see that we're storing it here but we're also returning it this is because if you're using a web wallet then it's going to have like a redirect and you'll need to save it in

  43. 28:37

    storage because any information you had uh just in the browser will be lost unless it's saved in like session or or local storage yeah good okay so now we've created the TR the payload and the transaction we can request the signature this is the function you call which takes the wallet the contract that we're calling which was can you remember what it was called uh this one V1 sign do dd.

  44. 29:19

    testet um and the payload what we're actually going to send so we call this method from uh by using the wallet and that's just specified in this wallet FAL you can learn more about that if you want it basically is just doing a call method and and sending it um broadcasting it via RPC to the near chain yeah I've done that before in other front ends that are not trans yeah nice so yeah we're calling this contract

  45. 30:02

    we're specifying the method the method is just called sign and the arguments we saw this earlier uh where was it over here so the sign method just takes a request and this request is um an object which has the payload the path and path is uh where we were talking about before like it could be nothing it could be ethereum one ethereum 2 whatever you want it to be and then key version which is just like if the contract changes

  46. 30:46

    then they can update the key version and at the moment it's just set to zero as we'll see uh yeah so we put payload the path zero version it therefore checks that the signer of this uh transaction is the same one that is associated with the derivation po so I wouldn't be able to sign a transaction that is from the derivation path of another account so this path is different to

  47. 31:20

    that path this is like a smaller path the larger path comes from your account ID and this path and so basically the MPC contract will look at the predecessor account ID like who sent this to the MPC service and their their D derivation path will be based on your account ID so it's handled in the MPC contract if that makes sense yeah makes sense so we just attached some gas and we attach a

  48. 31:57

    deposit it here we're attaching .05 n but this deposit will change based upon the uh like how congested the MPC service is so it goes from like one yo n which is the smallest amount of n it's basically nothing but it just needs that amount of near to uh have the wallet pop up because you're doing something like that transaction that where you have to um clearly accept and and sign the

  49. 32:36

    transaction and then it can go up to something like I think it's .7 near no 65 near I think it is which is quite expensive but it's unlikely to get that high and whatever deposit you attach if it's not using that amount of deposit you'll get it sent back and again if the signature fails for whatever reason you'll get the amount of deposit sent back so I could attach like one n if I wanted and get everything back but we're just attaching a small amount of

  50. 33:15

    n um and then this will give us Big R S and Recovery ID I'm not particularly too sure about the details of this it's just like the signature is split up into two parts um and once we've requested the signature and got this information back we reconstruct it because this isn't giving us the signature straight away we have to um get the signature from here so we're adding the uh the

  51. 33:54

    signature to the transaction that we got earlier with this uh r s and and V values and you don't need to know again you don't need to know the details of this too much and then we just have some uh some code to check that the signature is is proper and like I said earlier there's this reconstruct signature from local storage um just in case we're using a web wallet because we won't actually get

  52. 34:27

    this information back we will have to fetch it from the RPC and then finally once we have this signature with the this the signature being added to the transaction it should really be called maybe sign transaction instead uh yeah well it's called sign transaction here so uh we uh we serialize it and then we use the RPC to just send that transaction to the to the blockchain we want to send it to and then we'll

  53. 35:10

    uh we'll probably fetch some receipt for that wherever uh I think that's done somewhere so basically that's the inner workings of the methods we're going to be calling so we can look at the component a little bit here but it's it's quite simple we're just basically we're basically just like driving an address based upon the account we're logged in with and the derivation path we're putting in once that's set when you click a button then we'll request the signature once we've

  54. 35:49

    got the signature we will um say the signature is ready uh look sign payload ready need to be relayed to the ethereum network uh so once we have that signature it'll say relay signature and at that point we well relay the transaction and if it's successful we'll get successful with the uh what you call this like a ether scan link so we can check the details and check everything was all right uh any more questions or we can

  55. 36:27

    actually look what the front end looks like oh I'm good uh let's get into the front end let's go hopefully everything will work so we'll just do yarn Dev remember we did yarn install before let's take a look okay so I'll need to log in with my account oh do I have ah I'm on a different thing here I'm on a different browser so I have to open up this one uh quickly create one in the console I don't want to add my my account to the devhub one someone someone else might

  56. 37:25

    steal my test net tokens oh that's what I mean you could just create uh yeah yeah create an account quickly yeah so I I already have my accounts and I have some funds on that so I can just quickly do things uh so yeah you just come in here log in with a wallet or create a wallet I have a few accounts so I just sign in basically you can this without a wallet this is specified to handle signatures from other uh chains because you only need to

  57. 38:06

    sign transaction on transactions on near the only issue is with uh wallets that don't have a standardized way of displaying the paths is that you don't know your balance right because you can't look it up because there's no interface because there AR they on a world supporting these on mainnet yet yeah so at the moment when like if we went to our wallet we wouldn't be able to see how much ethereum I have on this account we could create one of them as a hackathon project because why not

  58. 38:46

    um that would be cool but we can see that when we come into here it shows how much eth I have based upon my account and my my derivation path and what chain I'm on so if I swap I can swap to bitcoin but that is that is then yeah yeah this is spolia so if I change this derivation path to something random then I have no balance on that yeah I just try to get myself some not you have a link for me well I'll go ahead and do something now

  59. 39:26

    I I have it in my brows already I think this Google one is quite good I'll send that over to you cheers uh spolia This Not That so when I put in the path you'll see that the address will change based upon that path and the same would happen if I was change wallet so I'll copy this path and uh uh put it in there and I'll get some spolia but what you want to might want to do is instead of sending the aolia to

  60. 40:07

    just one address that is connected to a n account for testing you might want to um like send it to a metamask so you can send more refined amounts to each account if you're testing because uh say you were to forget what derivation path it was uh then it wouldn't be too good because these things are like rate limited so if I refresh this then I should see that there's balance yeah I've got .05 e but I'm going to use this

  61. 40:43

    one I had before ethereum one if you got a spolia address I can send you eth to FD oh sorry I was muted uh I was just requesting soia or I'll send I'll just send it I have 0.05 with I have that's how it went through my near derived ethereum One account actually has now some that's already exciting what is your what is your address I'll send do a bit more through through like there we go so I'm

  62. 41:33

    just trying to get suia working on my metam mask because I don't know how to ah here we go yeah I have mine setup on here because I'm I'm so scared that I'm actually going to swap to main net and just send all my fun so I have it in a different browser uh but yeah it should be able to request a signature to your address and it will make my wallet pop up enter in my password can see how much n I'm depositing but if I'm using less n than this remember I'll get the deposit

  63. 42:14

    back send that take a while to get the signature we'll see will it go through hopefully fingers crossed whil we're waiting oh there we go so we've had we've got the signature from the MPC service and now we will try and relay it to the chain so we're relating to ethereum network it might take a while it's good to know because it's taking a bit of a while okay so uh what is not possible

  64. 42:55

    yet is to have both of these steps in one or is it just for being able to are these five steps okay now we can request the signature it's all just being done one by one to Showcase this and we could also do it automatically but it would just be under the hood yeah you could have a button where it's just like send funds um and you would just say like await signature and then relay it but in this example it's two separate steps just for the aid

  65. 43:34

    of learning I suppose yes yeah makes all sense it's cool now so this this worked right so I can see that I got a link and it shows that I had .05 eth sent to your address and you should see that your your balance went up a little bit more uh and what else so that was just a transfer we can also call a counter which is just some contract on on sapoia ethereum and we can just add in some

  66. 44:13

    data here and request sent uh ethereum to my metamask call it as well that's Co that's pretty pretty neat awesome but super cool I didn't uh I didn't even know that it would be able to create these transactions this easily if you just clone the repository and you just install it even without Dev knowledge you can just try it out I wasn't aware thing uh and you could just do it on

  67. 44:48

    Main net if you just put in the addresses and change I would maybe not recommend that I to start with I would practice with test net to start with and then go over to main net if you're if you're brave oh yeah no first I will try to create something like a near test net and suppo ethereum token swap but it looks very easy so um not very easy but it looks manageable more manageable than before this call uh it's really hard for me to always just stare

  68. 45:28

    at code and I mean it's explained everywhere pretty well I wouldn't even thought the near documentation but um it's just the way I learned to just talk through once and be able to ask a couple of questions just makes it a bit more um I don't know it's easier for my brain to process yes starting is always the most difficult thing so now I see have a very odd balance so I started

  69. 46:00

    with 0.05 and you send I have done a transaction and I got sent something and now I have like Z 0.05 3719 yeah mine is mine is very long you could round that I'm sure oh no I'm I'm just wondering so this case it wasn't doing um it was taking the transaction fees from the actual eth balance and it wasn't using using near funds right because we haven't this is not part of this contract to have a what what was

  70. 46:35

    the name for that um that a specific name as well using using non-native eth funds to pay for your transaction fee yeah so all the transactions at the moment in in this example is being used with G like the native gas token um which may not be a good onboarding experience for example if we were wanting to call this counter where we're not actually attaching any funds we would still have to deposit funds to process that transaction um but you can

  71. 47:13

    use a thing called a gas relayer which basically uses an oracle to see what is the near price and what is the price of the gas token like ethereum um and you just pay a certain amount of near or NE 141 token like native usdc on there and it will swap that for you and then like send it to your account so you can sign transactions uh without needing to hold gas on the the target chain so

  72. 47:54

    um the only thing that I was would be worrying about is just how do I figure out how large the fees are going to be because I am not confirming anything on the ethereum side and there's just less balance after that so if e has just a very popular nft Mint or something and the gas price is really high then it's just confirming it without it needing to be confirmed by the user yeah I think what you would do in that case is like query what the gas price is maybe add a little bit more and then you

  73. 48:38

    would input that into the gas station of like how much gas do I need and how much tokens do I need so you just uh the only shot you have right now is to display it on the front end because the wallets are not handling it yet uh yeah there is no implementation of wallets that I'm aware of yeah I mean if anyone's listening feel free to do that for your hackathon project yeah I mean let's go wallets um so I've just tried calling

  74. 49:18

    counter and this didn't work for me so maybe you can have a try sometimes sometimes you have to wait like a certain amount of time for your eth balance to arrive for you to be able to sign the transaction just because it's like a waiting confirmations I think um that's why I didn't use the uh account where I just received funds on to sign uh I used the account where I had funds on before just to get around that

  75. 49:56

    just just saying not every uh chain has a confirmation time of one second we have spoils here on near uh that part worked uh just like for you and then well the signature work we'll see if the relay works it's taking its time so it probably means it works let's have a look yeah when it fa for meia was quicker yeah it's probably way why is it saying uh amount ethereum units because we're not transacting anything is this for the gas

  76. 50:42

    fee uh oh this is because the because I was using a web wallet it's just swapped back over because the page of refreshed um you as suppose we need to implement it so it checks what transaction was everything on the above relay transaction is basically um for the next transaction it has nothing to do with our relay transaction okay yeah yeah uh because if we go into here then yeah

  77. 51:14

    makes sense it's the same but you could well yeah your current number is 1,5 so it apparently worked yeah for some reason I'm not getting the successful response but it changed the number so yeah I guess it I guess it did work uh I if I look into the Explorer I'm sure it'll say we we'll have a look at how that data bit is done because like I said earlier that where are we there's this extra data value you can put in the transaction and for the

  78. 51:53

    transfer example it's for uh message for the council yeah I changed it to, one yeah has it changed on mind ah yeah oh I finally got the transaction successful yeah I can see you sent it um so this data bit let's have a look where this comes from data create transaction data so that set up a new contract receiver ABI so okay where um where did you go now what's what's your goal right

  79. 52:41

    now I'm trying to look at how this data is constructed um this data argument so we can see how to send like custom transaction instead of just transferring ethereum and calling functions on contracts and stuff yeah yeah yeah so that is probably then just you can just uh some ethereum research basically yeah it'll be ethereum uh specific so it looks like we're creating a new uh contract object

  80. 53:19

    which is imported from The Ether library and it takes the rece ver so what is the contract uh address and the ABI for that and the ABI is just like what's the interface of the contract and then once we have that contract object we just do like encode the data so what method are we doing using from the uh the ABI and what arguments are we passing so the one thing we need to look

  81. 53:57

    at is where the ABI is coming from and we have the same thing for a view function which shows us what the contract is so where that's funny uh the so the yeah I mean it's in hexad decim I don't know if probably it the method has a real name I'm just in the ether scan and the method ID is just hexadecimal but I guess it's just hexadecimal convert from letters or something what you mean Sor I was

  82. 54:33

    looking up the uh change number function call on this ether scan and it's showing me uh method ID in heximal so just put it in in the chat the method ID is like 06 0x6 ZF y y y yeah maybe you need to convert that it probably is just change number in hexo decimal or something yeah yeah I'm I'm not too familiar with ethereum to be honest when you knock on N blocks it just tells you like what the name is

  83. 55:12

    right yeah uh yeah so we're defining this ABI in this component it seems uh and that has yeah it should be the hexad decimal for set so we have sets get n which are just some functions and we have the contract name in there and then we'll do this uh view function and there should be the the create transaction data so it's it seems pretty simple to create a a new like custom transaction and I suppose

  84. 55:53

    you're just you'll just need to change what the ABI is and you can use this same uh method so you should be able to just Fork this example um easy enough that's pretty much it from that example do you want to do you have any questions or yeah I mean we can uh call the quits in a moment I just had in my mind for the swapping example M we don't need to do anything extra then so uh we if somebody wants to create an

  85. 56:35

    order and wants to exchange ethereum to near they just call whatever contract I am creating and this contract is basically supposed to go through these the front end is going through the different steps and then is just making a function call to the MPC contract and also to my contract well I think with this example of swapping you're going to need more logic than this because say me and you were swapping ethereum for near or whatever then I could decide to send

  86. 57:21

    like one transaction without sending the another and like how we we basically we don't want to be with swapping we don't actually want to be sending any ethereum because to send ethereum that costs um gas on near uh it costs gas on ethereum and it has ethereum finality instead we want to move the transaction and the logic and the swapping onto ethereum so basically think less about sending on the native chain and think more about swapping access to

  87. 58:09

    accounts so if you were to if you were to say swap ethereum for near what you would do is send money into this ethereum account and then once it's in this account when I want to give this ethereum to you I instead say that this derived account is no longer owned by me is now owned by you and you can do whatever you want with that account um but if I derive the same account name from my near account it will still come out

  88. 58:55

    as the same account name just I don't have the access to it anymore right so yeah this is where we have to implement like a a proxy contract so instead of just calling the MPC directly we call a contract to call the MPC and the derivation comes from the predecessor account ID so it's coming from what contract or what account is calling the MPC which will be this like orderbook

  89. 59:29

    contract it won't be your specific account and the orderbook contract just says like who has access to this account but in reality the contract has access to all the accounts it just then divies up who has access to which specific account and if you remove the keys to the contract then well no one really have like the contract doesn't really have access to it it's dependent on the contract's logic if that makes

  90. 1:00:03

    sense yeah I'll have to think it through maybe we can text a bit about it uh moving forward because protocol your protocol get let's do get hell yeah um so yeah what I um really have to look into our access keys and how to utilize them because I think uh I don't fully understand them yet and they are probably great tools uh after everything I've heard in the past by most of more experienced

  91. 1:00:33

    developers and also I would have just thought yeah for every order that you want to create you just have to pay two transaction transaction fees twice which is obviously not really cool uh not really how it's supposed to be what I have just thought yeah that's why we use the like if you want good U Works you'd use gas station what I what I thought what you do what you could do as well is you um kind of

  92. 1:01:03

    broadcast the uh unsigned transaction and the contract maybe stores the sign transaction and the moment somebody accepts the transactions uh it just fills it with the uh with the person that has accepted the order um and it's address and then the transaction is being signed but that doesn't make sense because uh sign the the message CH changes so do the signature and therefore you can't do it this way yeah and the thing with like signing

  93. 1:01:42

    is the yeah yeah you could decide to store the transaction in the contract if you wanted but there's a partial aspect of it so if somebody wants to swap one ethereum for a thousand year um if somebody says Okay I accept 10% of this order uh you don't know in the end how how many parts the order is going to be split so you don't know how many transactions you have to broadcast beforehand so this doesn't really work

  94. 1:02:15

    so there has to be a more uh yeah I mean this this will take some thinking but maybe you'll just have to let the person that takes the order or part of the order pay for the transaction fee and then you must have two transactions one is paid by the order Creator and the other one is the receiver that has to pay the final transaction to their account maybe there's no way around it how I would probably do this like order book is you

  95. 1:02:46

    have you have um like a near contract and you create an order in that near contract and when you create the order it says like how much ethereum I want depositing in there and from that action it like spins up A New Path uh like a random path or it could be a path dependent on like inside the contract and it creates a an ethereum address and that eum address will be where you deposit in for that order um and you could do it so

  96. 1:03:30

    like you could confirm that this is happening in the front end but this would probably only work for um full orders so if you like send the full amount then you can say hey we're both happy that this has been filled so we're going to make the make the swap um like we're going to change who access to these two accounts um or how you could do it which would be better but more complex is you use like

  97. 1:04:04

    something like a li client to confirm like which ethereum address has deposited how much and then like actually take that from ethereum on that logic on ethereum into uh into near I think that would work I just dabble around with uh what you've shown me today and then uh I'll have to figure out a solution for the problem at hand and how to implement it because there is certainly also limitations and

  98. 1:04:37

    not only what makes sense logically but also what I'm able to implement uh from scratch right now so you got like if you're doing this hackathon you have quite a while though so I think you can bit done yeah we we will see uh I mean at least at least for think like if if there wasn't a partial fill like the single fill version of all of this sounds pretty easily implementable because you can just change the access keys to whoever fills the order but what

  99. 1:05:09

    makes it a bit dicey is the partial fill and the transaction fees yeah because you just the the person who's taking the order is supposed to pay the transaction fees we could deduct it from the amount that is uh in the order but we have to make sure that the amount that somebody has uh exchanged is above the actual transaction fee itself so that actually you can pay the transaction fee at all and uh yeah it's there are different

  100. 1:05:40

    ways of implementing this but uh yeah for now um I think I have a good starting point of moving forward and actually understanding how uh we can create payload and how it works and how I can call function Ops um I think it'll be useful to quickly walk through this example okay yeah go ahead and this this example is basically what I was talking about like a proxy contract which allows you to

  101. 1:06:11

    swap access to contract uh access to foreign accounts um so I can swap like ethereum for for Bitcoin um and basically this contract is working through nft standards so to swap an account you swap it the same as you would swap an nft um and it just has some extra functionalities where I can say that you have also access to my account uh not not just me um and what more this account does it

  102. 1:06:50

    just has like an extra method where you can uh sign send transactions to it uh send payloads to it um and you just specify which nft we're using and then the payload uh and let's take a quick look I think it was ckt sign hash yeah here we go so yeah when you call this function it just takes the token ID another like a another path if you want to specify that um the payload and you can sort of figure out about this approval ID

  103. 1:07:38

    uh and yeah so this basically just has some logic to check that it's the expected owner and then actually sends the transaction to the NPC service and does some call back um logic but it's it's quite a difficult implementation but the the the the contract at a high level is relatively simple so if you want to implement some sort of swapping mechanism i' definitely recommend that

  104. 1:08:24

    you take a look at this this contract to base it upon or instead you can have like another contract uh that instead of signing transactions through the nfts you just check whether you own an nft and allow you to sign a transaction based upon that uh but yeah that's that's the contract pretty simple okay yeah I'll take a look at it any more final questions before we wrap up no I think I'm good uh thanks

  105. 1:09:06

    for your time and look forward to make my hands study and then uh yeah I'm pretty sure we'll see each other in the death chat because it always sounds easier in theory than on the keyboard