blockxy-flux 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -0
- package/package.json +35 -0
- package/sdk/index.js +13 -0
- package/sdk/metamask.js +10 -0
- package/sdk/solana/config.js +3 -0
- package/sdk/solana/index.js +23 -0
- package/sdk/solana/utils.js +20 -0
- package/sdk/solana/wallet.js +7 -0
package/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# Flux SDK
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
Flux SDK enables gasless transactions for Web3 applications, allowing users to interact with blockchain networks without paying gas fees. It supports both EVM chains (like Ethereum and Polygon) and Solana.
|
5
|
+
|
6
|
+
For EVM chains, it integrates with meta-transaction relayers like Biconomy. For Solana, it uses a custom relayer to sponsor transactions.
|
7
|
+
|
8
|
+
## Features
|
9
|
+
- Gasless transactions using meta-transactions (EVM) or a relayer (Solana)
|
10
|
+
- Supports Ethereum, Polygon, and other EVM-compatible chains
|
11
|
+
- Supports Solana (Devnet)
|
12
|
+
- Easy frontend integration
|
13
|
+
- NPM package for simplified deployment
|
14
|
+
|
15
|
+
## Folder Structure
|
16
|
+
```
|
17
|
+
flux-sdk/
|
18
|
+
│── contracts/ # Smart contracts for relaying transactions (EVM)
|
19
|
+
│── relayer/ # Biconomy client configuration (EVM)
|
20
|
+
│── solana-relayer/ # Node.js service for relaying Solana transactions
|
21
|
+
│── sdk/ # JavaScript SDK for frontend integration
|
22
|
+
│ ├── solana/ # Solana-specific SDK modules
|
23
|
+
│ └── ...
|
24
|
+
│── dashboard/ # Admin dashboard with GraphQL support
|
25
|
+
│── docs/ # Documentation
|
26
|
+
│── frontend/ # Example frontend integration
|
27
|
+
│── package.json # NPM configuration
|
28
|
+
│── README.md # SDK overview
|
29
|
+
```
|
30
|
+
|
31
|
+
## Installation
|
32
|
+
Clone the repository and install dependencies:
|
33
|
+
```sh
|
34
|
+
npm install
|
35
|
+
```
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
### EVM (Ethereum, Polygon, etc.)
|
40
|
+
|
41
|
+
Import the SDK in your JavaScript application:
|
42
|
+
```js
|
43
|
+
import { sendEVMApiBiconomy } from 'flux-sdk/sdk';
|
44
|
+
|
45
|
+
// ... connect to wallet ...
|
46
|
+
|
47
|
+
// Example of calling a smart contract
|
48
|
+
sendEVMApiBiconomy(contractAddress, abi, 'functionName', [arg1, arg2], userAddress);
|
49
|
+
```
|
50
|
+
|
51
|
+
### Solana
|
52
|
+
|
53
|
+
Import the Solana part of the SDK:
|
54
|
+
```js
|
55
|
+
import { solanaGasless } from 'flux-sdk/sdk';
|
56
|
+
import { Connection, Transaction, SystemProgram, sendAndConfirmTransaction } from '@solana/web3.js';
|
57
|
+
|
58
|
+
// ... connect to solana wallet (e.g. Phantom) ...
|
59
|
+
|
60
|
+
const connection = new Connection('https://api.devnet.solana.com');
|
61
|
+
const transaction = new Transaction().add(
|
62
|
+
SystemProgram.transfer({
|
63
|
+
fromPubkey: wallet.publicKey,
|
64
|
+
toPubkey: otherPublicKey,
|
65
|
+
lamports: 1000,
|
66
|
+
})
|
67
|
+
);
|
68
|
+
|
69
|
+
const signature = await solanaGasless.sendGaslessTransaction(connection, wallet, transaction);
|
70
|
+
console.log('Transaction signature:', signature);
|
71
|
+
```
|
72
|
+
|
73
|
+
## Running the Solana Relayer
|
74
|
+
To enable gasless transactions on Solana, you need to run the Solana relayer.
|
75
|
+
|
76
|
+
First, you need to configure the relayer with a secret key. Create a `.env` file in the `solana-relayer` directory with the following content:
|
77
|
+
```
|
78
|
+
RELAYER_SECRET_KEY=YOUR_SOLANA_SECRET_KEY_IN_BS58_FORMAT
|
79
|
+
```
|
80
|
+
You can generate a new keypair using the Solana CLI: `solana-keygen new`. Make sure your relayer account has enough SOL to pay for transaction fees.
|
81
|
+
|
82
|
+
Navigate to the root directory and start the relayer service:
|
83
|
+
```sh
|
84
|
+
npm run start:solana-relayer
|
85
|
+
```
|
86
|
+
|
87
|
+
## Frontend Example
|
88
|
+
Open `frontend/index.html` in a browser to test the gasless transaction flow. You will need to update it to include Solana examples.
|
89
|
+
|
90
|
+
## License
|
91
|
+
MIT License.
|
package/package.json
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
{
|
2
|
+
"name": "blockxy-flux",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "Flux is a gasless transaction SDK for Web3",
|
5
|
+
"main": "sdk/index.js",
|
6
|
+
"files": [
|
7
|
+
"sdk"
|
8
|
+
],
|
9
|
+
"repository": {
|
10
|
+
"type": "git",
|
11
|
+
"url": "https://github.com/Blockxyprotocols/Flux.git"
|
12
|
+
},
|
13
|
+
"scripts": {
|
14
|
+
"test": "mocha",
|
15
|
+
"build": "webpack",
|
16
|
+
"start:solana-relayer": "node solana-relayer/index.js"
|
17
|
+
},
|
18
|
+
"dependencies": {
|
19
|
+
"@biconomy/mexa": "^1.0.0",
|
20
|
+
"ethers": "^5.7.0",
|
21
|
+
"@solana/web3.js": "^1.91.4",
|
22
|
+
"@solana/wallet-adapter-base": "^0.9.23",
|
23
|
+
"@solana/wallet-adapter-wallets": "^0.19.32",
|
24
|
+
"express": "^4.18.2",
|
25
|
+
"cors": "^2.8.5",
|
26
|
+
"bs58": "^5.0.0"
|
27
|
+
},
|
28
|
+
"devDependencies": {
|
29
|
+
"mocha": "^9.0.0",
|
30
|
+
"webpack": "^5.0.0"
|
31
|
+
},
|
32
|
+
"keywords": ["Flux", "web3", "sdk"],
|
33
|
+
"author": "Blockxy Protocols",
|
34
|
+
"license": "MIT"
|
35
|
+
}
|
package/sdk/index.js
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
import { ethers } from "ethers";
|
2
|
+
import biconomy from "../relayer/biconomy";
|
3
|
+
import * as solana from './solana';
|
4
|
+
|
5
|
+
export async function sendEVMApiBiconomy(contractAddress, abi, functionName, args, userAddress) {
|
6
|
+
const provider = new ethers.providers.Web3Provider(window.ethereum);
|
7
|
+
const signer = provider.getSigner();
|
8
|
+
const contract = new ethers.Contract(contractAddress, abi, signer);
|
9
|
+
const tx = await contract.populateTransaction[functionName](...args);
|
10
|
+
return biconomy.sendTransaction(tx, userAddress);
|
11
|
+
}
|
12
|
+
|
13
|
+
export const solanaGasless = solana;
|
package/sdk/metamask.js
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
import { ethers } from "ethers";
|
2
|
+
export async function connectWallet() {
|
3
|
+
if (window.ethereum) {
|
4
|
+
const provider = new ethers.providers.Web3Provider(window.ethereum);
|
5
|
+
await provider.send("eth_requestAccounts", []);
|
6
|
+
return provider.getSigner();
|
7
|
+
} else {
|
8
|
+
throw new Error("MetaMask not installed");
|
9
|
+
}
|
10
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { Transaction, PublicKey } from '@solana/web3.js';
|
2
|
+
import { sendTransaction as sendRelayedTransaction } from './utils';
|
3
|
+
import { RELAYER_PUBLIC_KEY } from './config';
|
4
|
+
|
5
|
+
export async function sendGaslessTransaction(connection, wallet, transaction) {
|
6
|
+
const relayerPublicKey = new PublicKey(RELAYER_PUBLIC_KEY);
|
7
|
+
|
8
|
+
// Set the fee payer to be the relayer
|
9
|
+
transaction.feePayer = relayerPublicKey;
|
10
|
+
|
11
|
+
// Get a recent blockhash
|
12
|
+
const { blockhash } = await connection.getRecentBlockhash();
|
13
|
+
transaction.recentBlockhash = blockhash;
|
14
|
+
|
15
|
+
// The wallet signs the transaction
|
16
|
+
const signedTransaction = await wallet.signTransaction(transaction);
|
17
|
+
|
18
|
+
// The signed transaction is sent to the relayer
|
19
|
+
const signature = await sendRelayedTransaction(signedTransaction);
|
20
|
+
|
21
|
+
// Return the signature of the relayed transaction
|
22
|
+
return signature;
|
23
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
const RELAYER_URL = 'http://localhost:3001/relay';
|
2
|
+
|
3
|
+
export async function sendTransaction(signedTransaction) {
|
4
|
+
const response = await fetch(RELAYER_URL, {
|
5
|
+
method: 'POST',
|
6
|
+
headers: {
|
7
|
+
'Content-Type': 'application/json',
|
8
|
+
},
|
9
|
+
body: JSON.stringify({
|
10
|
+
transaction: signedTransaction.serialize().toString('base64'),
|
11
|
+
}),
|
12
|
+
});
|
13
|
+
|
14
|
+
if (!response.ok) {
|
15
|
+
throw new Error('Failed to send transaction to relayer');
|
16
|
+
}
|
17
|
+
|
18
|
+
const { signature } = await response.json();
|
19
|
+
return signature;
|
20
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { WalletAdapterNetwork } from '@solana/wallet-adapter-base';
|
2
|
+
import { getPhantomWallet } from '@solana/wallet-adapter-wallets';
|
3
|
+
|
4
|
+
export function getWallet(network = WalletAdapterNetwork.Devnet) {
|
5
|
+
const wallets = [getPhantomWallet()];
|
6
|
+
return wallets[0];
|
7
|
+
}
|