Skip to content

PinkCodePromise

The PinkCodePromise class allows the developer to manage calls to the phalaPhatContracts.clusterUploadResource. When your Phat Contract's codeHash no found in the cluster, you can use PinkCodePromise upload your code to the cluster.

Usage

import * as fs from 'node:fs'
import { PinkCodePromise } from '@phala/sdk'
 
const source = fs.readFileSync('path/to/contract.contract', 'utf-8') 
const pinkCodePromise = new PinkCodePromise(client, source)
if (!(await pinkCodePromise.hasExists())) {
    const submittableResult = await pinkCodePromise.send({ provider })
    await submittableResult.waitFinalized()
}
const blueprintPromise = pinkCodePromise.getBlueprint()

Methods

hasExists

Check if the code exists in the cluster.

Returns

Promise<boolean>

getBlueprint

Get the PinkBlueprintPromise instance.

Returns

PinkBlueprintPromise

send

Submit the phalaPhatContracts.clusterUploadResource transaction with specified provider.

Parameters

  • provider: AnyProvider

Returns

Promise<InkCodeSubmittableResult>

See InkCodeSubmittableResult for more details.

upload

Prepare the SubmittableExtrinsic. You need call .signAndSend or use the signAndSend helper to submit the transaction.

Returns

SubmittableExtrinsic<InkCodeSubmittableResult>

InkCodeSubmittableResult

The SubmittableResult for phalaPhatContracts.clusterUploadResource transaction. On the top of the SubmittableResult, it also provides the waitFinalized method to wait the transaction finalized.

waitFinalized

Wait for the transaction finalized.