-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example of generated wCCD client
- Loading branch information
Showing
11 changed files
with
171 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { credentials } from '@grpc/grpc-js'; | ||
import * as SDK from '@concordium/node-sdk'; | ||
import meow from 'meow'; | ||
import { parseEndpoint } from '../shared/util'; | ||
|
||
//import * as wCCDModule from './lib/wCCD'; | ||
|
||
const cli = meow( | ||
` | ||
This example uses a generated smart contract client for the wCCD smart contract. | ||
Usage | ||
$ yarn run-example <path-to-this-file> [options] | ||
Required | ||
--index, -i The index of the smart contract. Defaults to 2059, which is wCCD on testnet. | ||
Options | ||
--help, -h Displays this message | ||
--endpoint, -e Specify endpoint of a grpc2 interface of a Concordium node in the format "address:port". Defaults to 'localhost:20000' | ||
--subindex, The subindex of the smart contract. Defaults to 0 | ||
`, | ||
{ | ||
importMeta: import.meta, | ||
flags: { | ||
endpoint: { | ||
type: 'string', | ||
alias: 'e', | ||
default: 'localhost:20000', | ||
}, | ||
index: { | ||
type: 'number', | ||
alias: 'i', | ||
isRequired: true, | ||
default: 2059, | ||
}, | ||
subindex: { | ||
type: 'number', | ||
default: 0, | ||
}, | ||
}, | ||
} | ||
); | ||
|
||
const [address, port] = parseEndpoint(cli.flags.endpoint); | ||
const grpcClient = SDK.createConcordiumClient( | ||
address, | ||
Number(port), | ||
credentials.createInsecure() | ||
); | ||
|
||
const contractAddress: SDK.ContractAddress = { | ||
index: BigInt(cli.flags.index), | ||
subindex: BigInt(cli.flags.subindex), | ||
}; | ||
|
||
(async () => { | ||
// Importing the generated smart contract module client. | ||
// eslint-disable-next-line import/no-unresolved, @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
const wCCDModule = await import('./lib/wCCD').catch((e) => { | ||
console.error( | ||
'\nFailed to load the generated wCCD module, did you run the `generate` script?\n' | ||
); | ||
throw e; | ||
}); | ||
|
||
const parameter = '010000'; // First 2 bytes for number of tokens to query, 1 byte for the token ID. | ||
const contract = new wCCDModule.Cis2WCCD(grpcClient, contractAddress); | ||
|
||
contract.dryRun.tokenMetadata(parameter).then((responseHex: string) => { | ||
console.log({ responseHex }); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env node | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const cli = require('../dist/src/cli.js'); | ||
const cli = require('../lib/src/cli.js'); | ||
cli.main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters