Skip to main content
Version: near-api-js@1.1.0

Class: Contract

contract.Contract

Defines a smart contract on NEAR including the change (mutable) and view (non-mutable) methods

See

https://docs.near.org/tools/near-api-js/quick-reference#contract

Example

import { Contract } from 'near-api-js';

async function contractExample() {
const methodOptions = {
viewMethods: ['getMessageByAccountId'],
changeMethods: ['addMessage']
};
const contract = new Contract(
wallet.account(),
'contract-id.testnet',
methodOptions
);

// use a contract view method
const messages = await contract.getMessages({
accountId: 'example-account.testnet'
});

// use a contract change method
await contract.addMessage({
meta: 'some info',
callbackUrl: 'https://example.com/callback',
args: { text: 'my message' },
amount: 1
})
}

Constructors

constructor

new Contract(account, contractId, options)

Parameters

NameTypeDescription
accountAccountNEAR account to sign change method transactions
contractIdstringNEAR account id where the contract is deployed
optionsContractMethodsNEAR smart contract methods that your application will use. These will be available as contract.methodName

Defined in

contract.ts:90

Properties

account

Readonly account: Account

Defined in

contract.ts:82


contractId

Readonly contractId: string

Defined in

contract.ts:83

Methods

_changeMethod

Private _changeMethod(__namedParameters): Promise<any>

Parameters

NameType
__namedParametersChangeMethodOptions

Returns

Promise<any>

Defined in

contract.ts:132