AppClient
AppClient
Section titled “AppClient”High-level client for interacting with a specific Algorand smart contract application.
Creating an AppClient
Section titled “Creating an AppClient”From app ID
Section titled “From app ID”const appClient = algorand.client.getAppClientById({ appId: 1234n, appSpec: myAppSpec,});From creator address
Section titled “From creator address”const appClient = algorand.client.getAppClientByCreatorAndName({ creatorAddress: creator.addr, appSpec: myAppSpec,});Methods
Section titled “Methods”send.call(params)
Section titled “send.call(params)”Calls a method on the smart contract.
| Parameter | Type | Description |
|---|---|---|
params.method | string | ABI method name |
params.args | any[] | Method arguments |
params.sender | TransactionSignerAccount | Transaction sender |
const result = await appClient.send.call({ method: 'hello', args: ['World'], sender: myAccount,});console.log(result.return); // "Hello, World"send.optIn(params)
Section titled “send.optIn(params)”Opts the sender into the application.
await appClient.send.optIn({ sender: myAccount });send.closeOut(params)
Section titled “send.closeOut(params)”Closes out the sender from the application.
await appClient.send.closeOut({ sender: myAccount });getGlobalState()
Section titled “getGlobalState()”Gets the current global state of the application.
const state = await appClient.getGlobalState();getLocalState(address)
Section titled “getLocalState(address)”Gets the local state for a specific account.
const state = await appClient.getLocalState(myAccount.addr);