It will be removed in the next major release, please switch to TypedContract with type-safe ABI support
Defines a smart contract on NEAR including the change (mutable) and view (non-mutable) methods
https://docs.near.org/tools/near-api-js/quick-reference#contract
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 })} Copy
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 })}
NEAR account id where the contract is deployed
NEAR smart contract methods that your application will use. These will be available as contract.methodName
contract.methodName
Optional
Readonly
Deprecated
It will be removed in the next major release, please switch to TypedContract with type-safe ABI support
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