Signing an ethereum transaction
The Provider has aaddress of our MPC wallet. The Provider then proxies the request for balance to the configured RPC url and returns the result.
Below is an example of how to use Portal to send a USDC transaction on the Monad Testnet network:
- Chain ID: The transaction is configured for the Monad Testnet network using the CAIP-2 format (
eip155:10143). - Transaction Parameters: The
BuildTransactionParamstruct is used to define the transaction details:to: The recipient’s address.token: The token to send (in this case,USDC).amount: The amount of the token to send (e.g.,1USDC).
- Building the Transaction: The
portal.buildEip155Transactionmethod constructs the transaction object using the specified parameters. - Signing and Sending: The
portal.requestmethod is used to sign and send the transaction. The method takes the chain ID, theeth_sendTransactionmethod, and the transaction details as parameters. - Transaction Hash: Once the transaction is successfully sent, the transaction hash is returned and printed to the console.
PortalRequestMethods available for you to use, which you can find in the SDK.
Estimating Gas
By default, Portal will estimate and populate thegas property in a transaction object if the property is undefined.
To estimate the gas value manually, you’ll want to use the eth_estimateGas RPC call and pass in your transaction as the parameter.
- Chain ID: The transaction is configured for the Monad Testnet network using the CAIP-2 format (
eip155:10143). - Sender Address: The
portal.getAddressmethod retrieves the user’s wallet address for the specified chain. - Transaction Object: A transaction object is created with the following fields:
from: The sender’s address.to: The recipient’s address.value: The amount of native token (ETH) to send, specified in WEI.
- Gas Estimation: The
portal.requestmethod is used to call theeth_estimateGasmethod, which estimates the gas required for the transaction. - Result Handling: The estimated gas value is retrieved from the response and printed to the console.
Signing Solana Transactions
To construct your own advanced transaction for solana simply follow that example:- Chain ID: The transaction is configured for the Solana Devnet using the CAIP-2 format (
solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1). - Transaction Parameters: The
BuildTransactionParamstruct is used to define the transaction details:to: The recipient’s address.token: The token to send (in this case,USDC).amount: The amount of the token to send (e.g.,1USDC).
- Building the Transaction: The
portal.buildSolanaTransactionmethod constructs the transaction object using the specified parameters. - Signing and Sending: The
portal.requestmethod is used to sign and send the transaction. The method takes the chain ID, thesol_signAndSendTransactionmethod, and the transaction details as parameters. - Transaction Hash: Once the transaction is successfully sent, the transaction hash is returned and printed to the console.
Raw sign
You can now utilize our SDK to generate raw signatures that are generated using the underlying key share without adding any chain specific formatting to the signature. This effectively unlocks your ability to use the Portal SDK with any chain that usesSECP256K1 or ED25519.
Enabling the Enclave Signer
Executing MPC operations requires computation on the client device. Depending on the CPU of the client device this can take variable amounts of time, leading to inconsistent signing times across users. To solve this, you can leverage the Enclave MPC API from your SDK to execute MPC operations server-side which leads to consistent (and often faster) signing speeds. This feature leverages the Enclave MPC API by sending the user’s key share to a Trusted Execution Environment (TEE) which runs the MPC code in a secure AWS Nitro Enclave with the same non-custodial guarantees as client-side MPC.By enabling the
useEnclaveMpcApi feature flag the client key share will be transmitted from the user device, but it is never stored.useEnclaveMPCApi to true, the Portal instance will use the Enclave MPC API for signing transactions, ensuring faster computation and consistent performance across client devices.
And now you are signing transactions with Portal! 🙌 🚀 Next, we’ll explore how to simulate a transaction so that you can create smoother experiences for your users. Related Documentation