-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
309 additions
and
2,676 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
single-factor-auth-web/sfa-next-jwt-example/app/evm.ethers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 29 additions & 30 deletions
59
single-factor-auth-web/sfa-next-jwt-example/app/evm.web3.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,70 @@ | ||
import type {SafeEventEmitterProvider} from '@web3auth/base' | ||
import Web3 from 'web3' | ||
import type { IProvider } from "@web3auth/base"; | ||
import Web3 from "web3"; | ||
|
||
export default class EthereumRpc { | ||
private provider: SafeEventEmitterProvider | ||
private provider: IProvider; | ||
|
||
constructor(provider: SafeEventEmitterProvider) { | ||
this.provider = provider | ||
constructor(provider: IProvider) { | ||
this.provider = provider; | ||
} | ||
|
||
async getAccounts(): Promise<string[]> { | ||
try { | ||
const web3 = new Web3(this.provider as any) | ||
const accounts = await web3.eth.getAccounts() | ||
return accounts | ||
const web3 = new Web3(this.provider as any); | ||
const accounts = await web3.eth.getAccounts(); | ||
return accounts; | ||
} catch (error: unknown) { | ||
return error as string[] | ||
return error as string[]; | ||
} | ||
} | ||
|
||
async getBalance(): Promise<string> { | ||
try { | ||
const web3 = new Web3(this.provider as any) | ||
const accounts = await web3.eth.getAccounts() | ||
const balance = await web3.eth.getBalance(accounts[0]) | ||
const web3 = new Web3(this.provider as any); | ||
const accounts = await web3.eth.getAccounts(); | ||
const balance = await web3.eth.getBalance(accounts[0]); | ||
return balance.toString(); | ||
} catch (error) { | ||
return error as string | ||
return error as string; | ||
} | ||
} | ||
|
||
async signMessage(): Promise<string | undefined> { | ||
try { | ||
const web3 = new Web3(this.provider as any) | ||
const accounts = await web3.eth.getAccounts() | ||
const message = | ||
'0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad' | ||
;(web3.currentProvider as any)?.send( | ||
const web3 = new Web3(this.provider as any); | ||
const accounts = await web3.eth.getAccounts(); | ||
const message = "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"; | ||
(web3.currentProvider as any)?.send( | ||
{ | ||
method: 'eth_sign', | ||
method: "eth_sign", | ||
params: [accounts[0], message], | ||
from: accounts[0], | ||
}, | ||
(err: Error, result: any) => { | ||
if (err) { | ||
return console.error(err) | ||
return console.error(err); | ||
} | ||
return result | ||
}, | ||
) | ||
return result; | ||
} | ||
); | ||
} catch (error) { | ||
return error as string | ||
return error as string; | ||
} | ||
return | ||
} | ||
|
||
async signAndSendTransaction(): Promise<string> { | ||
try { | ||
const web3 = new Web3(this.provider as any) | ||
const accounts = await web3.eth.getAccounts() | ||
const web3 = new Web3(this.provider as any); | ||
const accounts = await web3.eth.getAccounts(); | ||
|
||
const txRes = await web3.eth.sendTransaction({ | ||
from: accounts[0], | ||
to: accounts[0], | ||
value: web3.utils.toWei('0.01', 'ether'), | ||
}) | ||
value: web3.utils.toWei("0.01", "ether"), | ||
}); | ||
return txRes.transactionHash.toString(); | ||
} catch (error) { | ||
return error as string | ||
return error as string; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.