
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
stellar-snap
Advanced tools
This guide provides detailed instructions on integrating Stellar wallet functionalities into MetaMask Snaps, enabling seamless interaction with Stellar applications. This integration aims to create a universal standard for integrating Stellar wallet functionalities across different applications.
Follow these steps to get started with integrating Stellar-Wallet functionalities into your MetaMask Snaps.
Set Up MetaMask Flask: Ensure you have MetaMask Flask installed, which is a version tailored for developers to create and integrate Snaps.
Install Metastellar Snap: Follow the installation instructions provided in the Full Documentation to connect your MetaMask to the Stellar network.
Create Your Snap: Use the MetaMask Snaps CLI to initialize a new Snap project. Refer to the MetaMask Snaps documentation for detailed guidance on setting up your environment. Installation To install Stellar Snap, clone the repository and install the necessary dependencies:
git clone https://github.com/yourusername/stellar-snap.git
cd stellar-snap
yarn install
To run the application, execute:
yarn start
This command starts the application and opens the user interface for interaction.
To connect Stellar Snap to MetaMask, use the following method:
const result = await ethereum.request({
method: 'wallet_requestSnaps',
params: {
[`npm:stellar-snap`]: {}
},
});
You can invoke Stellar wallet methods using the following structure:
const result = await ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: `npm:stellar-snap`,
request: {
method: `${methodName}`,
params: {
paramName: `${paramValue}`
}
}
}
});
To call Stellar-Wallet functions from other MetaMask snaps, you need to ensure that the Snap containing the Stellar wallet is installed and running. You can then use the wallet_invokeSnap method to access its functions.
Example Assuming you have another Snap that needs to call the getBalance method from Stellar Snap, you can do this:
const balance = await ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: `npm:stellar-snap`,
request: {
method: 'getBalance',
params: {
address: 'your-stellar-address', // replace with the actual Stellar address
testnet: false // optional; true for testnet
}
}
}
});
console.log('Balance:', balance);
Error Handling: Always implement error handling for network requests to manage any exceptions or issues that may arise.
Snap ID: Ensure that you are using the correct Snap ID (e.g., npm:stellar-snap) when invoking methods.
Asynchronous Calls: The requests to the Snap are asynchronous, so make sure to use async/await or .then() for handling promises.
Integrating Stellar functionalities allows applications to leverage important wallet features. Below are key methods for interaction:
Retrieve essential information related to the user's Stellar wallet.
const address = await callMetaStellar('getAddress');
console.log(`Current Address: ${address}`);
Set the network environment for transactions, ensuring users connect to the appropriate Stellar network (Mainnet or Testnet). this can be done by passing a boolean into the testnet parameter to any call. This is optional, and method calls will be treated as mainnet if this parameter is omitted. If the testnet parameter is not relevant to a method call it is simply ignored
const balance = await ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: `npm:stellar-snap`,
request: {
method: 'getBalance',
params: {
testnet: false // optional; true for testnet
}
}
}
});
Enable users to securely sign transactions to ensure authorized actions.
const signedTransaction = await callMetaStellar('signTransaction', { transaction:xdr });
console.log(`Signed Transaction: ${signedTransaction}`);
callMetaStellar FunctionThe easiest way to interact with the wallet is by copying the callMetaStellar function. This function acts as a bridge to make calls to the Stellar RPC methods defined in your Snap.
async function callMetaStellar(method, params){
if (typeof window !== 'undefined' && typeof window.ethereum !== undefined) {
//You Can Delete this section after offical launch
const isFlask = (
await window.ethereum?.request({ method: "web3_clientVersion" })
)?.includes("flask");
if(!isFlask){
alert("install Metamask Flask")
}
// ------------------------------------------------
try{
if(method === 'connect'){
//This will also install stellar if the user has metamask
return await window.ethereum.request({
method: 'wallet_requestSnaps',
params: {
['npm:stellar-snap']: {}
},
});
}
const rpcPacket = {
method: 'wallet_invokeSnap',
params:{
snapId:'npm:stellar-snap',
request: {'method':method, params:params}
}
}
return await window.ethereum.request(rpcPacket);
}
catch(e){
alert(e.message);
}
}
}
Invoke the callMetaStellar function:
// Connect
const connected = await callMetaStellar('connect');
// Get Address
const address = await callMetaStellar('getAddress');
// Sign Transaction
const params = { transaction: txn, testnet: true };
const signedTxn = await callMetaStellar('signTransaction', params);
// Returns a signed Stellar transaction in XDR as a string
Here’s a comprehensive list of Stellar methods available for invocation via the callMetaStellar function. Each function includes a brief description of its purpose and a sample implementation.
getAddress
async function getAddress() {
return await callMetaStellar('getAddress');
}
getAccountInfo
async function getAccountInfo(accountId) {
return await callMetaStellar('getAccountInfo', { address:accountId });
}
getBalance
async function getBalance(accountId) {
return await callMetaStellar('getBalance', {testnet:true});
}
transfer
async function transfer(destination, amount) {
gAddress = destination //stellar address
xlmAmount = amount //decimal amount of xlm as a string ex. '2.146'
return await callMetaStellar('transfer', {to:`${gAddress}`, amount:`${xlmAmount}`, testnet?:true});
}
fund
async function fund(accountId, amount) {
return await callMetaStellar('fund');
}
signTransaction
async function signTransaction(xdr) {
return await callMetaStellar('signTransaction', { transaction:`${xdr} as a string` });
}
signAndSubmitTransaction
async function signAndSubmitTransaction(xdr) {
return await callMetaStellar('signAndSubmitTransaction', { transaction:`${xdr} as a string` });
}
getDataPacket
async function getDataPacket() {
return await callMetaStellar('getDataPacket');
}
setCurrentAccount
async function setCurrentAccount(accountId) {
return await callMetaStellar('setCurrentAccount', { address:'G-address' });
}
showAddress
async function showAddress() {
return await callMetaStellar('showAddress');
}
createAccount
async function createAccount() {
return await callMetaStellar('createAccount', {name:'accountname-string'});
}
listAccounts
async function listAccounts() {
return await callMetaStellar('listAccounts');
}
renameAccount
async function renameAccount(address) {
return await callMetaStellar('renameAccount', {address:`${address}`});
}
importAccount
async function importAccount(secretKey) {
return await callMetaStellar('importAccount');
}
getAssets
async function getAssets() {
return await callMetaStellar('getAssets');
}
sendAuthRequest
async function sendAuthRequest(destination) {
return await callMetaStellar('sendAuthRequest', { destination });
}
signStr
async function signStr(message) {
return await callMetaStellar('signStr', { message });
}
dispPrivateKey
async function dispPrivateKey(accountId) {
return await callMetaStellar('dispPrivateKey', { accountId });
}
These functions form the core of your Stellar wallet integration within MetaMask Snaps. By utilizing these methods, you enable smooth interaction with Stellar features, fostering a cohesive user experience across applications.
By following this guide, you can effectively integrate Stellar wallet functionalities into your MetaMask Snaps. This modular approach enhances your application while establishing a universal standard for Stellar wallet integration, allowing other developers to easily adopt the framework.
FAQs
A non custodial Stellar Wallet for metamask
The npm package stellar-snap receives a total of 45 weekly downloads. As such, stellar-snap popularity was classified as not popular.
We found that stellar-snap demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.