Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing chainId when send raw tx #665

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions deploy/src/deploymentUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const {
HOME_EXPLORER_URL,
FOREIGN_EXPLORER_URL,
HOME_EXPLORER_API_KEY,
FOREIGN_EXPLORER_API_KEY
FOREIGN_EXPLORER_API_KEY,
HOME_CHAIN_ID,
FOREIGN_CHAIN_ID
} = require('./web3')
const verifier = require('./utils/verifier')

Expand All @@ -29,18 +31,21 @@ async function deployContract(contractJson, args, { from, network, nonce }) {
let gasPrice
let apiUrl
let apiKey
let chainId
if (network === 'foreign') {
web3 = web3Foreign
url = FOREIGN_RPC_URL
gasPrice = FOREIGN_DEPLOYMENT_GAS_PRICE
apiUrl = FOREIGN_EXPLORER_URL
apiKey = FOREIGN_EXPLORER_API_KEY
chainId = FOREIGN_CHAIN_ID
} else {
web3 = web3Home
url = HOME_RPC_URL
gasPrice = HOME_DEPLOYMENT_GAS_PRICE
apiUrl = HOME_EXPLORER_URL
apiKey = HOME_EXPLORER_API_KEY
chainId = HOME_CHAIN_ID
}
const options = {
from
Expand All @@ -58,7 +63,8 @@ async function deployContract(contractJson, args, { from, network, nonce }) {
to: null,
privateKey: deploymentPrivateKey,
url,
gasPrice
gasPrice,
chainId
})
if (Web3Utils.hexToNumber(tx.status) !== 1 && !tx.contractAddress) {
throw new Error('Tx failed')
Expand All @@ -80,18 +86,20 @@ async function deployContract(contractJson, args, { from, network, nonce }) {
async function sendRawTxHome(options) {
return sendRawTx({
...options,
chainId: HOME_CHAIN_ID,
gasPrice: HOME_DEPLOYMENT_GAS_PRICE
})
}

async function sendRawTxForeign(options) {
return sendRawTx({
...options,
chainId: FOREIGN_CHAIN_ID,
gasPrice: FOREIGN_DEPLOYMENT_GAS_PRICE
})
}

async function sendRawTx({ data, nonce, to, privateKey, url, gasPrice, value }) {
async function sendRawTx({ data, nonce, to, privateKey, url, gasPrice, value, chainId }) {
try {
const txToEstimateGas = {
from: privateKeyToAddress(Web3Utils.bytesToHex(privateKey)),
Expand Down Expand Up @@ -121,7 +129,8 @@ async function sendRawTx({ data, nonce, to, privateKey, url, gasPrice, value })
gasLimit: Web3Utils.toHex(gas),
to,
data,
value
value,
chainId
}

const tx = new Tx(rawTx)
Expand Down
4 changes: 3 additions & 1 deletion deploy/src/loadEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ let validations = {
FOREIGN_BRIDGE_OWNER: addressValidator(),
FOREIGN_UPGRADEABLE_ADMIN: addressValidator(),
HOME_MAX_AMOUNT_PER_TX: bigNumValidator(),
FOREIGN_MAX_AMOUNT_PER_TX: bigNumValidator()
FOREIGN_MAX_AMOUNT_PER_TX: bigNumValidator(),
HOME_CHAIN_ID: envalid.num(),
FOREIGN_CHAIN_ID: envalid.num(),
}

if (BRIDGE_MODE.includes('AMB_')) {
Expand Down
8 changes: 6 additions & 2 deletions deploy/src/web3.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const {
HOME_EXPLORER_URL,
FOREIGN_EXPLORER_URL,
HOME_EXPLORER_API_KEY,
FOREIGN_EXPLORER_API_KEY
FOREIGN_EXPLORER_API_KEY,
HOME_CHAIN_ID,
FOREIGN_CHAIN_ID
} = env

const homeProvider = new Web3.providers.HttpProvider(HOME_RPC_URL)
Expand All @@ -36,5 +38,7 @@ module.exports = {
HOME_EXPLORER_URL,
FOREIGN_EXPLORER_URL,
HOME_EXPLORER_API_KEY,
FOREIGN_EXPLORER_API_KEY
FOREIGN_EXPLORER_API_KEY,
HOME_CHAIN_ID,
FOREIGN_CHAIN_ID
}