链请求增加chain参数, 用于向不同链发送请求
This commit is contained in:
parent
23bc433368
commit
16698de399
@ -3,6 +3,8 @@ import Web3 from 'web3'
|
|||||||
|
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import { Account } from 'web3-core'
|
import { Account } from 'web3-core'
|
||||||
|
import { AllChains } from './allchain'
|
||||||
|
import { HttpRetryProvider } from './HttpRetryProvider'
|
||||||
|
|
||||||
const abiFt = require('abis/ERC20.json').abi
|
const abiFt = require('abis/ERC20.json').abi
|
||||||
export class ERC20Reactor {
|
export class ERC20Reactor {
|
||||||
@ -114,6 +116,7 @@ export class ERC20Reactor {
|
|||||||
to,
|
to,
|
||||||
amount,
|
amount,
|
||||||
account,
|
account,
|
||||||
|
chain,
|
||||||
gas,
|
gas,
|
||||||
encodeABI = false,
|
encodeABI = false,
|
||||||
estimate = false,
|
estimate = false,
|
||||||
@ -122,13 +125,22 @@ export class ERC20Reactor {
|
|||||||
from?: string
|
from?: string
|
||||||
to: string
|
to: string
|
||||||
account?: string
|
account?: string
|
||||||
|
chain?: number
|
||||||
amount: number | string
|
amount: number | string
|
||||||
gas?: number
|
gas?: number
|
||||||
encodeABI?: boolean
|
encodeABI?: boolean
|
||||||
estimate?: boolean
|
estimate?: boolean
|
||||||
}) {
|
}) {
|
||||||
from = from || account || this.account.address
|
from = from || account || this.account.address
|
||||||
const contract = new this.web3.eth.Contract(abiFt, address, { from: account || this.account.address })
|
let w3 = this.web3
|
||||||
|
if (chain) {
|
||||||
|
let chainData = AllChains.find(o => o.id === chain)
|
||||||
|
if (chainData) {
|
||||||
|
const provider = new HttpRetryProvider(chainData.rpc.split('|'))
|
||||||
|
w3 = new Web3(provider)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const contract = new w3.eth.Contract(abiFt, address, { from: account || this.account.address })
|
||||||
const amountBN = Web3.utils.toBN(Web3.utils.toWei(amount + ''))
|
const amountBN = Web3.utils.toBN(Web3.utils.toWei(amount + ''))
|
||||||
if (encodeABI) {
|
if (encodeABI) {
|
||||||
return contract.methods.transferFrom(from, to, amountBN).encodeABI()
|
return contract.methods.transferFrom(from, to, amountBN).encodeABI()
|
||||||
@ -146,16 +158,26 @@ export class ERC20Reactor {
|
|||||||
to,
|
to,
|
||||||
amount,
|
amount,
|
||||||
account,
|
account,
|
||||||
|
chain,
|
||||||
encodeABI = false,
|
encodeABI = false,
|
||||||
}: {
|
}: {
|
||||||
account?: string
|
account?: string
|
||||||
address?: string
|
address?: string
|
||||||
to: string
|
to: string
|
||||||
amount: string
|
amount: string
|
||||||
|
chain?: number
|
||||||
encodeABI: boolean
|
encodeABI: boolean
|
||||||
}) {
|
}) {
|
||||||
|
let w3 = this.web3
|
||||||
|
if (chain) {
|
||||||
|
let chainData = AllChains.find(o => o.id === chain)
|
||||||
|
if (chainData) {
|
||||||
|
const provider = new HttpRetryProvider(chainData.rpc.split('|'))
|
||||||
|
w3 = new Web3(provider)
|
||||||
|
}
|
||||||
|
}
|
||||||
const contract = address
|
const contract = address
|
||||||
? new this.web3.eth.Contract(abiFt, address, { from: account || this.account.address })
|
? new w3.eth.Contract(abiFt, address, { from: account || this.account.address })
|
||||||
: this.contract
|
: this.contract
|
||||||
let amountBN = Web3.utils.toBN(Web3.utils.toWei(amount + ''))
|
let amountBN = Web3.utils.toBN(Web3.utils.toWei(amount + ''))
|
||||||
if (encodeABI) {
|
if (encodeABI) {
|
||||||
|
@ -3,6 +3,8 @@ import { getFormattedIpfsUrl } from 'utils/wallet.util'
|
|||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import { Account } from 'web3-core'
|
import { Account } from 'web3-core'
|
||||||
|
import { AllChains } from './allchain'
|
||||||
|
import { HttpRetryProvider } from './HttpRetryProvider'
|
||||||
|
|
||||||
export const ERC721 = 'ERC721'
|
export const ERC721 = 'ERC721'
|
||||||
export const ERC721_INTERFACE_ID = '0x80ac58cd'
|
export const ERC721_INTERFACE_ID = '0x80ac58cd'
|
||||||
@ -299,6 +301,7 @@ export class ERC721Reactor {
|
|||||||
to,
|
to,
|
||||||
tokenId,
|
tokenId,
|
||||||
account,
|
account,
|
||||||
|
chain,
|
||||||
gas,
|
gas,
|
||||||
encodeABI = false,
|
encodeABI = false,
|
||||||
}: {
|
}: {
|
||||||
@ -307,11 +310,20 @@ export class ERC721Reactor {
|
|||||||
to: string
|
to: string
|
||||||
tokenId: string
|
tokenId: string
|
||||||
account?: string
|
account?: string
|
||||||
|
chain?: number
|
||||||
gas?: number
|
gas?: number
|
||||||
encodeABI?: boolean
|
encodeABI?: boolean
|
||||||
}) {
|
}) {
|
||||||
|
let w3 = this.web3
|
||||||
|
if (chain) {
|
||||||
|
let chainData = AllChains.find(o => o.id === chain)
|
||||||
|
if (chainData) {
|
||||||
|
const provider = new HttpRetryProvider(chainData.rpc.split('|'))
|
||||||
|
w3 = new Web3(provider)
|
||||||
|
}
|
||||||
|
}
|
||||||
const contract = address
|
const contract = address
|
||||||
? new this.web3.eth.Contract(abiNft, address, { from: account || this.account.address })
|
? new w3.eth.Contract(abiNft, address, { from: account || this.account.address })
|
||||||
: this.contract
|
: this.contract
|
||||||
if (encodeABI) {
|
if (encodeABI) {
|
||||||
return contract.methods.safeTransferFrom(from, to, tokenId).encodeABI()
|
return contract.methods.safeTransferFrom(from, to, tokenId).encodeABI()
|
||||||
@ -326,16 +338,24 @@ export class ERC721Reactor {
|
|||||||
address,
|
address,
|
||||||
to,
|
to,
|
||||||
tokenId,
|
tokenId,
|
||||||
|
chain,
|
||||||
encodeABI = false,
|
encodeABI = false,
|
||||||
}: {
|
}: {
|
||||||
address?: string
|
address?: string
|
||||||
to: string
|
to: string
|
||||||
tokenId: string
|
tokenId: string
|
||||||
|
chain?: number
|
||||||
encodeABI?: boolean
|
encodeABI?: boolean
|
||||||
}) {
|
}) {
|
||||||
const contract = address
|
let w3 = this.web3
|
||||||
? new this.web3.eth.Contract(abiNft, address, { from: this.account.address })
|
if (chain) {
|
||||||
: this.contract
|
let chainData = AllChains.find(o => o.id === chain)
|
||||||
|
if (chainData) {
|
||||||
|
const provider = new HttpRetryProvider(chainData.rpc.split('|'))
|
||||||
|
w3 = new Web3(provider)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const contract = address ? new w3.eth.Contract(abiNft, address, { from: this.account.address }) : this.contract
|
||||||
if (encodeABI) {
|
if (encodeABI) {
|
||||||
return contract.methods.mint(to, tokenId).encodeABI()
|
return contract.methods.mint(to, tokenId).encodeABI()
|
||||||
}
|
}
|
||||||
@ -348,16 +368,26 @@ export class ERC721Reactor {
|
|||||||
address,
|
address,
|
||||||
to,
|
to,
|
||||||
tokenIds,
|
tokenIds,
|
||||||
|
chain,
|
||||||
encodeABI = false,
|
encodeABI = false,
|
||||||
}: {
|
}: {
|
||||||
account?: string
|
account?: string
|
||||||
address?: string
|
address?: string
|
||||||
to: string
|
to: string
|
||||||
tokenIds: string[]
|
tokenIds: string[]
|
||||||
|
chain?: number
|
||||||
encodeABI?: boolean
|
encodeABI?: boolean
|
||||||
}) {
|
}) {
|
||||||
|
let w3 = this.web3
|
||||||
|
if (chain) {
|
||||||
|
let chainData = AllChains.find(o => o.id === chain)
|
||||||
|
if (chainData) {
|
||||||
|
const provider = new HttpRetryProvider(chainData.rpc.split('|'))
|
||||||
|
w3 = new Web3(provider)
|
||||||
|
}
|
||||||
|
}
|
||||||
const contract = address
|
const contract = address
|
||||||
? new this.web3.eth.Contract(abiNft, address, { from: account || this.account.address })
|
? new w3.eth.Contract(abiNft, address, { from: account || this.account.address })
|
||||||
: this.contract
|
: this.contract
|
||||||
// let gas = await contract.methods.batchMint(to, tokenIds, configIds).estimateGas({ gas: 1000000 })
|
// let gas = await contract.methods.batchMint(to, tokenIds, configIds).estimateGas({ gas: 1000000 })
|
||||||
if (encodeABI) {
|
if (encodeABI) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user