New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Neon EVM 🛠 How to access Solana using Neon EVM

ETHGlobalWed, Oct 9, 2024, 12:00 AM

Join Miroslav Nedelchev, Integration Developer at Neon EVM, in this workshop and learn: - How Ethereum-like transactions are getting processed on Solana through Neon EVM; - What are precompiles and how they can be used to interact natively with Solana; - How to build & perform Solana instructions inside Solidity; ETHGlobal Brussels 2024 brings together the most skilled web3 developers, designers and product builders from all around the globe for a weekend-long adventure to advance the Ethereum ecosystem! ---------------- Follow us: x.com/ethglobal Website: https://ethglobal.com Email us at: hello@ethglobal.com

Transcript

[Music] hi everyone my name is Miro I'm integration developer at nebm and today's video we will speak about the upcoming uh kakon at eth procs starting at July 12th so heading to our challenges first two or three words about new n who are we what we are doing so basically uh newm is a program on Sal which means that uh basically we manag to store the entire evm on salana how is this possible well thanks to one of the many benefits of sudana that we can store up to 10 megab of executable data and the evm itself is only 2 or 3 megab so it was entirely possible to store the EV on top of Solana so one of the benefits of Solana parall execution of transactions the most important one which is uh which means that thanks to the protocol called sea level to the Future sea level uh Sol is processing transactions simultaneously compared to EVMS where they where they uh process transactions in a sequential order so the other benefits of salana low gas fees High transactions speed and uh yeah we are uh we do support the F etherum compatible RPC with supporting the majority of the eth methods uh as you can see the most uh widely used languages s Viper most of the well-known tools such as metamask uh remix wallet connect uh moving forward we live on uh we're live on the on the M since July last year these are one of the key components of our uh uh project I will just go through them very quickly the first the evm which is our evm program on salana a smart contract on Solana the proxy server which is the RPC which helps to uh which helps our new operators to grab etherum pending eum like transactions unwrap them and wrap them again into Sal like transactions tracer app which serve Developers for debugging inspecting tracing neon pass which is our native bridge on salana which which is our native bridge between newana which basically helps for bridging SPO tokens between newana new foret the place where developers and projects can uh request air drop of uh defet uh tokens and assets to play around with and build their projects and the new DA which is still in the build but expected to be live very soon and the idea is that the Dow will be owner of the new evm and all of the changes will be happening through governance just going very quickly through all the tools that we support so you can see the wallets the majority uh metamask wallet connect Ledger we have our own save noses Fork uh we're supported by the bridge and also we do like I did mention neon pass our native bridge subs squid under grab when it comes to indexers and for Block explorers we do have our native block export new scan and we're supported by new block Scout when it comes to De Frameworks developers can decide to choose between hard and Foundry for SD case to support the majority and the most widely used ones such as web 3GS uh ether GS and all kind all of the libraries and uh examples from open zelin now going back to the challenges uh the first challenge for the hakon will be base use case of new NVM compatibility future so uh this is a fature that we provide very recently basically in simple words this means that any solidity uh smart contract on UNM can send the requests to any uh program on salana basically uh how does this happen this happens through instructions instructions are the smallest logic inside uh Solana basically inside your uh solid smart contract you build instructions and you forward them to our precompile which uh then forwards them into Sol chain uh I will I will I will show you uh uh just a demo in in a bit about the composability feature because it's a brand new feature as you can see documentation is not linked here it's still in the buildup but right before the hackaton starts I'll make sure to update uh this description and include all of the proper uh all of the relevant uh documentation and examples when it comes to use our compossibility feature the Second Challenge in our uh in our hackaton would be base use case of new basically you can uh deploy any cool D any cool idea on our chain which utilize some of the properties listed here such as parallel execution speed low transaction costs access to sonana liquidity now going back to the compossibility feature first from from from where you will start with both challenges is chain list you will type a new NM devet and here you have to check include test Nets and here you will find our RPC which is the one for our uh DEET the block explor that you would use to validate the history of your transaction is Dev net. newon scan.org and the faucet is located at net.org here you would connect your wallet and request the native neon token airdrop or any of the a20s in the list to be air dropped now uh going back to the composability feature uh demo first let's start with the pre compile so the pre compile is is on the this address ending on 006 basically this promile serves to uh handle requests from uh smartone contct on SOL smart contracts on to Solana so this is the interface of the pre compile we have a struct of uh code instruction which holds the very similar uh parameters being sent to any instruction on salana first is program ID second is uh accounts accounts is array of Str account mea where you basically this is a list of your of all of the keys that your instruction will have to access for reading or writing and byes is the instruction data which is basically encoded uh version of the method that you want to request with with the program method that you want to request with this instruction moving down to the methods of the of the of the pre compile first get new address which is a PDA calculation out of your new address so passing here uh different uh address we will return different byes 32 why byes 32 and why the keys are also in bytes 32 well because uh Sana Sana public Keys cannot be stored inside solidity so we have to encode them in byes 32 format to keep them in solidity next methods get resource address this method is tightly related to create resource so first uh to create create resource allows to ebm developers to create any uh type of account Onana basically you just have to define a random generated so space needed for your account lamp ports to make it exempt and an owner basically uh when you create a resource and then you you pass the same s to get resource address you will be able to uh get the account by the previously created resource uh get external Authority this method is used to uh return a PDA calculation of a public which could be used for delegate uh logic where an account can approve a delegate and uh then the delegate can spend the tokens of this account next method is get payer this is a very important method of the precompile basically um because um some instructions on sonana require a payer or Aigner to be attached to the instruction and uh from you cannot attach private keys to the to the promile which because it would be security issue everything on SOL can be can be accessed even if it's a private variable uh Storage storage dos can be read so it's really a security issue to uh paste private Keys here uh so this is why we created a get pair method which is basically uh unique uh unique it has unique value for each one of of the message sender so every time a different message sender is requesting this method it will return a different account and the thing is this method get paer is tight related to the execute method why because here in execute you see the second parameter is instruction here we pass what we have generated here after filling the required data to fill the instruction here we pass the in instruction and then the first parameter you see is lamp ports now this lamp Port is basically uh is basically a method basically saying okay Grant this amount of Lamport to the payer why because uh very often you need to provide uh like one one of the most widely used examples is to create account so if you decide to not use uh create resource but you decide to use execute then you have to for for account creation then you you have to provide lamp ports in order to make this account rent exempt and since everything here is happening on solity level you have uh uh you'll be dealing only with your ethereum like U address so you don't really have access to S so basically you can say okay let's use get payer as a signer and Grant this x uh this amount of Lamport to the payer to execute my uh to execute my uh transaction and uh let's say let's say uh a certain um a particular uh method on uh on UNM let's say it will cost uh 0.01 as a new fee as as a gas fee used for the transaction to be successful then if we request let's say one uh soul in Lamport and we're using this one so let's say to create some kind of account fill them with some uh uh some Lamport balance and we end up spending all of this one so that we have spent then basically the fee for our transaction is getting increased with uh uh 0.

1 newon plus the equivalence of one soul in newon so basically whatever we request to be given to the to the pair and we spend on behalf and we spend it on behalf of the pair then basically this is getting our our fee for the new transaction is getting increased if let's say in the other scenario where we requested one soul but we end up spending only half of it then we basically uh we're being charged uh only half of the soul in the equivalence of uh neon fee and the other uh and the other uh 0.5 Soul are being returned from the new operator where initially uh the source has been sent to the payer so now uh going back uh to some uh examples uh first uh I'll be using a hard Hut project as you can see in my hard Hut config I have defined the new definite uh chain uh I have get uh I got the RPC URL and the chain ID from chain list what I have showed you previously uh right here and uh now I can move forward with uh my uh demo I basically I have made the smart contract which is making a uh interface instance of the pre compile and now basically I have one execute method which which I'm just uh which I'm just forwarding uh my instructions from uh the front end to the promile right here now uh moving forward uh first my script to execute is basically to Mint uh SPO token it's it's a combination of three different instructions first one is to create the account for the SPO token uh you can see that uh this is the this is the SPO token uh this is this is the bytes needed for SPO mint initialization uh then I have created a random seat because I'm creating account with create account with seed and uh I put the lamp I make a calculation with a connection dot get minimum balance for L exempt basically passing the the same uh space that I would use to create the account why basically to make a calculation what kind of lamp ports I need to make this account rent exempt this is the first instruction second would be to initialize the maint instruction as you can see I'm using methods of the I'm using methods of the SPO token Library why because uh as you can see I did show you in the precompile you have to pass all of the encoded data Keys basically to mention who is signer and who is not this would be a bit too much confusing for uh evm developers this is why for your East I advise you to use uh uh I will advise you to use Solana web 3GS library and the Solana SPO token Library why because let's let's see for example this instruction which helps me to initialize my mint if I open it I can see inside that uh I can see inside that this instruction this method of the library is basically preparing all the keys for me encoding the data and returning everything in order that I only have to include this output in my object and pass it to the pr compile so it saves a lot of time and work for me so I really advise you to stick using this library because sometimes the keys can go up to 50 uh 50 uh entities in in the in the in the array of keys and it will be too hard to manage them by yourself next instruction so first we create account second we initialize this account as SPL uh token and now uh the third instruction would be to create a metadata uh why this has to be on chain uh action well basically there is one main difference between erc20 tokens on evm chains and the SPL tokens on on chain and this is uh basically the metadata on evm chains is very often most of the time stored offchain on block exports or some offchain space meanwhile in sonana this metadata is being stored onchain uh inside the metaplex program and this is why we have to make onchain instruction to save the metadata for our token now moving forward with executing this script you see I'm calling a mint uh SPO token GS yes this is this would be our uh this would be our token Min account I first generating it right here thanks to my uh in the thanks to my uh random generated seed and I pass it to web 3pu create with seed I get the public the the random generated public key and I pass it here in the create account with see it to parameter code new account public now I can see uh basically uh you saw that I have uh you you you see uh that I have added all of the instructions together in one uh web3 transaction object so this means that I have executed together the three instructions inside one newon uh solidity call uh you see uh this method this object I have added three instructions and now I'm passing it to batch execute compossibility method which is a request to my contract instance to call bat execute so you see this is the method right here basically it accepts it's accept aray of accounts instruction data lorts and so on and basically uh we are allowed to uh request multiple instructions inside one uh new solal and the limit is the default uh is is the maximum of the compute units on on no lch which is 1.4 million compute units so we can see uh let's let's open the transaction in our uh definite new scan you see our new NM transaction was successful for our new evm transaction there are four like transactions why because a new transaction is very often very big it cannot be go as a one transaction inside salana so this is why we split the transaction into smaller Chun of transaction and processing them on Solana now heading to the last one which is the last uh transaction is is uh usually writing the final State on salana we can see that here this is our Cent account with C instruction this is our random seat that they have USS it's a seat plus the current time stamp uh the space that allocated is 82 which is the usual space needed for SPO token instance then after the creation of the account this is the new account you can see that I initialized the mint here is our mint address and the third instruction is here it's basically uh to uh metaplex basically uh saving our metadata and now if I open uh our mint account our new account you see that okay it already it's already recognized by uh by block Explorer and it has metadata now something important to show you uh when you scroll to the to the bottom we can see that okay our transaction which which includes uh three Uh custom inner instructions through through the compossibility feature has consumed almost 1.1 million components out of 1.4 Computing unit limit uh computer units so you can basically see that we're almost at the end of the limit so maybe adding one more instruction and there will be no room for another uh we're looking basically to uh make this is our first initial version of the compossibility feature and the next versions We will see how we can increase this limit and basically fit more instructions into into uh one Sol call now moving to to my next script uh basically taking the token Min uh key public key and placing it in the next script I will be creating a at account so what is at account basically if you want to receive or send SPO tokens Onana you have to have a ATA account which is specific for this token and the owner is your main account so now uh I will be making ATA accounts for my user and for my contract when the at token accounts are made the sociate token accounts are made only then I can uh proceed with more uh uh logic to be executed for example meing SPO tokens transferring them approving them and so on so let's grab one one transaction and check it uh so I have the transaction successful again and just to show you very quickly here again I'm using the web3 GS SDK and I'm using the salana SPO token library and here I'm I'm this is how I'm uh I'm making the create associate token account instruction I am using this instruction again just to show you very quickly this instruction is preparing all of the keys and encoded data for me I don't have to worry to creating this object manually and so on so I highly advise you to stick using this uh SDK now you can you can see here I have added to my object to the salana TX object that I'm passing to the precompile associate create associate token account instruction and if we go to the sonana transaction you can see that okay here here is my SPO associate token account creation Now when I have the 0 accounts made for my user one and the contract I can proceed with making some interaction between of them let's mint some tokens and transfer them now the third script for our Workshop is called SPL token instructions here in this uh in this example first I'm including a create Min to instruction basically I'm meeting a th000 tokens to the ATA account of my contract then the second instruction will be uh create uh a transfer instruction from the ATA contract to the to the ATA user one so this is the ATA of the contract and this is the ATA of the user I mean th000 tokens to the contract then I transfer uh 10 tokens from contract to user and the last U instruction is just approval now heading to executing this script okay we can see at the beginning that uh the ATA uh contract has a zero balance and then we can see also oops then we can see also so we can see the ATA contract has a zero balance and then we can see the ATA user one has also zero balance why because we have just initialized them they brand new token account so they hold a zero balance now after after our instructions which are first the meeting we can see that we we read again the balance of at contract and now we can see that it holds some amount of tokens and we can also see that the ATA user one has also own some am of tokens so yeah why because we have a first Meed to ATA contract and then we have made a transfer instruction from ATA contract to ATA user and now if we open again the transaction to just to validate what is our output open again the last son transaction and if we scroll down we can see okay this is our Min to Method basically we Min uh 1,000 tokens to our uh ATA uh the associate token account of the myart contract and then the second transfer uh instruction which is basically transferring 10 tokens from the ATA of uh of the of the smart contract to the associate token account of my user so n this is the compossibility feature it's it's it's a brand new feature we just uh provided few days ago documentation is still in the buildup I will make sure to uh to attach the documentation here and uh looking forward to see you in person on the event I'll be there I'll be happy to help you and support you with uh everything during the buildup of your projects during the submission and so on so please do not hesitate we will have a we we will have a chat where we can ask me anything I will be there to support you with everything I can to so you can basically submit your projects once again our two challenges first one best use case of new NM compatibility feature and the second one is uh best Ed Case of new NM for both challenges the qualification requirements are uh live pitching at the boot uh submitting demo hosted on domain or submitting video recording so uh we are very happy and we are looking forward to see your submission see you at the event w [Music]

Automatic transcript — names and jargon may be misspelled.