Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Eos = require('eosjs')
- // Default configuration
- config = {
- chainId: null, // 32 byte (64 char) hex string
- keyProvider: ['PrivateKeys...'], // WIF string or array of keys..
- httpEndpoint: 'http://127.0.0.1:8888',
- expireInSeconds: 60,
- broadcast: true,
- verbose: false, // API activity
- sign: true
- }
- eos = Eos(config)
- eos.transaction(
- {
- // ...headers,
- // context_free_actions: [],
- actions: [
- {
- account: 'eosio.token',
- name: 'transfer',
- authorization: [{
- actor: 'inita',
- permission: 'active'
- }],
- data: {
- from: 'inita',
- to: 'initb',
- quantity: '7.0000 SYS',
- memo: ''
- }
- }
- ]
- }
- // config -- example: {broadcast: false, sign: true}
- )
- const { Api, JsonRpc, RpcError } = require('eosjs');
- const JsSignatureProvider = require('eosjs/dist/eosjs-jssig'); // development only
- const fetch = require('node-fetch'); // node only; not needed in browsers
- const { TextEncoder, TextDecoder } = require('util'); // node only; native TextEncoder/Decoder
- const { TextEncoder, TextDecoder } = require('text-encoding');
- const defaultPrivateKey = "5JtUScZK2XEp3g9gh7F8bwtPTRAkASmNrrftmx4AxDKD5K4zDnr"; // useraaaaaaaa
- const signatureProvider = new JsSignatureProvider([defaultPrivateKey]);
- const rpc = new JsonRpc('http://127.0.0.1:8888', { fetch });
- const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
- (async () => {
- const result = await api.transact({
- actions: [{
- account: 'eosio.token',
- name: 'transfer',
- authorization: [{
- actor: 'useraaaaaaaa',
- permission: 'active',
- }],
- data: {
- from: 'useraaaaaaaa',
- to: 'useraaaaaaab',
- quantity: '0.0001 SYS',
- memo: '',
- },
- }]
- }, {
- blocksBehind: 3,
- expireSeconds: 30,
- });
- console.dir(result);
- })();
- /** in Api constructor */
- public chainId: string;
- /** in transact() function */
- if (!this.chainId) {
- info = await this.rpc.get_info();
- this.chainId = info.chain_id;
- }
- /** `fetch()` prepends the path with the host provided to JsonRpc and returns JSON containing `chain_id` */
- public async get_info(): Promise<GetInfoResult> {
- return await this.fetch("/v1/chain/get_info", {});
- }
Add Comment
Please, Sign In to add comment