Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

dSigner.ethers.node.js

Overview

dSigner.ethers.js provides a straightforward method to create an ethers.js compatible signer object that integrates with Supabase for authentication and wallet management.

Quick Start

Create a Signer Object

import { ethers } from "ethers";
import dSigner from "./dSigner.ethers.node.js";

const provider = new ethers.providers.JsonRpcProvider('https://rpc-l1.jibchain.net');
const signer = new dSigner(provider);

Authentication

Sign-up Example

The signIn() and signUp() methods are provided for development purposes only and should not be used in production environments. For production, it is recommended to use the Supabase SDK to manage authentication and then supply the access token to setAccessToken() as shown below.

import { ethers } from "ethers";
import dSigner from "./dSigner.ethers.node.js";

const provider = new ethers.providers.JsonRpcProvider('https://rpc-l1.jibchain.net');
const signer = new dSigner(provider);

await signer.signUp('[email protected]', 'your_super_secure_password');

After signing up, please check your inbox for the email confirmation.

Sign-in Example

import { ethers } from "ethers";
import dSigner from "./dSigner.ethers.node.js";

const provider = new ethers.providers.JsonRpcProvider('https://rpc-l1.jibchain.net');
const signer = new dSigner(provider);

await signer.signIn('[email protected]', 'your_super_secure_password');

Set Access Token from Supabase

For production implementations, use the access token generated by the Supabase SDK. The signIn() and signUp() methods provided above are for development convenience.

import { ethers } from "ethers";
import dSigner from "./dSigner.ethers.node.js";

const provider = new ethers.providers.JsonRpcProvider('https://rpc-l1.jibchain.net');
const signer = new dSigner(provider);

await signer.setAccessToken('SUPABASE_JWT_TOKEN');

Wallet Operations

Sign a Message

import dSigner from "./dSigner.ethers.node.js";

const signer = new dSigner(); // Yes, you may not need provider to sign message

await signer.setAccessToken('SUPABASE_JWT_TOKEN');

const signedMessage = await signer.signMessage('Message to sign');

Sending Ether (or Native Currency)

You can send transactions just as you would normally with ethers.js.

import { ethers } from "ethers";
import dSigner from "./dSigner.ethers.node.js";

const provider = new ethers.providers.JsonRpcProvider('https://rpc-l1.jibchain.net');
const signer = new dSigner(provider);

await signer.setAccessToken('SUPABASE_JWT_TOKEN');

const trx = await signer.sendTransaction({
    to: signer.address, // Example: Sending to your own address
    value: ethers.utils.parseEther('0.00001')
});
await trx.wait();
console.log(trx);

Interact with Smart Contracts

Interacting with smart contracts is as seamless as it is with ethers.js.

import { ethers } from "ethers";
import dSigner from "./dSigner.ethers.node.js";

const provider = new ethers.providers.JsonRpcProvider('https://rpc-l1.jibchain.net');
const signer = new dSigner(provider);

await signer.setAccessToken('SUPABASE_JWT_TOKEN');

const Token = new ethers.Contract('YOUR_CONTRACT_ADDRESS', [
    'function transfer(address to, uint256 value) external returns (bool)'
], signer);

const trx = await Token.transfer(
    signer.address, // Example: Sending to your own address
    ethers.utils.parseUnits('100')
);
await trx.wait();
console.log(trx.hash);