Skip to main content

web3-eth-contract

The web3.eth.Contract object makes it easy to interact with smart contracts on the Ethereum blockchain. When you create a new contract object you give it the JSON interface of the respective smart contract and web3 will auto convert all calls into low level ABI calls over RPC for you. This allows you to interact with smart contracts as if they were JavaScript objects.

To use it standalone:

const Contract = require('web3-eth-contract');

// set provider for all later instances to use
Contract.setProvider('ws://localhost:8546');

const contract = new Contract(jsonInterface, address);

contract.methods.somFunc().send({from: ....})
.on('receipt', function(){
...
});

Index

References

default

Renames and re-exports Contract

Type Aliases

ContractAbiWithSignature

ContractAbiWithSignature: ReadonlyArray<AbiFragment & { signature: HexString }>

ContractBoundEvent

ContractBoundEvent: (options?: ContractEventOptions) => LogsSubscription

Type declaration

    • The event object can be accessed from myContract.events.myEvent.

      &gt; Remember: To subscribe to an event, your provider must have support for subscriptions.

      const subscription = await myContract.events.MyEvent([options])

      Parameters

      Returns LogsSubscription

      • A Promise resolved with LogsSubscription object

ContractEventEmitterInterface

ContractEventEmitterInterface<Abi>: { [ EventAbi in FilterAbis<Abi, AbiFunctionFragment & { type: event }> as EventAbi[name] ]: ContractEvent<EventAbi>[Inputs] }

Type parameters

ContractEventsInterface

ContractEventsInterface<Abi, Events>: { [ Name in keyof Events | allEvents ]: ContractBoundEvent } & {}

Type parameters

ContractMethodsInterface

ContractMethodsInterface<Abi>: { [ MethodAbi in FilterAbis<Abi, AbiFunctionFragment & { type: function }> as MethodAbi[name] ]: ContractBoundMethod<MethodAbi> } & {}

Type parameters

ContractOverloadedMethodInputs

ContractOverloadedMethodInputs<AbiArr>: NonNullable<AbiArr extends readonly [] ? undefined : AbiArr extends readonly [infer A, ...infer R] ? A extends AbiFunctionFragment ? ContractMethodInputParameters<A[inputs]> | ContractOverloadedMethodInputs<R> : undefined : undefined>

Type parameters

  • AbiArr: ReadonlyArray<unknown>

ContractOverloadedMethodOutputs

ContractOverloadedMethodOutputs<AbiArr>: NonNullable<AbiArr extends readonly [] ? undefined : AbiArr extends readonly [infer A, ...infer R] ? A extends AbiFunctionFragment ? ContractMethodOutputParameters<A[outputs]> | ContractOverloadedMethodOutputs<R> : undefined : undefined>

Type parameters

  • AbiArr: ReadonlyArray<unknown>

NonPayableTxOptions

NonPayableTxOptions: NonPayableCallOptions

PayableTxOptions

PayableTxOptions: PayableCallOptions

Web3ContractContext

Web3ContractContext: Partial<Web3ContextInitOptions<EthExecutionAPI, { logs: typeof LogsSubscription; newBlockHeaders: typeof NewHeadsSubscription; newHeads: typeof NewHeadsSubscription }>>