Skip to content

Providers

Provider is the concept that holding the wallet and decide the way submit extrincts. We don't use polkadot-js KeyringPair and ApiPromise directly, because the origin model has limitation and we need to hide the complexity of evm_account_mapping.

The SDK includes three providers for different use cases:

All provider implementations have following share accessors & methods.

address

string

The SS58 format address of the wallet.

name

string

The name of the provider implementation. You can use it to distinguish different providers.

The name for each provider implementation is:

  • KeyringPairProvider: keyring
  • UIKeyringPairProvider: uiKeyring
  • EvmAccountMappingProvider: evmAccountMapping
if (provider.name === 'keyring') {
  console.log('This is a KeyringPairProvider')
}

isCertificateExpired

boolean

Check if the certificate is expired.

const isExpired = provider.isCertificateExpired 

hasCertificate

boolean

Check if the provider has a certificate.

const hasCertificate = provider.hasCertificate 

send

Submit an extrinsic to the chain.

Usage

const apiPromise = client.api
const result = await provider.send(apiPromise.tx.system.remark('Hello, Phat')) 

Parameters

extrinsic

SubmittableExtrinsic

Any SubmittableExtrinsic instance from @polkadot/api. It usually comes from api.tx.*.

transform (optional)

(input: ISubmittableResult) => ISubmittableResult

Set a customize transform function to the extrinsic result before returns.

It use internally and you don't need to use it in most cases.

Returns

SubmittableResult

The result of the extrinsic submission, check detailed on polkadot-js/api.

adjustStake

Adjusting the staking token for a specified Phat Contract. Depends on the pecentage of staking pool, the Phat Contract will the same percentage of computation power.

Usage

const contractId = '0x...'
await provider.adjustStake(contractId, 1e14) 

Parameters

contractId

string

The contract id of the contract.

amount

number

The amount of stake to adjust. It's in the unit of Planck. It can be a negative number to unstake specified amount of tokens.

signCertificate

Get the CertificateData from the provider. The CertificateData will cache for specified time as ttl parameter set.

Usage

const cert = await provider.signCertificate() 

Parameters

ttl (optional)

number

The time to live of the certificate. It's in the unit of seconds. The default value is 0x7fffffff (2,147,483,647 seconds, or 68 years).

Returns

CertificateData

revokeCertificate

Revoke the certificate cache inside the provider.

Usage

provider.revokeCertificate()