Skip to content

Commit

Permalink
Merge pull request #130 from fioprotocol/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
adsorptionenthalpy authored May 30, 2022
2 parents c23f425 + ac2a637 commit 71e0068
Show file tree
Hide file tree
Showing 8 changed files with 579 additions and 96 deletions.
63 changes: 63 additions & 0 deletions examples/SendTokensSerializeSignSteps/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
fetch = require('node-fetch')
const { FIOSDK } = require('../../lib/FIOSDK');

const privateKey = ''
const publicKey = ''
const payeePublicKey = ''

const baseUrl = '' // https://testnet.fioprotocol.io:443/v1/
const defaultFee = 800 * FIOSDK.SUFUnit

const fetchJson = async (uri, opts = {}) => {
return fetch(uri, opts)
}

const timeout = async (ms) => {
await new Promise(resolve => {
setTimeout(resolve, ms)
})
}

async function main () {
const fundsAmount = 2 * FIOSDK.SUFUnit
const publicFioSdk = new FIOSDK(
'',
'',
baseUrl,
fetchJson
);
await timeout(4000)

const chainData = await publicFioSdk.transactions.getChainDataForTx();
const transaction = await publicFioSdk.transactions.createRawTransaction({
action: 'trnsfiopubky',
account: 'fio.token',
data: {
payee_public_key: payeePublicKey,
amount: fundsAmount,
max_fee: defaultFee,
tpid: '',
// actor
},
publicKey,
chainData,
});

const { serializedContextFreeData, serializedTransaction } = await publicFioSdk.transactions.serialize({
chainId: chainData.chain_id,
transaction,
});

const signedTransaction = await publicFioSdk.transactions.sign({
chainId: chainData.chain_id,
privateKeys: [privateKey],
transaction,
serializedTransaction,
serializedContextFreeData,
});

const result = await publicFioSdk.executePreparedTrx('transfer_tokens_pub_key', signedTransaction);
console.log(result);
}

main()
14 changes: 14 additions & 0 deletions examples/SendTokensSerializeSignSteps/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "SendTokensSerializeSignSteps",
"version": "1.0.0",
"description": "Example of how to execute transaction using serialize/sign/execute steps",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Dapix, Inc. Copyright(c) 2020",
"license": "MIT",
"dependencies": {
"@fioprotocol/fiojs": "1.0.1"
}
}
16 changes: 9 additions & 7 deletions lib/FIOSDK.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ class FIOSDK {
this.technologyProviderId = technologyProviderId;
this.returnPreparedTrx = returnPreparedTrx;
for (const accountName of constants_1.Constants.rawAbiAccountName) {
this.getAbi(accountName)
.then((response) => {
Transactions_1.Transactions.abiMap.set(response.account_name, response);
})
.catch((error) => {
throw error;
});
if (!Transactions_1.Transactions.abiMap.get(accountName)) {
this.getAbi(accountName)
.then((response) => {
Transactions_1.Transactions.abiMap.set(response.account_name, response);
})
.catch((error) => {
throw error;
});
}
}
}
/**
Expand Down
Loading

0 comments on commit 71e0068

Please sign in to comment.