Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async sendTransaction (to, value, data, from) {
await this.assertContractExists()
if (!data) {
// erc20 transfer
data = this.generateErc20Transfer(to, value)
value = 0
to = ensure0x(this._contractAddress)
}
return this.getMethod('sendTransaction')(to, value, data, from)
}
if (from == null) {
const addresses = await this.getAddresses()
from = ensure0x(addresses[0].address)
}
value = BigNumber(value).toString(16)
const nonce = (parseInt((await this.getMethod('jsonrpc')('eth_getTransactionCount', this.wallet.getAddressString(), 'pending')), 16)).toString(16)
console.log('nonce')
console.log(nonce)
const gasPrice = await this.getMethod('jsonrpc')('eth_gasPrice')
const gasLimit = await this.getMethod('jsonrpc')('eth_estimateGas', { from, to, value: ensure0x(value), data: ensure0x(data), gasPrice: ensure0x(gasPrice)})
const txParams = {
nonce: ensure0x(nonce),
gasPrice: ensure0x(gasPrice),
gasLimit: ensure0x(gasLimit),
to,
value: ensure0x(value),
data: ensure0x(data),
chainId: networkId
}
const tx = new EthereumTx(txParams)
tx.sign(this.wallet.getPrivateKey())
const serializedTx = tx.serialize()
const txHash = await this.getMethod('jsonrpc')('eth_sendRawTransaction', ensure0x(serializedTx.toString('hex')))
return remove0x(txHash)
}
if (to != null) {
to = ensure0x(to)
}
if (from == null) {
const addresses = await this.getAddresses()
from = ensure0x(addresses[0].address)
}
value = BigNumber(value).toString(16)
const nonce = (parseInt((await this.getMethod('jsonrpc')('eth_getTransactionCount', this.wallet.getAddressString(), 'pending')), 16)).toString(16)
console.log('nonce')
console.log(nonce)
const gasPrice = await this.getMethod('jsonrpc')('eth_gasPrice')
const gasLimit = await this.getMethod('jsonrpc')('eth_estimateGas', { from, to, value: ensure0x(value), data: ensure0x(data), gasPrice: ensure0x(gasPrice)})
const txParams = {
nonce: ensure0x(nonce),
gasPrice: ensure0x(gasPrice),
gasLimit: ensure0x(gasLimit),
to,
value: ensure0x(value),
data: ensure0x(data),
chainId: networkId
}
const tx = new EthereumTx(txParams)
tx.sign(this.wallet.getPrivateKey())
const serializedTx = tx.serialize()
const txHash = await this.getMethod('jsonrpc')('eth_sendRawTransaction', ensure0x(serializedTx.toString('hex')))
async sendTransaction (to, value, data, from) {
const networkId = await this.getWalletNetworkId()
if (this._network) {
if (networkId !== this._network.networkId) {
throw new Error('Invalid MetaMask Network')
}
}
if (!from) {
const addresses = await this.getAddresses()
from = addressToString(addresses[0])
}
const tx = {
from: ensure0x(from),
value: ensure0x(BigNumber(value).toString(16))
}
if (to) tx.to = ensure0x(addressToString(to))
if (data) tx.data = ensure0x(data)
const txHash = await this.metamask('eth_sendTransaction', tx)
return remove0x(txHash)
}
async sendTransaction (to, value, data, from) {
if (!from) {
const addresses = await this.getAddresses()
from = addresses[0]
}
const tx = {
from: ensure0x(addressToString(from)),
to: to ? ensure0x(addressToString(from)) : null,
value: ensure0x(BigNumber(value).toString(16))
}
if (to) tx.to = ensure0x(addressToString(to))
if (data) {
tx.data = ensure0x(data)
tx.gas = ensure0x((await this.estimateGas(tx)).toString(16))
}
const txHash = await this.jsonrpc('eth_sendTransaction', tx)
return remove0x(txHash)
}
addresses.map(address => this.getMethod('jsonrpc')(
'eth_call',
{
data: [
SOL_BALACE_OF_FUNCTION,
padHexStart(remove0x(address), 64)
].join('').toLowerCase(),
to: ensure0x(this._contractAddress).toLowerCase()
},
'latest'
))
)
async getBorrowerPubKey (contractAddress, block) {
const prefixFunctionSignature = '0xac6bd7e4'
const suffixFunctionSignature = '0x527a438f'
const prefixBorrowerPubKey = await this.getMethod('jsonrpc')('eth_call', { data: prefixFunctionSignature, to: ensure0x(contractAddress) }, ensureBlockFormat(block))
const suffixBorrowerPubKey = await this.getMethod('jsonrpc')('eth_call', { data: suffixFunctionSignature, to: ensure0x(contractAddress) }, ensureBlockFormat(block))
return padHexStart(parseInt(prefixBorrowerPubKey, 16).toString(16)) + suffixBorrowerPubKey
}
async getLenderPubKey (contractAddress) {
const prefixFunctionSignature = '0xac6bd7e4'
const suffixFunctionSignature = '0x527a438f'
const prefixLenderPubKey = await this.getMethod('jsonrpc')('eth_call', { data: prefixFunctionSignature, to: ensure0x(contractAddress) }, 'latest')
const suffixLenderPubKey = await this.getMethod('jsonrpc')('eth_call', { data: suffixFunctionSignature, to: ensure0x(contractAddress) }, 'latest')
return padHexStart(parseInt(prefixLenderPubKey, 16).toString(16)) + suffixLenderPubKey
}