-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(example): Nodejs example (#375)
- Loading branch information
Showing
4 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { client, selectSp, generateString } = require('./client'); | ||
const { ACCOUNT_ADDRESS, ACCOUNT_PRIVATEKEY } = require('./env'); | ||
|
||
(async () => { | ||
const accountInfo = await client.account.getAccount(ACCOUNT_ADDRESS); | ||
|
||
const accountBalance = await client.account.getAccountBalance({ | ||
address: ACCOUNT_ADDRESS, | ||
denom: 'BNB', | ||
}); | ||
|
||
const moduleAccounts = await client.account.getModuleAccounts(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const { client, selectSp, generateString } = require('./client'); | ||
const { ACCOUNT_ADDRESS, ACCOUNT_PRIVATEKEY } = require('./env'); | ||
|
||
(async () => { | ||
const GROUP_NAME = generateString(10); | ||
const EXTRA = generateString(10); | ||
|
||
// create group tx | ||
const createGroupTx = await client.group.createGroup({ | ||
creator: ACCOUNT.address, | ||
extra: EXTRA, | ||
groupName: GROUP_NAME, | ||
}); | ||
|
||
const simulateInfo = await createGroupTx.simulate({ | ||
denom: 'BNB', | ||
}); | ||
|
||
console.log('simulateInfo', simulateInfo); | ||
|
||
const createGroupTxRes = await createGroupTx.broadcast({ | ||
denom: 'BNB', | ||
gasLimit: Number(simulateInfo?.gasLimit), | ||
gasPrice: simulateInfo?.gasPrice || '5000000000', | ||
payer: ACCOUNT_ADDRESS, | ||
granter: '', | ||
privateKey: ACCOUNT_PRIVATEKEY, | ||
}); | ||
|
||
// update group tx | ||
const newExtra = generateString(10); | ||
const updateGroupTx = await client.group.updateGroupExtra({ | ||
groupName: GROUP_NAME, | ||
groupOwner: ACCOUNT_ADDRESS, | ||
operator: ACCOUNT_ADDRESS, | ||
extra: newExtra, | ||
}); | ||
|
||
const simulateInfo = await updateGroupTx.simulate({ | ||
denom: 'BNB', | ||
}); | ||
|
||
expect(simulateInfo).not.toBeNull(); | ||
|
||
const updateGroupTxRes = await updateGroupTx.broadcast({ | ||
denom: 'BNB', | ||
gasLimit: Number(simulateInfo.gasLimit), | ||
gasPrice: simulateInfo.gasPrice, | ||
granter: '', | ||
payer: ACCOUNT_ADDRESS, | ||
privateKey: ACCOUNT_PRIVATEKEY, | ||
}); | ||
|
||
// delete group tx | ||
const deleteGroupTx = await client.group.deleteGroup({ | ||
groupName: GROUP_NAME, | ||
operator: ACCOUNT_ADDRESS, | ||
}); | ||
const simulateInfo = await deleteGroupTx.simulate({ | ||
denom: 'BNB', | ||
}); | ||
const deleteGroupTxRes = await deleteGroupTx.broadcast({ | ||
denom: 'BNB', | ||
gasLimit: Number(simulateInfo.gasLimit), | ||
gasPrice: simulateInfo.gasPrice, | ||
granter: '', | ||
payer: ACCOUNT_ADDRESS, | ||
privateKey: ACCOUNT_PRIVATEKEY, | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const { client, selectSp, generateString } = require('./client'); | ||
const { ACCOUNT_ADDRESS, ACCOUNT_PRIVATEKEY } = require('./env'); | ||
|
||
(async () => { | ||
const spInfo = await selectSp(); | ||
|
||
const queryLockFeeRes = await client.storage.queryLockFee({ | ||
createAt: Long.fromInt(0), | ||
primarySpAddress: spInfo.primarySpAddress, | ||
payloadSize: Long.fromInt(1111), | ||
}); | ||
})(); |