使用steemjs在同一个transaction里发送多个转账

in hive-180932 •  4 years ago 

之前看到别人用steem python在一个transaction里发送多个转账,也想试试steemjs能不能做,但是找了一圈没看到有人介绍steemjs同个transaction多个转账/操作的文章,所以自己研究了一下方法,代码如下:

const steem = require('steem');
const wif = "ACTIVE KEY";

let operations = [
    ['transfer', {
        from: 'xiaoyuanwmm',
        to: 'ericet',
        amount: '0.001 STEEM',
        memo: 'test'
    }], ['transfer', {
        from: 'xiaoyuanwmm',
        to: 'teamcn-shop',
        amount: '0.001 STEEM',
        memo: 'test'
    }], ['transfer', {
        from: 'xiaoyuanwmm',
        to: 'team-cn',
        amount: '0.001 STEEM',
        memo: 'test'
    }], ['transfer', {
        from: 'xiaoyuanwmm',
        to: 'steem-drivers',
        amount: '0.001 STEEM',
        memo: 'test'
    }], ['transfer', {
        from: 'xiaoyuanwmm',
        to: 'steem.buzz',
        amount: '0.001 STEEM',
        memo: 'test'
    }]
];


steem.broadcast.send(
    { operations: operations, extensions: [] },
    { active: wif },
    function (e, r) {
        console.log(e, r);
    });

这个程序会在同个transaction里面给5个不同账号进行转账:

image.png

使用同个transaction多个操作可以减少RC的使用率。本来你需要发送5个transactions转账给5个账号,现在只需发送1个transaction

除了上面transfer那个操作外,还有custom_json,comment,vote,等等。具体可以参考dsteem(steemjs没有具体介绍):https://jnordberg.github.io/dsteem/interfaces/operation.html

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!