1.0.1 • Published 6 years ago

pcjs2 v1.0.1

Weekly downloads
2
License
MIT
Repository
-
Last release
6 years ago

pcjs2

Library for talking to the potato api.

Browser

npm run build-web or yarn build-web

<pre style="width: 100%; height: 100%; margin:0px; "></pre>

<script src='dist-web/pcjs2-debug.js'></script>
<script src='dist-web/pcjs2-jsonrpc-debug.js'></script>
<script src='dist-web/pcjs2-jssig-debug.js'></script>
<script>
    let pre = document.getElementsByTagName('pre')[0];
    let rpc = new pcjs2_jsonrpc.JsonRpc('http://localhost:8000');
    let signatureProvider = new pcjs2_jssig.default(['5JtUScZK2XEp3g9gh7F8bwtPTRAkASmNrrftmx4AxDKD5K4zDnr']);
    let api = new pcjs2.Api({ rpc, signatureProvider });

    (async () => {
        try {
            let result = await api.pushTransaction({
                blocksBehind: 3,
                expireSeconds: 10,
                actions: [{
                    account: 'pcoin.token',
                    name: 'transfer',
                    authorization: [{
                        actor: 'useraaaaaaaa',
                        permission: 'active',
                    }],
                    data: {
                        from: 'useraaaaaaaa',
                        to: 'useraaaaaaab',
                        quantity: '0.0001 PC',
                        memo: '',
                    },
                }],
            });
            pre.textContent += '\n\nTransaction pushed!\n\n' + JSON.stringify(result, null, 4);
        } catch (e) {
            pre.textContent += '\nCaught exception: ' + e;
            if (e instanceof pcjs2_jsonrpc.RpcError)
                pre.textContent += '\n\n' + JSON.stringify(e.json, null, 4);
        }
    })();
</script>

Node / ES2015

npm install pcjs2 or yarn add pcjs2

import pcjs2 from 'pcjs2';

// or use named imports
// import { Api, Rpc, SignatureProvider } from 'pcjs2';

const rpc = new pcjs2.Rpc.JsonRpc('http://localhost:8000');
const signatureProvider = new pcjs2.SignatureProvider(['5JtUScZK2XEp3g9gh7F8bwtPTRAkASmNrrftmx4AxDKD5K4zDnr']);
const api = new pcjs2.Api({ rpc, signatureProvider });

(async () => {
    try {
        const result = await api.pushTransaction({
            blocksBehind: 3,
            expireSeconds: 10,
            actions: [{
                account: 'pcoin.token',
                name: 'transfer',
                authorization: [{
                    actor: 'useraaaaaaaa',
                    permission: 'active',
                }],
                data: {
                    from: 'useraaaaaaaa',
                    to: 'useraaaaaaab',
                    quantity: '0.0001 PC',
                    memo: '',
                },
            }],
        });
        console.log(result)
    } catch (e) {
        // handle error
    }
})();
1.0.1

6 years ago

1.0.0

6 years ago