Skip to content

Commit

Permalink
Merge pull request #12 from ideal-lab5/feat/9-murmurjs-move-communica…
Browse files Browse the repository at this point in the history
…tion-with-idn-to-the-client

Feat/9 murmurjs move communication with idn to the client
  • Loading branch information
driemworks authored Oct 8, 2024
2 parents 62a2c1b + de72596 commit 41605d6
Show file tree
Hide file tree
Showing 13 changed files with 450 additions and 96 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/dist
/node_modules
dist
node_modules
package-lock.json
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,52 @@

A wrapper to enable easy usage of murmur wallets in web apps.

More coming soon.
More coming soon.

## Usage

The Murmur Client depends on:

- Axios for making HTTP requests to the Murmur API
- Polkadot-js for interacting with the Ideal Network

You need to configure an `axios` and a `polkadot-js` instances to be injected in the Murmur Client.

```javascript
import { ApiPromise, WsProvider, Keyring } from "@polkadot/api";
import { KeyringPair } from "@polkadot/keyring/types";
import axios from "axios";
import { MurmurClient } from "murmur.js";

/* Polkadot API initialization */
const provider = new WsProvider("ws://127.0.0.1:9944");
console.log("Provider initialized");
const api = await ApiPromise.create({ provider });
console.log("API initialized");

/* Axios initialization */
const httpClient = axios.create({
baseURL: "https://api.example.com",
headers: {
"Content-Type": "application/json",
},
});

/* Define the master account (optional, it falls back to `alice`) */
const keyring = new Keyring({ type: "sr25519" });
const alice = keyring.addFromUri("//Alice");

/* MurmurClient initialization */
const murmurClient = new MurmurClient(httpClient, api, alice);
console.log("MurmurClient initialized");

// Use the MurmurClient instance to make requests
murmurClient
.authenticate("username", "password")
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
```
21 changes: 21 additions & 0 deletions examples/create-execute/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "murmur-example-create-execute",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"type": "module",
"scripts": {
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"typescript": "^4.9.5"
},
"dependencies": {
"@polkadot/api": "^13.2.1",
"axios": "^1.7.7",
"murmur.js": "file:../../../murmur.js"
}
}
40 changes: 40 additions & 0 deletions examples/create-execute/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { ApiPromise, WsProvider } from "@polkadot/api";
import axios from "axios";
import { MurmurClient } from "murmur.js";

/* Polkadot API initialization */
const provider = new WsProvider("ws://127.0.0.1:9944");
console.log("Provider initialized");
const api = await ApiPromise.create({ provider });
console.log("API initialized");
// Retrieve the chain & node information via rpc calls
const [chain, nodeName, nodeVersion] = await Promise.all([
api.rpc.system.chain(),
api.rpc.system.name(),
api.rpc.system.version(),
]);
console.log(
`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}`
);

/* Axios initialization */
const httpClient = axios.create({
baseURL: "http://127.0.0.1:8000",
headers: {
"Content-Type": "application/json",
},
});

/* MurmurClient initialization */
const murmurClient = new MurmurClient(httpClient, api);
console.log("MurmurClient initialized");

const loguinResult = await murmurClient.authenticate("admin", "password");
console.log(loguinResult);

await murmurClient.new(100, async (result: any) => {
console.log(`Tx Block Hash: ${result.status.asFinalized}`);
const bob = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty";
const call = api.tx.balances.transferAllowDeath(bob, 1000000000000);
await murmurClient.execute(call);
});
15 changes: 15 additions & 0 deletions examples/create-execute/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "es2017",
"module": "esnext",
"moduleResolution": "node",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"]
}
21 changes: 21 additions & 0 deletions examples/simple-connect/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "murmur-example-simple-connect",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"type": "module",
"scripts": {
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"typescript": "^4.9.5"
},
"dependencies": {
"@polkadot/api": "^13.2.1",
"axios": "^1.7.7",
"murmur.js": "file:../../../murmur.js"
}
}
30 changes: 30 additions & 0 deletions examples/simple-connect/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ApiPromise, WsProvider } from "@polkadot/api";
import axios from "axios";
import { MurmurClient } from "murmur.js";

/* Polkadot API initialization */
const provider = new WsProvider("ws://127.0.0.1:9944");
console.log("Provider initialized");
const api = await ApiPromise.create({ provider });
console.log("API initialized");
// Retrieve the chain & node information via rpc calls
const [chain, nodeName, nodeVersion] = await Promise.all([
api.rpc.system.chain(),
api.rpc.system.name(),
api.rpc.system.version(),
]);
console.log(
`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}`
);

/* Axios initialization */
const httpClient = axios.create({
baseURL: "https://api.example.com",
headers: {
"Content-Type": "application/json",
},
});

/* MurmurClient initialization */
new MurmurClient(httpClient, api);
console.log("MurmurClient initialized");
15 changes: 15 additions & 0 deletions examples/simple-connect/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "es2017",
"module": "esnext",
"moduleResolution": "node",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"author": "Ideal Labs <[email protected]>",
"dependencies": {
"@polkadot/api": "^13.2.1",
"axios": "^1.7.7"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 41605d6

Please sign in to comment.