web3-eth-contract
Advanced tools
Comparing version 4.5.1-dev.fd2982d.0 to 4.6.0
import { Web3Context, Web3EventEmitter, Web3PromiEvent } from 'web3-core'; | ||
import { NewHeadsSubscription, SendTransactionEvents } from 'web3-eth'; | ||
import { NewHeadsSubscription, SendTransactionEvents, TransactionMiddleware } from 'web3-eth'; | ||
import { AbiFunctionFragment, ContractAbi, ContractConstructorArgs, ContractEvent, ContractEvents, ContractMethod, ContractMethodInputParameters, ContractMethodOutputParameters, Address, EthExecutionAPI, Filter, FilterAbis, HexString, ContractInitOptions, PayableCallOptions, DataFormat, DEFAULT_RETURN_FORMAT, EventLog, ContractOptions, TransactionReceipt, FormatType, DecodedParams } from 'web3-types'; | ||
@@ -263,2 +263,3 @@ import { LogsSubscription } from './log_subscription.js'; | ||
readonly options: ContractOptions; | ||
private transactionMiddleware?; | ||
/** | ||
@@ -312,2 +313,4 @@ * Set to true if you want contracts' defaults to sync with global defaults. | ||
constructor(jsonInterface: Abi, address: Address | undefined, options: ContractInitOptions, contextOrReturnFormat?: Web3ContractContext | Web3Context | DataFormat, returnFormat?: DataFormat); | ||
setTransactionMiddleware(transactionMiddleware: TransactionMiddleware): void; | ||
getTransactionMiddleware(): TransactionMiddleware | undefined; | ||
/** | ||
@@ -314,0 +317,0 @@ * Subscribe to an event. |
@@ -341,2 +341,8 @@ "use strict"; | ||
} | ||
setTransactionMiddleware(transactionMiddleware) { | ||
this.transactionMiddleware = transactionMiddleware; | ||
} | ||
getTransactionMiddleware() { | ||
return this.transactionMiddleware; | ||
} | ||
/** | ||
@@ -753,2 +759,19 @@ * Subscribe to an event. | ||
send: (options) => this._contractMethodSend(methodAbi, abiParams, internalErrorsAbis, options), | ||
populateTransaction: (options, contractOptions) => { | ||
var _a, _b; | ||
let modifiedContractOptions = contractOptions !== null && contractOptions !== void 0 ? contractOptions : this.options; | ||
modifiedContractOptions = Object.assign(Object.assign({}, modifiedContractOptions), { input: undefined, from: (_b = (_a = modifiedContractOptions === null || modifiedContractOptions === void 0 ? void 0 : modifiedContractOptions.from) !== null && _a !== void 0 ? _a : this.defaultAccount) !== null && _b !== void 0 ? _b : undefined }); | ||
const tx = (0, utils_js_1.getSendTxParams)({ | ||
abi, | ||
params, | ||
options: Object.assign(Object.assign({}, options), { dataInputFill: this.config.contractDataInputFill }), | ||
contractOptions: modifiedContractOptions, | ||
}); | ||
// @ts-expect-error remove unnecessary field | ||
if (tx.dataInputFill) { | ||
// @ts-expect-error remove unnecessary field | ||
delete tx.dataInputFill; | ||
} | ||
return tx; | ||
}, | ||
estimateGas: (options, returnFormat = this | ||
@@ -828,7 +851,13 @@ .defaultReturnFormat) => __awaiter(this, void 0, void 0, function* () { | ||
}); | ||
const transactionToSend = (0, web3_eth_1.sendTransaction)(this, tx, this.defaultReturnFormat, { | ||
// TODO Should make this configurable by the user | ||
checkRevertBeforeSending: false, | ||
contractAbi: this._jsonInterface, | ||
}); | ||
const transactionToSend = ((0, web3_validator_1.isNullish)(this.transactionMiddleware)) ? | ||
(0, web3_eth_1.sendTransaction)(this, tx, this.defaultReturnFormat, { | ||
// TODO Should make this configurable by the user | ||
checkRevertBeforeSending: false, | ||
contractAbi: this._jsonInterface, // explicitly not passing middleware so if some one is using old eth package it will not break | ||
}) : | ||
(0, web3_eth_1.sendTransaction)(this, tx, this.defaultReturnFormat, { | ||
// TODO Should make this configurable by the user | ||
checkRevertBeforeSending: false, | ||
contractAbi: this._jsonInterface, | ||
}, this.transactionMiddleware); | ||
// eslint-disable-next-line no-void | ||
@@ -853,4 +882,4 @@ void transactionToSend.on('error', (error) => { | ||
}); | ||
return (0, web3_eth_1.sendTransaction)(this, tx, this.defaultReturnFormat, { | ||
transactionResolver: receipt => { | ||
const returnTxOptions = { | ||
transactionResolver: (receipt) => { | ||
if (receipt.status === BigInt(0)) { | ||
@@ -867,3 +896,6 @@ throw new web3_errors_1.Web3ContractError("code couldn't be stored", receipt); | ||
checkRevertBeforeSending: false, | ||
}); | ||
}; | ||
return (((0, web3_validator_1.isNullish)(this.transactionMiddleware)) ? | ||
(0, web3_eth_1.sendTransaction)(this, tx, this.defaultReturnFormat, returnTxOptions) : // not calling this with undefined Middleware because it will not break if Eth package is not updated | ||
(0, web3_eth_1.sendTransaction)(this, tx, this.defaultReturnFormat, returnTxOptions, this.transactionMiddleware)); | ||
} | ||
@@ -870,0 +902,0 @@ _contractMethodEstimateGas({ abi, params, returnFormat, options, contractOptions, }) { |
import { Web3ContextInitOptions, Web3PromiEvent } from 'web3-core'; | ||
import { AccessListResult, BlockNumberOrTag, EthExecutionAPI, HexString, Numbers, TransactionReceipt, NonPayableCallOptions, PayableCallOptions, DataFormat, DEFAULT_RETURN_FORMAT, FormatType } from 'web3-types'; | ||
import { AccessListResult, BlockNumberOrTag, EthExecutionAPI, HexString, Numbers, TransactionReceipt, NonPayableCallOptions, PayableCallOptions, DataFormat, DEFAULT_RETURN_FORMAT, FormatType, TransactionCall } from 'web3-types'; | ||
import { NewHeadsSubscription, SendTransactionEvents } from 'web3-eth'; | ||
import type { ContractOptions } from 'web3-types'; | ||
import { LogsSubscription } from './log_subscription.js'; | ||
export declare type NonPayableTxOptions = NonPayableCallOptions; | ||
export declare type PayableTxOptions = PayableCallOptions; | ||
export { ContractAbiWithSignature, EventLog, ContractOptions } from 'web3-types'; | ||
export type { ContractAbiWithSignature, EventLog, ContractOptions } from 'web3-types'; | ||
export interface ContractEventOptions { | ||
@@ -138,2 +139,3 @@ /** | ||
send(tx?: NonPayableTxOptions): Web3PromiEvent<FormatType<TransactionReceipt, typeof DEFAULT_RETURN_FORMAT>, SendTransactionEvents<typeof DEFAULT_RETURN_FORMAT>>; | ||
populateTransaction(tx?: PayableTxOptions | NonPayableTxOptions, contractOptions?: ContractOptions): TransactionCall; | ||
/** | ||
@@ -317,2 +319,8 @@ * Returns the amount of gas consumed by executing the method locally without creating a new transaction on the blockchain. | ||
/** | ||
* | ||
* @param tx | ||
* @param contractOptions | ||
*/ | ||
populateTransaction(tx?: PayableTxOptions | NonPayableTxOptions, contractOptions?: ContractOptions): TransactionCall; | ||
/** | ||
* Returns the amount of gas consumed by executing the method locally without creating a new transaction on the blockchain. | ||
@@ -319,0 +327,0 @@ * The returned amount can be used as a gas estimate for executing the transaction publicly. The actual gas used can be |
@@ -1,2 +0,2 @@ | ||
import { TransactionForAccessList, AbiFunctionFragment, TransactionWithSenderAPI, TransactionCall, HexString, Address, NonPayableCallOptions, PayableCallOptions, ContractOptions } from 'web3-types'; | ||
import { TransactionForAccessList, AbiFunctionFragment, TransactionWithSenderAPI, TransactionCall, HexString, Address, NonPayableCallOptions, PayableCallOptions, ContractOptions, Numbers } from 'web3-types'; | ||
export declare const getSendTxParams: ({ abi, params, options, contractOptions, }: { | ||
@@ -44,1 +44,3 @@ abi: AbiFunctionFragment; | ||
}) => TransactionForAccessList; | ||
export declare const createContractAddress: (from: Address, nonce: Numbers) => Address; | ||
export declare const create2ContractAddress: (from: Address, salt: HexString, initCode: HexString) => Address; |
@@ -19,5 +19,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getCreateAccessListParams = exports.isWeb3ContractContext = exports.getEstimateGasParams = exports.getEthTxCallParams = exports.getSendTxParams = void 0; | ||
exports.create2ContractAddress = exports.createContractAddress = exports.getCreateAccessListParams = exports.isWeb3ContractContext = exports.getEstimateGasParams = exports.getEthTxCallParams = exports.getSendTxParams = void 0; | ||
const rlp_1 = require("@ethereumjs/rlp"); | ||
const web3_errors_1 = require("web3-errors"); | ||
const web3_utils_1 = require("web3-utils"); | ||
const web3_validator_1 = require("web3-validator"); | ||
const encoding_js_1 = require("./encoding.js"); | ||
@@ -123,2 +125,30 @@ const dataInputEncodeMethodHelper = (txParams, abi, params, dataInputFill) => { | ||
exports.getCreateAccessListParams = getCreateAccessListParams; | ||
const createContractAddress = (from, nonce) => { | ||
if (!(0, web3_validator_1.isAddress)(from)) | ||
throw new web3_errors_1.InvalidAddressError(`Invalid address given ${from}`); | ||
let nonceValue = nonce; | ||
if (typeof nonce === "string" && (0, web3_validator_1.isHexString)(nonce)) | ||
nonceValue = (0, web3_utils_1.hexToNumber)(nonce); | ||
else if (typeof nonce === "string" && !(0, web3_validator_1.isHexString)(nonce)) | ||
throw new web3_errors_1.InvalidNumberError("Invalid nonce value format"); | ||
const rlpEncoded = rlp_1.RLP.encode([from, nonceValue]); | ||
const result = (0, web3_utils_1.keccak256)(rlpEncoded); | ||
const contractAddress = '0x'.concat(result.substring(26)); | ||
return (0, web3_utils_1.toChecksumAddress)(contractAddress); | ||
}; | ||
exports.createContractAddress = createContractAddress; | ||
const create2ContractAddress = (from, salt, initCode) => { | ||
if (!(0, web3_validator_1.isAddress)(from)) | ||
throw new web3_errors_1.InvalidAddressError(`Invalid address given ${from}`); | ||
if (!(0, web3_validator_1.isHexString)(salt)) | ||
throw new web3_errors_1.InvalidMethodParamsError(`Invalid salt value ${salt}`); | ||
if (!(0, web3_validator_1.isHexString)(initCode)) | ||
throw new web3_errors_1.InvalidMethodParamsError(`Invalid initCode value ${initCode}`); | ||
const initCodeHash = (0, web3_utils_1.keccak256)(initCode); | ||
const initCodeHashPadded = initCodeHash.padStart(64, '0'); // Pad to 32 bytes (64 hex characters) | ||
const create2Params = ['0xff', from, salt, initCodeHashPadded].map(x => x.replace(/0x/, '')); | ||
const create2Address = `0x${create2Params.join('')}`; | ||
return (0, web3_utils_1.toChecksumAddress)(`0x${(0, web3_utils_1.keccak256)(create2Address).slice(26)}`); // Slice to get the last 20 bytes (40 hex characters) & checksum | ||
}; | ||
exports.create2ContractAddress = create2ContractAddress; | ||
//# sourceMappingURL=utils.js.map |
@@ -338,2 +338,8 @@ /* | ||
} | ||
setTransactionMiddleware(transactionMiddleware) { | ||
this.transactionMiddleware = transactionMiddleware; | ||
} | ||
getTransactionMiddleware() { | ||
return this.transactionMiddleware; | ||
} | ||
/** | ||
@@ -750,2 +756,19 @@ * Subscribe to an event. | ||
send: (options) => this._contractMethodSend(methodAbi, abiParams, internalErrorsAbis, options), | ||
populateTransaction: (options, contractOptions) => { | ||
var _a, _b; | ||
let modifiedContractOptions = contractOptions !== null && contractOptions !== void 0 ? contractOptions : this.options; | ||
modifiedContractOptions = Object.assign(Object.assign({}, modifiedContractOptions), { input: undefined, from: (_b = (_a = modifiedContractOptions === null || modifiedContractOptions === void 0 ? void 0 : modifiedContractOptions.from) !== null && _a !== void 0 ? _a : this.defaultAccount) !== null && _b !== void 0 ? _b : undefined }); | ||
const tx = getSendTxParams({ | ||
abi, | ||
params, | ||
options: Object.assign(Object.assign({}, options), { dataInputFill: this.config.contractDataInputFill }), | ||
contractOptions: modifiedContractOptions, | ||
}); | ||
// @ts-expect-error remove unnecessary field | ||
if (tx.dataInputFill) { | ||
// @ts-expect-error remove unnecessary field | ||
delete tx.dataInputFill; | ||
} | ||
return tx; | ||
}, | ||
estimateGas: (options, returnFormat = this | ||
@@ -825,7 +848,13 @@ .defaultReturnFormat) => __awaiter(this, void 0, void 0, function* () { | ||
}); | ||
const transactionToSend = sendTransaction(this, tx, this.defaultReturnFormat, { | ||
// TODO Should make this configurable by the user | ||
checkRevertBeforeSending: false, | ||
contractAbi: this._jsonInterface, | ||
}); | ||
const transactionToSend = (isNullish(this.transactionMiddleware)) ? | ||
sendTransaction(this, tx, this.defaultReturnFormat, { | ||
// TODO Should make this configurable by the user | ||
checkRevertBeforeSending: false, | ||
contractAbi: this._jsonInterface, // explicitly not passing middleware so if some one is using old eth package it will not break | ||
}) : | ||
sendTransaction(this, tx, this.defaultReturnFormat, { | ||
// TODO Should make this configurable by the user | ||
checkRevertBeforeSending: false, | ||
contractAbi: this._jsonInterface, | ||
}, this.transactionMiddleware); | ||
// eslint-disable-next-line no-void | ||
@@ -850,4 +879,4 @@ void transactionToSend.on('error', (error) => { | ||
}); | ||
return sendTransaction(this, tx, this.defaultReturnFormat, { | ||
transactionResolver: receipt => { | ||
const returnTxOptions = { | ||
transactionResolver: (receipt) => { | ||
if (receipt.status === BigInt(0)) { | ||
@@ -864,3 +893,6 @@ throw new Web3ContractError("code couldn't be stored", receipt); | ||
checkRevertBeforeSending: false, | ||
}); | ||
}; | ||
return ((isNullish(this.transactionMiddleware)) ? | ||
sendTransaction(this, tx, this.defaultReturnFormat, returnTxOptions) : // not calling this with undefined Middleware because it will not break if Eth package is not updated | ||
sendTransaction(this, tx, this.defaultReturnFormat, returnTxOptions, this.transactionMiddleware)); | ||
} | ||
@@ -867,0 +899,0 @@ _contractMethodEstimateGas({ abi, params, returnFormat, options, contractOptions, }) { |
@@ -17,4 +17,6 @@ /* | ||
*/ | ||
import { Web3ContractError } from 'web3-errors'; | ||
import { isNullish, mergeDeep, isContractInitOptions } from 'web3-utils'; | ||
import { RLP } from '@ethereumjs/rlp'; | ||
import { InvalidAddressError, InvalidMethodParamsError, InvalidNumberError, Web3ContractError } from 'web3-errors'; | ||
import { isNullish, mergeDeep, isContractInitOptions, keccak256, toChecksumAddress, hexToNumber } from 'web3-utils'; | ||
import { isAddress, isHexString } from 'web3-validator'; | ||
import { encodeMethodABI } from './encoding.js'; | ||
@@ -115,2 +117,28 @@ const dataInputEncodeMethodHelper = (txParams, abi, params, dataInputFill) => { | ||
}; | ||
export const createContractAddress = (from, nonce) => { | ||
if (!isAddress(from)) | ||
throw new InvalidAddressError(`Invalid address given ${from}`); | ||
let nonceValue = nonce; | ||
if (typeof nonce === "string" && isHexString(nonce)) | ||
nonceValue = hexToNumber(nonce); | ||
else if (typeof nonce === "string" && !isHexString(nonce)) | ||
throw new InvalidNumberError("Invalid nonce value format"); | ||
const rlpEncoded = RLP.encode([from, nonceValue]); | ||
const result = keccak256(rlpEncoded); | ||
const contractAddress = '0x'.concat(result.substring(26)); | ||
return toChecksumAddress(contractAddress); | ||
}; | ||
export const create2ContractAddress = (from, salt, initCode) => { | ||
if (!isAddress(from)) | ||
throw new InvalidAddressError(`Invalid address given ${from}`); | ||
if (!isHexString(salt)) | ||
throw new InvalidMethodParamsError(`Invalid salt value ${salt}`); | ||
if (!isHexString(initCode)) | ||
throw new InvalidMethodParamsError(`Invalid initCode value ${initCode}`); | ||
const initCodeHash = keccak256(initCode); | ||
const initCodeHashPadded = initCodeHash.padStart(64, '0'); // Pad to 32 bytes (64 hex characters) | ||
const create2Params = ['0xff', from, salt, initCodeHashPadded].map(x => x.replace(/0x/, '')); | ||
const create2Address = `0x${create2Params.join('')}`; | ||
return toChecksumAddress(`0x${keccak256(create2Address).slice(26)}`); // Slice to get the last 20 bytes (40 hex characters) & checksum | ||
}; | ||
//# sourceMappingURL=utils.js.map |
import { Web3Context, Web3EventEmitter, Web3PromiEvent } from 'web3-core'; | ||
import { NewHeadsSubscription, SendTransactionEvents } from 'web3-eth'; | ||
import { NewHeadsSubscription, SendTransactionEvents, TransactionMiddleware } from 'web3-eth'; | ||
import { AbiFunctionFragment, ContractAbi, ContractConstructorArgs, ContractEvent, ContractEvents, ContractMethod, ContractMethodInputParameters, ContractMethodOutputParameters, Address, EthExecutionAPI, Filter, FilterAbis, HexString, ContractInitOptions, PayableCallOptions, DataFormat, DEFAULT_RETURN_FORMAT, EventLog, ContractOptions, TransactionReceipt, FormatType, DecodedParams } from 'web3-types'; | ||
@@ -263,2 +263,3 @@ import { LogsSubscription } from './log_subscription.js'; | ||
readonly options: ContractOptions; | ||
private transactionMiddleware?; | ||
/** | ||
@@ -312,2 +313,4 @@ * Set to true if you want contracts' defaults to sync with global defaults. | ||
constructor(jsonInterface: Abi, address: Address | undefined, options: ContractInitOptions, contextOrReturnFormat?: Web3ContractContext | Web3Context | DataFormat, returnFormat?: DataFormat); | ||
setTransactionMiddleware(transactionMiddleware: TransactionMiddleware): void; | ||
getTransactionMiddleware(): TransactionMiddleware | undefined; | ||
/** | ||
@@ -314,0 +317,0 @@ * Subscribe to an event. |
import { Web3ContextInitOptions, Web3PromiEvent } from 'web3-core'; | ||
import { AccessListResult, BlockNumberOrTag, EthExecutionAPI, HexString, Numbers, TransactionReceipt, NonPayableCallOptions, PayableCallOptions, DataFormat, DEFAULT_RETURN_FORMAT, FormatType } from 'web3-types'; | ||
import { AccessListResult, BlockNumberOrTag, EthExecutionAPI, HexString, Numbers, TransactionReceipt, NonPayableCallOptions, PayableCallOptions, DataFormat, DEFAULT_RETURN_FORMAT, FormatType, TransactionCall } from 'web3-types'; | ||
import { NewHeadsSubscription, SendTransactionEvents } from 'web3-eth'; | ||
import type { ContractOptions } from 'web3-types'; | ||
import { LogsSubscription } from './log_subscription.js'; | ||
export declare type NonPayableTxOptions = NonPayableCallOptions; | ||
export declare type PayableTxOptions = PayableCallOptions; | ||
export { ContractAbiWithSignature, EventLog, ContractOptions } from 'web3-types'; | ||
export type { ContractAbiWithSignature, EventLog, ContractOptions } from 'web3-types'; | ||
export interface ContractEventOptions { | ||
@@ -138,2 +139,3 @@ /** | ||
send(tx?: NonPayableTxOptions): Web3PromiEvent<FormatType<TransactionReceipt, typeof DEFAULT_RETURN_FORMAT>, SendTransactionEvents<typeof DEFAULT_RETURN_FORMAT>>; | ||
populateTransaction(tx?: PayableTxOptions | NonPayableTxOptions, contractOptions?: ContractOptions): TransactionCall; | ||
/** | ||
@@ -317,2 +319,8 @@ * Returns the amount of gas consumed by executing the method locally without creating a new transaction on the blockchain. | ||
/** | ||
* | ||
* @param tx | ||
* @param contractOptions | ||
*/ | ||
populateTransaction(tx?: PayableTxOptions | NonPayableTxOptions, contractOptions?: ContractOptions): TransactionCall; | ||
/** | ||
* Returns the amount of gas consumed by executing the method locally without creating a new transaction on the blockchain. | ||
@@ -319,0 +327,0 @@ * The returned amount can be used as a gas estimate for executing the transaction publicly. The actual gas used can be |
@@ -1,2 +0,2 @@ | ||
import { TransactionForAccessList, AbiFunctionFragment, TransactionWithSenderAPI, TransactionCall, HexString, Address, NonPayableCallOptions, PayableCallOptions, ContractOptions } from 'web3-types'; | ||
import { TransactionForAccessList, AbiFunctionFragment, TransactionWithSenderAPI, TransactionCall, HexString, Address, NonPayableCallOptions, PayableCallOptions, ContractOptions, Numbers } from 'web3-types'; | ||
export declare const getSendTxParams: ({ abi, params, options, contractOptions, }: { | ||
@@ -44,2 +44,4 @@ abi: AbiFunctionFragment; | ||
}) => TransactionForAccessList; | ||
export declare const createContractAddress: (from: Address, nonce: Numbers) => Address; | ||
export declare const create2ContractAddress: (from: Address, salt: HexString, initCode: HexString) => Address; | ||
//# sourceMappingURL=utils.d.ts.map |
{ | ||
"name": "web3-eth-contract", | ||
"version": "4.5.1-dev.fd2982d.0+fd2982d", | ||
"version": "4.6.0", | ||
"description": "Web3 module to interact with Ethereum smart contracts.", | ||
@@ -48,9 +48,10 @@ "main": "./lib/commonjs/index.js", | ||
"dependencies": { | ||
"web3-core": "4.4.1-dev.fd2982d.0+fd2982d", | ||
"web3-errors": "1.2.1-dev.fd2982d.0+fd2982d", | ||
"web3-eth": "4.7.1-dev.fd2982d.0+fd2982d", | ||
"web3-eth-abi": "4.2.3-dev.fd2982d.0+fd2982d", | ||
"web3-types": "1.6.1-dev.fd2982d.0+fd2982d", | ||
"web3-utils": "4.3.1-dev.fd2982d.0+fd2982d", | ||
"web3-validator": "2.0.7-dev.fd2982d.0+fd2982d" | ||
"@ethereumjs/rlp": "^5.0.2", | ||
"web3-core": "^4.5.0", | ||
"web3-errors": "^1.2.0", | ||
"web3-eth": "^4.8.1", | ||
"web3-eth-abi": "^4.2.3", | ||
"web3-types": "^1.7.0", | ||
"web3-utils": "^4.3.1", | ||
"web3-validator": "^2.0.6" | ||
}, | ||
@@ -72,6 +73,6 @@ "devDependencies": { | ||
"typescript": "^4.7.4", | ||
"web3-eth-accounts": "4.1.3-dev.fd2982d.0+fd2982d", | ||
"web3-providers-ws": "4.0.8-dev.fd2982d.0+fd2982d" | ||
"web3-eth-accounts": "^4.1.3", | ||
"web3-providers-ws": "^4.0.8" | ||
}, | ||
"gitHead": "fd2982d1afacd6bf89084324b478ec04af18052e" | ||
"gitHead": "2b6f7f5435230d860f55766f2d2a3c1358227e4f" | ||
} |
@@ -42,2 +42,4 @@ /* | ||
SendTransactionEvents, | ||
TransactionMiddleware, | ||
SendTransactionOptions, | ||
} from 'web3-eth'; | ||
@@ -437,3 +439,3 @@ import { | ||
public readonly options: ContractOptions; | ||
private transactionMiddleware?: TransactionMiddleware; | ||
/** | ||
@@ -645,2 +647,10 @@ * Set to true if you want contracts' defaults to sync with global defaults. | ||
public setTransactionMiddleware(transactionMiddleware: TransactionMiddleware) { | ||
this.transactionMiddleware = transactionMiddleware; | ||
} | ||
public getTransactionMiddleware() { | ||
return this.transactionMiddleware; | ||
} | ||
/** | ||
@@ -1274,3 +1284,25 @@ * Subscribe to an event. | ||
this._contractMethodSend(methodAbi, abiParams, internalErrorsAbis, options), | ||
populateTransaction: ( | ||
options?: PayableTxOptions | NonPayableTxOptions, | ||
contractOptions?: ContractOptions, | ||
) => { | ||
let modifiedContractOptions = contractOptions ?? this.options; | ||
modifiedContractOptions = { | ||
...modifiedContractOptions, | ||
input: undefined, | ||
from: modifiedContractOptions?.from ?? this.defaultAccount ?? undefined, | ||
}; | ||
const tx = getSendTxParams({ | ||
abi, | ||
params, | ||
options: { ...options, dataInputFill: this.config.contractDataInputFill }, | ||
contractOptions: modifiedContractOptions, | ||
}); | ||
// @ts-expect-error remove unnecessary field | ||
if (tx.dataInputFill) { | ||
// @ts-expect-error remove unnecessary field | ||
delete tx.dataInputFill; | ||
} | ||
return tx; | ||
}, | ||
estimateGas: async <ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>( | ||
@@ -1403,7 +1435,13 @@ options?: PayableCallOptions | NonPayableCallOptions, | ||
const transactionToSend = sendTransaction(this, tx, this.defaultReturnFormat, { | ||
// TODO Should make this configurable by the user | ||
checkRevertBeforeSending: false, | ||
contractAbi: this._jsonInterface, | ||
}); | ||
const transactionToSend = (isNullish(this.transactionMiddleware)) ? | ||
sendTransaction(this, tx, this.defaultReturnFormat, { | ||
// TODO Should make this configurable by the user | ||
checkRevertBeforeSending: false, | ||
contractAbi: this._jsonInterface, // explicitly not passing middleware so if some one is using old eth package it will not break | ||
}) : | ||
sendTransaction(this, tx, this.defaultReturnFormat, { | ||
// TODO Should make this configurable by the user | ||
checkRevertBeforeSending: false, | ||
contractAbi: this._jsonInterface, | ||
}, this.transactionMiddleware); | ||
@@ -1437,4 +1475,5 @@ // eslint-disable-next-line no-void | ||
}); | ||
return sendTransaction(this, tx, this.defaultReturnFormat, { | ||
transactionResolver: receipt => { | ||
const returnTxOptions: SendTransactionOptions<Contract<Abi>> = { | ||
transactionResolver: (receipt: TransactionReceipt) => { | ||
if (receipt.status === BigInt(0)) { | ||
@@ -1453,3 +1492,8 @@ throw new Web3ContractError("code couldn't be stored", receipt); | ||
checkRevertBeforeSending: false, | ||
}); | ||
}; | ||
return ( | ||
(isNullish(this.transactionMiddleware)) ? | ||
sendTransaction(this, tx, this.defaultReturnFormat, returnTxOptions) : // not calling this with undefined Middleware because it will not break if Eth package is not updated | ||
sendTransaction(this, tx, this.defaultReturnFormat, returnTxOptions, this.transactionMiddleware)); | ||
} | ||
@@ -1456,0 +1500,0 @@ |
@@ -31,4 +31,6 @@ /* | ||
FormatType, | ||
TransactionCall, | ||
} from 'web3-types'; | ||
import { NewHeadsSubscription, SendTransactionEvents } from 'web3-eth'; | ||
import type { ContractOptions } from 'web3-types'; | ||
import { LogsSubscription } from './log_subscription.js'; | ||
@@ -38,3 +40,3 @@ | ||
export type PayableTxOptions = PayableCallOptions; | ||
export { ContractAbiWithSignature, EventLog, ContractOptions } from 'web3-types'; | ||
export type { ContractAbiWithSignature, EventLog, ContractOptions } from 'web3-types'; | ||
@@ -182,2 +184,6 @@ export interface ContractEventOptions { | ||
>; | ||
populateTransaction( | ||
tx?: PayableTxOptions | NonPayableTxOptions, | ||
contractOptions?: ContractOptions, | ||
): TransactionCall; | ||
@@ -382,2 +388,11 @@ /** | ||
/** | ||
* | ||
* @param tx | ||
* @param contractOptions | ||
*/ | ||
populateTransaction( | ||
tx?: PayableTxOptions | NonPayableTxOptions, | ||
contractOptions?: ContractOptions, | ||
): TransactionCall; | ||
/** | ||
* Returns the amount of gas consumed by executing the method locally without creating a new transaction on the blockchain. | ||
@@ -384,0 +399,0 @@ * The returned amount can be used as a gas estimate for executing the transaction publicly. The actual gas used can be |
@@ -18,3 +18,4 @@ /* | ||
import { Web3ContractError } from 'web3-errors'; | ||
import { RLP } from '@ethereumjs/rlp'; | ||
import { InvalidAddressError, InvalidMethodParamsError, InvalidNumberError, Web3ContractError } from 'web3-errors'; | ||
import { | ||
@@ -30,4 +31,6 @@ TransactionForAccessList, | ||
ContractOptions, | ||
Numbers, | ||
} from 'web3-types'; | ||
import { isNullish, mergeDeep, isContractInitOptions } from 'web3-utils'; | ||
import { isNullish, mergeDeep, isContractInitOptions, keccak256, toChecksumAddress, hexToNumber } from 'web3-utils'; | ||
import { isAddress, isHexString } from 'web3-validator'; | ||
import { encodeMethodABI } from './encoding.js'; | ||
@@ -215,1 +218,40 @@ import { Web3ContractContext } from './types.js'; | ||
}; | ||
export const createContractAddress = (from: Address, nonce: Numbers): Address => { | ||
if(!isAddress(from)) | ||
throw new InvalidAddressError(`Invalid address given ${from}`); | ||
let nonceValue = nonce; | ||
if(typeof nonce === "string" && isHexString(nonce)) | ||
nonceValue = hexToNumber(nonce); | ||
else if(typeof nonce === "string" && !isHexString(nonce)) | ||
throw new InvalidNumberError("Invalid nonce value format"); | ||
const rlpEncoded = RLP.encode( | ||
[from, nonceValue] | ||
); | ||
const result = keccak256(rlpEncoded); | ||
const contractAddress = '0x'.concat(result.substring(26)); | ||
return toChecksumAddress(contractAddress); | ||
} | ||
export const create2ContractAddress = (from: Address, salt: HexString, initCode: HexString): Address => { | ||
if(!isAddress(from)) | ||
throw new InvalidAddressError(`Invalid address given ${from}`); | ||
if(!isHexString(salt)) | ||
throw new InvalidMethodParamsError(`Invalid salt value ${salt}`); | ||
if(!isHexString(initCode)) | ||
throw new InvalidMethodParamsError(`Invalid initCode value ${initCode}`); | ||
const initCodeHash = keccak256(initCode); | ||
const initCodeHashPadded = initCodeHash.padStart(64, '0'); // Pad to 32 bytes (64 hex characters) | ||
const create2Params = ['0xff', from, salt, initCodeHashPadded].map(x => x.replace(/0x/, '')); | ||
const create2Address = `0x${ create2Params.join('')}`; | ||
return toChecksumAddress(`0x${ keccak256(create2Address).slice(26)}`); // Slice to get the last 20 bytes (40 hex characters) & checksum | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
418839
7602
1
0
8
+ Added@ethereumjs/rlp@^5.0.2
+ Added@ethereumjs/rlp@4.0.15.0.2(transitive)
+ Added@noble/curves@1.4.2(transitive)
+ Added@noble/hashes@1.4.0(transitive)
+ Added@scure/base@1.1.7(transitive)
+ Added@scure/bip32@1.4.0(transitive)
+ Added@scure/bip39@1.3.0(transitive)
+ Added@types/node@22.4.0(transitive)
+ Added@types/ws@8.5.3(transitive)
+ Addedabitype@0.7.1(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedcrc-32@1.2.2(transitive)
+ Addedcross-fetch@4.0.0(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedethereum-cryptography@2.2.1(transitive)
+ Addedeventemitter3@5.0.1(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-arguments@1.1.1(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-generator-function@1.0.10(transitive)
+ Addedis-typed-array@1.1.13(transitive)
+ Addedisomorphic-ws@5.0.0(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedsetimmediate@1.0.5(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedtypescript@5.5.4(transitive)
+ Addedundici-types@6.19.6(transitive)
+ Addedutil@0.12.5(transitive)
+ Addedweb3-core@4.5.0(transitive)
+ Addedweb3-errors@1.2.1(transitive)
+ Addedweb3-eth@4.8.2(transitive)
+ Addedweb3-eth-abi@4.2.3(transitive)
+ Addedweb3-eth-accounts@4.1.3(transitive)
+ Addedweb3-eth-iban@4.0.7(transitive)
+ Addedweb3-net@4.1.0(transitive)
+ Addedweb3-providers-http@4.1.0(transitive)
+ Addedweb3-providers-ipc@4.0.7(transitive)
+ Addedweb3-providers-ws@4.0.8(transitive)
+ Addedweb3-rpc-methods@1.3.0(transitive)
+ Addedweb3-types@1.7.0(transitive)
+ Addedweb3-utils@4.3.1(transitive)
+ Addedweb3-validator@2.0.6(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
+ Addedwhich-typed-array@1.1.15(transitive)
+ Addedws@8.18.0(transitive)
+ Addedzod@3.23.8(transitive)
Updatedweb3-core@^4.5.0
Updatedweb3-errors@^1.2.0
Updatedweb3-eth@^4.8.1
Updatedweb3-eth-abi@^4.2.3
Updatedweb3-types@^1.7.0
Updatedweb3-utils@^4.3.1
Updatedweb3-validator@^2.0.6