@polkadot/types/types#AnyNumber TypeScript Examples
The following examples show how to use
@polkadot/types/types#AnyNumber.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Message.ts From gear-js with GNU General Public License v3.0 | 6 votes |
/**
* Send message
* @param message Message parameters
* @param meta Metadata
* @param messageType MessageType
* @returns Submitted result
* ```javascript
* const api = await GearApi.create()
* const programId = '0xd7540ae9da85e33b47276e2cb4efc2f0b58fef1227834f21ddc8c7cb551cced6'
* api.message.submit({
* destination: messageId,
* payload: 'Hello, World!',
* gasLimit: 20_000_000
* }, undefiend, 'String')
* api.message.signAndSend(account, (events) => {
* events.forEach(({event}) => console.log(event.toHuman()))
* })
* ```
*/
submit(
message: { destination: string | H256; payload: PayloadType; gasLimit: AnyNumber; value?: AnyNumber },
meta?: Metadata,
messageType?: string,
): SubmittableExtrinsic<'promise', ISubmittableResult> {
let payload = createPayload(this.createType, messageType || meta?.handle_input, message.payload, meta);
try {
this.submitted = this.api.tx.gear.sendMessage(message.destination, payload, message.gasLimit, message.value || 0);
return this.submitted;
} catch (error) {
throw new SendMessageError();
}
}
Example #2
Source File: Blocks.ts From gear-js with GNU General Public License v3.0 | 5 votes |
/**
* Get blockHash by number
* @param number number of block
* @returns blockHash
*/
async getBlockHash(number: AnyNumber | BlockNumber): Promise<BlockHash> {
return await this.api.rpc.chain.getBlockHash(number);
}
Example #3
Source File: MessageReply.ts From gear-js with GNU General Public License v3.0 | 5 votes |
/**
* Sends reply message
* @param message Message parameters
* @param meta Metadata
* @param messageType MessageType
* @returns Submitted result
* @example
* ```javascript
* const api = await GearApi.create()
* const messageId = '0xd7540ae9da85e33b47276e2cb4efc2f0b58fef1227834f21ddc8c7cb551cced6'
* api.reply.submit({
* replyToId: messageId,
* payload: 'Reply message',
* gasLimit: 20_000_000
* }, undefiend, 'String')
* api.reply.signAndSend(account, (events) => {
* events.forEach(({event}) => console.log(event.toHuman()))
* })
* ```
*/
submit(
message: {
replyToId: H256 | string;
payload: string | any;
gasLimit: u64 | AnyNumber;
value?: BalanceOf | AnyNumber;
},
meta?: Metadata,
messageType?: string,
): SubmittableExtrinsic<'promise', ISubmittableResult> {
let payload = createPayload(
this.createType,
messageType || meta?.async_handle_input || meta?.async_init_input,
message.payload,
meta,
);
try {
this.submitted = this.api.tx.gear.sendReply(message.replyToId, payload, message.gasLimit, message.value);
return this.submitted;
} catch (error) {
throw new SendReplyError();
}
}
Example #4
Source File: Program.ts From gear-js with GNU General Public License v3.0 | 5 votes |
/**
* @param program Upload program data
* @param meta Metadata
* @returns ProgramId
* @example
* ```javascript
* const code = fs.readFileSync('path/to/program.opt.wasm');
* const meta = await getWasmMetadata(fs.readFileSync('path/to/program.meta.wasm'));
* const api = await GearApi.create();
* const { programId, salt, submitted } = api.program.submit({
* code,
* initPayload: {field: 'someValue'},
* gasLimit: 20_000_000,
* }, meta)
* api.program.signAndSend(account, (events) => {
* events.forEach(({event}) => console.log(event.toHuman()))
* })
* ```
*/
submit(
program: {
code: Buffer | Uint8Array;
salt?: `0x${string}`;
initPayload?: string | any;
gasLimit: u64 | AnyNumber;
value?: BalanceOf | AnyNumber;
},
meta?: Metadata,
messageType?: string,
): { programId: Hex; salt: Hex; submitted: SubmittableExtrinsic<'promise', ISubmittableResult> } {
const salt = program.salt || randomAsHex(20);
const code = this.createType.create('bytes', Array.from(program.code)) as Bytes;
let payload = createPayload(this.createType, messageType || meta?.init_input, program.initPayload, meta);
try {
this.submitted = this.api.tx.gear.submitProgram(code, salt, payload, program.gasLimit, program.value || 0);
const programId = generateProgramId(code, salt);
return { programId, salt, submitted: this.submitted };
} catch (error) {
throw new SubmitProgramError();
}
}