The project comprises of two main components. The first component involves using MetaMask
wallet to sign and create the signature from your message. The second component involves writing a custom program and deploying it on the Solana
network. Bringing these two components together is the main objective of this project, showcasing how to create and transmit a transaction in Solana using an EVM keypair for signing, along with interacting with the Solana network through a custom program.
These are the references:
- Secp256k1 Program
- Signing data with Metamask
- How to Connect a React DApp to MetaMask
- How to Write Your First Anchor Program in Solana
- Create a simple DApp to connect with your Metamask wallet.
- Creaet input box for user to input the message.
- Signing your message with
Metamask
by usingpersonal_sign
method. (Note: It is necessary to convert the message to hex and add the currency0x
) - Verify this signature by using
ethers.utils.verifyMessage
to verify the signature.
- Write a simple transaction to interact with the
Secp256k1 Program
on theSolana
network (Example). - Write your own program to create PDA accounts and deploy it to the
Solana
network. - Write your own client.ts to interact with the program you wrote.
- Create
client
andserver
, client to interact with metamask wallet, and server to interact with solana network. - Get the signature, message, publickey of the eth address and wrap it up as the data of an instruction and send it to the server (Note: The message should be modified because when using the personal_sign method the message was modified to
\x19Ethereum Signed Message:\n${message.length}${message}
) - Update your program has written above, create 2 functions, one is create PDA account has amount, another is transfer amount from one PDA account to another PDA account (Example).
- The server will create a transaction with 2 instructions, one to send to the Secp256k1 Program to verify the signature of the metamask wallet and one to interact with your Program.
- If it only takes one person to sign, use
sign
. - To accommodate multiple signers, use
transaction.partialSign(signer)
to sign the transaction. Usingtransaction.sign(signer)
would nullify the signatures of previous signers, preventing confirmation of transactions with multiple signers. - If you serialize the same transaction multiple times, the network state will be out of sync, so set
skipPreflight:true
when usesendEncodedTransaction
instead ofsendTransaction
to avoid issues.
yarn start
cd server
node server.js