Skip to content

contract.exec.*

Submit a contract transaction.

Usage

example.ts
import * as fs from 'node:fs'
import { getContract } from '@phala/sdk'
import { client, provider } from './setup'
 
const abi = fs.readFileSync('path/to/abi.json', 'utf-8')
const contract = await getContract({
  client,
  contractId: '0x...',
  abi,
  provider, // It's required
})
 
await contract.exec.setRemark({
  args: ['Hi Remark'],
})

Parameters

args (optional)

any[]

args is the arguments for the transaction.

waitFinalized (optional)

() => Promise<boolean> | true

waitFinalized can be truly value or a function that returns a promise of a boolean value.

If it's a function, it will check customized condition to be met or not. It will runs every one second, once it returns true in 120 secs or the PRuntime node finalized 10 blocks, the waitFinalized will resolve. Otherwise it will throws an error.

If it's a truly value, it will wait for 120 secs or the PRuntime node finalized 10 blocks.

gasLimit (optional)

number

The maximum amount of gas to use for the transaction. The transaction will failed if the gas used exceed the gasLimit. If not specified, the transaction will always failed. It will use token in the cluster balance.

storageDepositLimit (optional)

number

The maximum amount of storage deposit to use for the transaction. The transaction will failed it the storage for the contract has been increased. It will use token in the cluster balance.

value (optional)

number

The amount of token to transfer to the contract. If not specified, it will use 0. It will use token in the user balance.

deposit (optional)

number

The amount of token to deposit to the cluster before execute the transaction. If not specified, it will use 0.

plain (optional)

boolean

By default, the contract transaction is visible on chain and encrypted. If plain is true, the transaction will be visible on chain and not encrypted.

nonce (optional)

string It's not the nonce for the on-chain transaction (since it will be auto-incremented), it's the nonce for the off-chain transaction and you can use it as the identify of the transaction to filtering the logs.

Returns

Promise<PinkSubmittableResult>