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
| Name | Type | Description |
|---|---|---|
account | Account | NEAR account to sign change method transactions |
contractId | string | NEAR account id where the contract is deployed |
options | ContractMethods | NEAR smart contract methods that your application will use. These will be available as contract.methodName |
Defined in
Properties
account
Readonly account: Account
Defined in
contractId
Readonly contractId: string
Defined in
Methods
_changeMethod
Private _changeMethod(__namedParameters): Promise<any>
Parameters
| Name | Type |
|---|---|
__namedParameters | ChangeMethodOptions |
Returns
Promise<any>