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

Properties

account?: Account

Deprecated

connection: Connection
contractId: string

Methods

  • Parameters

    • __namedParameters: ChangeMethodOptions

    Returns Promise<string | number | object>