eosjs 文档(交易)
交易
为了能够在区块链上发送交易和触发操作,你必须具有Api
实例。
签名提供程序必须包含与执行者和操作权限相对应的私钥。
const { Api, JsonRpc } = require('eosjs'); const JsSignatureProvider = require('eosjs/dist/eosjs-jssig'); // development only const fetch = require('node-fetch'); // node only; not needed in browsers const { TextDecoder, TextEncoder } = require('text-encoding'); // node, IE11 and IE Edge Browsers const privateKeys = [privateKey1]; const signatureProvider = new JsSignatureProvider.default(privateKeys); const rpc = new JsonRpc('http://127.0.0.1:8888', { fetch }); const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
示例
Buy ram
const result = await api.transact({ actions: [{ account: 'eosio', name: 'buyrambytes', authorization: [{ actor: 'useraaaaaaaa', permission: 'active', }], data: { payer: 'useraaaaaaaa', receiver: 'useraaaaaaaa', bytes: 8192, }, }] }, { blocksBehind: 3, expireSeconds: 30, });
Stake
const result = await api.transact({ actions: [{ account: 'eosio', name: 'delegatebw', authorization: [{ actor: 'useraaaaaaaa', permission: 'active', }], data: { from: 'useraaaaaaaa', receiver: 'useraaaaaaaa', stake_net_quantity: '1.0000 SYS', stake_cpu_quantity: '1.0000 SYS', transfer: false, } }] }, { blocksBehind: 3, expireSeconds: 30, });
示例:Unstake
const result = await api.transact({ actions: [{ account: 'eosio', name: 'undelegatebw', authorization: [{ actor: 'useraaaaaaaa', permission: 'active', }], data: { from: 'useraaaaaaaa', receiver: 'useraaaaaaaa', unstake_net_quantity: '1.0000 SYS', unstake_cpu_quantity: '1.0000 SYS', transfer: false, } }] }, { blocksBehind: 3, expireSeconds: 30, });
创建新帐户(多个操作)
const result = await api.transact({ actions: [{ account: 'eosio', name: 'newaccount', authorization: [{ actor: 'useraaaaaaaa', permission: 'active', }], data: { creator: 'useraaaaaaaa', name: 'mynewaccount', owner: { threshold: 1, keys: [{ key: 'PUB_R1_6FPFZqw5ahYrR9jD96yDbbDNTdKtNqRbze6oTDLntrsANgQKZu', weight: 1 }], accounts: [], waits: [] }, active: { threshold: 1, keys: [{ key: 'PUB_R1_6FPFZqw5ahYrR9jD96yDbbDNTdKtNqRbze6oTDLntrsANgQKZu', weight: 1 }], accounts: [], waits: [] }, }, }, { account: 'eosio', name: 'buyrambytes', authorization: [{ actor: 'useraaaaaaaa', permission: 'active', }], data: { payer: 'useraaaaaaaa', receiver: 'mynewaccount', bytes: 8192, }, }, { account: 'eosio', name: 'delegatebw', authorization: [{ actor: 'useraaaaaaaa', permission: 'active', }], data: { from: 'useraaaaaaaa', receiver: 'mynewaccount', stake_net_quantity: '1.0000 SYS', stake_cpu_quantity: '1.0000 SYS', transfer: false, } }] }, { blocksBehind: 3, expireSeconds: 30, });
上一篇:浏览器
下一篇:读取区块链
相关推荐
往后余生 2020-09-17
CXsilent 2020-09-16
webgm 2020-08-16
Lophole 2020-06-28
sqliang 2020-06-14
xcguoyu 2020-06-13
徐建岗网络管理 2020-06-11
前端开发Kingcean 2020-06-11
cbao 2020-06-10
yezitoo 2020-06-06
bigname 2020-06-04
前端开发Kingcean 2020-05-29
xiaofanguan 2020-05-29
ELEMENTS爱乐小超 2020-05-28
皖林 2020-05-11
wbczyh 2020-05-03
zuihaobushi 2020-04-30