Providers
The provider is a key part of our system that contains the wallet and determines how transactions, known as extrinsics, are sent. Instead of using polkadot-jsβs KeyringPair and ApiPromise, we use our own solution. This helps us overcome certain limitations and simplifies the evm_account_mapping process.
The SDK includes three providers for different use cases:
KeyringPairProvider
: The provider on-top of polkadot-jsKeyringPair
class. It's the most common provider for the SDK.UIKeyringProvider
: The provider for polkadot-js compatible browser wallet extensions.EvmAccountMappingProvider
: The provider for MetaMask. It required theevm_account_mapping
pallet to be enabled on the chain.
All provider implementations have following properties & 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 returns by 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
Adjust the staking token for any Phat Contract. The contract's share of the staking pool determines its portion of computational resources.
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 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()