Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jssdk: contract actions #1536

Merged
merged 8 commits into from
Feb 28, 2024
Merged

Conversation

Leechael
Copy link
Contributor

@Leechael Leechael commented Feb 23, 2024

This PR propose for introduce three new actions like viem

  • sendPinkQuery
  • sendPinkCommand
  • estimateContract

It propose to work with HttpProvider from polkadot-js.

The usage summary:

await cryptoWaitReady()

const metadata = await fetchMetadata('http://10.0.0.120:19944')
const api = new ApiPromise(options({
  provider: new HttpProvider('http://10.0.0.120:19944'),
  metadata,
  noInitWarn: true,
}))
await api.isReady
const client = new OnChainRegistry(api)
await client.connect({
  clusterId: '0x0000000000000000000000000000000000000000000000000000000000000001',
  pubkey: '0x3a3d45dc55b57bf542f4c6ff41af080ec675317f4ed50ae1d2713bf9f892692d',
  pruntimeURL: 'http://10.0.0.120:18200',
})

const contractId = '0x72590ce8ec70a1c13379be5cce4be8fc5a6173073fd169f9fbf93a33d485a9e0'
const contractKey = '0xa6c952655e61d39de165452be68a51719b23b7cbc60c56366590414d518dbf63'
const abi = fs.readFileSync('./abis/fat_badges.contract', 'utf8')

const provider = await KeyringPairProvider.createFromSURI(api, process.env.POLKADOT_ACCOUNT)
console.log('address: ', provider.address)

const name = `Badge${new Date().getTime()}`
const { request } = await estimateContract(client, {
  address: contractId,
  contractKey,
  abi,
  provider,
  functionName: 'newBadge',
  args: [name],
})
await sendPinkCommand(client, request)

// unlike PinkContractPromise, we don't have `waitFinalized`, so we need do that by hand.
await new Promise(resolve => setTimeout(resolve, 6_000))

const totalBadgesBefore = await sendPinkQuery(client, {
  address: contractId,
  abi,
  provider,
  functionName: 'getTotalBadges',
})
console.log('getTotalBadges:', totalBadgesBefore.toHuman())

@Leechael Leechael force-pushed the feat-jssdk-contract-actions branch from f112d9a to 3c17b52 Compare February 28, 2024 11:02
@Leechael Leechael merged commit 0eb0033 into jssdk-v060-develop Feb 28, 2024
8 checks passed
@Leechael Leechael deleted the feat-jssdk-contract-actions branch February 28, 2024 14:56
@Leechael Leechael restored the feat-jssdk-contract-actions branch March 13, 2024 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant