parent
2e8b90110a
commit
826e9443f6
@ -1,15 +1,21 @@ |
||||
import { |
||||
soliditySha3 |
||||
} from 'web3-utils'; |
||||
keccak256 as solidityKeccak256 |
||||
} from 'ethers/utils/solidity.js'; |
||||
|
||||
|
||||
export function keccak256(params) { |
||||
const types = []; |
||||
const values = []; |
||||
if (!Array.isArray(params)) { |
||||
params = [{ |
||||
type: 'string', |
||||
value: params |
||||
}]; |
||||
types.push('string'); |
||||
values.push(params); |
||||
}else { |
||||
params.forEach(p => { |
||||
types.push(p.type); |
||||
values.push(p.value); |
||||
}); |
||||
} |
||||
return soliditySha3(...params); |
||||
return solidityKeccak256(types, values); |
||||
} |
||||
|
||||
export const SIGN_PREFIX = '\x19Ethereum Signed Message:\n32'; |
||||
|
@ -1,24 +1,18 @@ |
||||
import * as Web3EthContract from 'web3-eth-contract'; |
||||
import Contract from 'ethers/contracts/contract.js'; |
||||
|
||||
export default function txDataByCompiled( |
||||
abi, |
||||
bytecode, |
||||
args |
||||
) { |
||||
|
||||
// solc returns a string which is often passed instead of the json
|
||||
if (typeof abi === 'string') abi = JSON.parse(abi); |
||||
|
||||
const web3Contract = new Web3EthContract.default( |
||||
const deployTransaction = Contract.getDeployTransaction( |
||||
'0x' + bytecode, |
||||
abi, |
||||
null, { |
||||
data: '0x' + bytecode |
||||
} |
||||
...args |
||||
); |
||||
|
||||
const createCode = web3Contract.deploy({ |
||||
arguments: args |
||||
}).encodeABI(); |
||||
|
||||
return createCode; |
||||
return deployTransaction.data; |
||||
} |
||||
|
Loading…
Reference in new issue