直接使用npm上的web3js

This commit is contained in:
cebgcontract 2022-07-06 17:09:00 +08:00
parent a66d11e368
commit 3e4ad763f5
11 changed files with 2231 additions and 42920 deletions

View File

@ -11,8 +11,10 @@
"author": "zhl", "author": "zhl",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@metamask/eth-sig-util": "^4.0.1",
"bip39": "^3.0.4", "bip39": "^3.0.4",
"ethereumjs-wallet": "^1.0.2", "ethereumjs-wallet": "^1.0.2",
"web3": "^1.7.4",
"whatwg-fetch": "^3.6.2" "whatwg-fetch": "^3.6.2"
}, },
"devDependencies": { "devDependencies": {

View File

@ -1,5 +1,5 @@
import {AbiItem} from 'web3-utils';
export const abiERC1155 = [ export const abiERC1155: AbiItem[] = [
{ {
inputs: [ inputs: [
{ {

View File

@ -1,6 +1,6 @@
import {AbiItem} from 'web3-utils';
export let abiERC20: AbiItem[] = [
export let abiERC20 = [
{ {
constant: true, constant: true,
inputs: [], inputs: [],

View File

@ -1,5 +1,6 @@
import {AbiItem} from 'web3-utils';
export const abiERC721 = [ export const abiERC721: AbiItem[] = [
{ {
constant: true, constant: true,
inputs: [ inputs: [

View File

@ -1,7 +1,7 @@
import { singleton } from "./decorator/singleton.decorator"; import { singleton } from "./decorator/singleton.decorator";
import Web3 from './lib/web3.min.js'; import Web3 from 'web3';
let sth = import('./lib/ethSigUtil.js'); import { recoverTypedSignature, signTypedData, SignTypedDataVersion } from '@metamask/eth-sig-util';
import 'whatwg-fetch' import 'whatwg-fetch'
import { AllChains } from "./data/allchain"; import { AllChains } from "./data/allchain";
import { createWalletEvents, WALLET_ACCOUNT_CHANGE, WALLET_CHAIN_CHANGE, WALLET_TOKEN_TYPE_CHANGE } from "./common/WalletEvent"; import { createWalletEvents, WALLET_ACCOUNT_CHANGE, WALLET_CHAIN_CHANGE, WALLET_TOKEN_TYPE_CHANGE } from "./common/WalletEvent";
@ -54,7 +54,7 @@ export default class JCWallet {
constructor() { constructor() {
// this.web3 = new Web3('https://rpc-mainnet.kcc.network') // this.web3 = new Web3('https://rpc-mainnet.kcc.network')
this.web3 = new Web3('https://rpc-testnet.kcc.network', {timeout: 30000}) this.web3 = new Web3('https://rpc-testnet.kcc.network')
this.erc20Standard = new ERC20Standard(this.web3); this.erc20Standard = new ERC20Standard(this.web3);
this.erc721Standard = new ERC721Standard(this.web3); this.erc721Standard = new ERC721Standard(this.web3);
this.wallet = this.web3.eth.accounts.wallet.load(this.password, WALLET_STORAGE_KEY_NAME) this.wallet = this.web3.eth.accounts.wallet.load(this.password, WALLET_STORAGE_KEY_NAME)
@ -213,18 +213,18 @@ export default class JCWallet {
public signTypedDataV4(signObj: any) { public signTypedDataV4(signObj: any) {
const account = this.currentAccount() const account = this.currentAccount()
return window.ethSigUtil.signTypedData({ return signTypedData({
data: signObj, data: signObj,
privateKey: Buffer.from(account.privateKey.replace('0x', ''), 'hex'), privateKey: Buffer.from(account.privateKey.replace('0x', ''), 'hex'),
version: 'V4' version: SignTypedDataVersion.V4
}) })
} }
public recoverTypedSignatureV4(signObj: any, signature: string) { public recoverTypedSignatureV4(signObj: any, signature: string) {
return window.ethSigUtil.recoverTypedSignature({ return recoverTypedSignature({
data: signObj, data: signObj,
signature, signature,
version: 'V4' version: SignTypedDataVersion.V4
}) })
} }
} }

File diff suppressed because one or more lines are too long

42858
src/lib/web3.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
import Web3 from '../lib/web3.min.js'; import Web3 from 'web3';
import { abiERC20 } from "../abis/abiERC20"; import { abiERC20 } from "../abis/abiERC20";
import { BN, toUtf8 } from 'ethereumjs-util'; import { BN, toUtf8 } from 'ethereumjs-util';

View File

@ -1,5 +1,5 @@
import Web3 from '../lib/web3.min.js'; import Web3 from 'web3';
import { abiERC721 } from "../abis/abiERC721"; import { abiERC721 } from "../abis/abiERC721";
import { timeoutFetch } from '../util/net.util'; import { timeoutFetch } from '../util/net.util';
import { getFormattedIpfsUrl } from '../util/wallet.util'; import { getFormattedIpfsUrl } from '../util/wallet.util';

View File

@ -1,4 +1,4 @@
import Web3 from '../lib/web3.min.js'; import Web3 from 'web3';
import { BN } from 'ethereumjs-util'; import { BN } from 'ethereumjs-util';
/** /**

2237
yarn.lock

File diff suppressed because it is too large Load Diff