@dioxide-js/silas is a Nodejs/javascript SDK which designed to interact with Dioxide JSON RPC API。
using npm
$ npm install @dioxide-js/silas
using yarn
$ yarn add @dioxide-js/silas
Using pnpm:
$ pnpm add @dioxide-js/silas
Using in browser
<script src="https://unpkg.com/@dioxide-js/silas@latest/dist/umd/index.min.js"></script>
<script>
const { Web3, NET } = DSSWeb3;
const web3 = new Web3(NET.TEST, {
apiKey: <YOUR_API_KEY>
});
web3.overview.chainStatus().then(console.log)
</script>
import { Web3, NET } from '@dioxide-js/silas'
import { dataview } from '@dioxide-js/misc'
const web3 = new Web3(NET.TEST, {
apiKey: 'YOUR_API_KEY',
}) // const web3 = new Web3(NET.MAIN); // For production
const user0 = {
address: 'jjkw5p9fz7nk0zfy6171ch0dy8bk16mhgpwkdcrc4rpt4sfzpvht9za2qr:sm2',
privatekey: 'AyyogAYL5nVC5CsrTxdYe9IBXOppNqsGd+hSHn+QT68=',
id: 'stest01',
}
const privatekeyU8 = dataview.base64ToU8(user0.privatekey)
To set a proof and retrieve tx hash as result.
const txnHash = await web3.proof.newProof(user0.privatekey, {
content: 'sdk unit test',
key: 'test234',
sender: user0.address,
})
To set a proof and retrieve tx hash as result.
import { utils } from "@dioxide-js/silas"
const fileBuffer = new Uint8Array([0x1, 0x2, 0x3, 0x4])
const proofKey = utils.toProofKeyHash(fileBuffer)
const txnHash = await web3.proof.newProofByProofKey(user0.privatekey, {
sender: user_0.address,
proof_key: proofKey,
content: 'ff' // optional
})
console.log(txnHash)
const proofs = await web3.proof.getProofs({
owner: user0.address,
})
const proofs = await web3.proof.checkProof("ctz5ftg90cxm65j3ns5g4f99zezen9a73dkw2s7xspjbg19t4ax0")
const result = await web3.account.generate('sm2')
console.log(result.publickey, result.privatekey, result.address)
getState(p: RegsiterOption): Promise<{address: string; publickey: string; status: number; userid: string}>
const userState = await web3.account.getState({
address: user0.address,
})
console.log(userState)
/* output: {
"address": "a0r0ywzbgntvppvbqwrc6fgfz54f5zq1fme9579bd69j64gvk7f78nmwjm:sm2",
"publickey": "S7dFGoY5TMydWP1+VuSG5+IpmVMv1jbbqwpBJDxIILtUlntfmrONqfPYZ+0GSbHZ4QlSQaUTcqKrPHWV2nqZTQ==",
"status": "0",
"userid": "new_test"
} */
const registed = await web3.account.register({id: user0.id})
const status = await web3.overview.chainStatus()
console.log(status.Throughput) // output: 100.03
Get recently transactions on blockchain.
const list = await web3.overview.getTxHistory()
console.log(list)
const isn = await web3.address.getISN()
console.log(isn) // output: 8
Get the list of transactions related to the address (summary information).
const list = await web3.address.getTxnListByAddress({
address: user0.address
})
const state = await web3.address.getAddressState({address: user0.address})
console.log(state)
const profile = await web3.address.getAddressInfo({
address: user0.address
})
console.log(profile)
getHistory(params: { height: number; limit?: number, pos?: number; shardindex?: number}): Promise<DIOX.Block[] | undefined
const blockList = await web3.block.getHistory({"shardindex": 1})
console.log(blockList)
getExcutedTx(params: { height: number; limit?: number; pos?: number; shardindex?: number }): Promise<DIOX.ExcutedTx | undefined>
const tx = await web3.block.getExcutedTx({"height": 100})
console.log(tx)
const detail = await web3.block.detail("mgthswczq1b3ycyvh5t3be01t4trayx4k7s7c09ad1natffhk0w0")
console.log(detail)
const detail = await web3.txn.getTx("a9cdzqythgtn8078ejhghb74f6s8x9k9v0rcn13azt1fp19wcftg")
cosnole.log(detail)
// output:
{
"ISN": 2,
"TTL": 1800000,
"Hash": "a9cdzqythgtn8078ejhghb74f6s8x9k9v0rcn13azt1fp19wcftg",
"Mode": "ITM_FIRST_SIGNER|TGM_USER_SIGNED",
"Size": 181,
...
}
Send a transaction. The transaction will be constructed and signed locally using the private key, and the signed result will be broadcast to the blockchain. The private key will not be transmitted over the network.
const data = aawait web3.txn.send({
args: {
Amount: '200000000',
To: user1.address
},
function: 'core.coin.transfer',
gasprice: '100',
sender: user0.address,
}, user0.privatekey)
console.log(data) // output: "5akjfknj9phq93r56kqygjcv3r1tpwm2gt82xex1z3nkrk4r509g"
see src/api/type.ts
link