dsa-developers/README.md

79 lines
6.4 KiB
Markdown
Raw Normal View History

2020-04-06 17:11:49 +00:00
# Developing on DSA
We empower third-party developers to build dapps, use-cases, and other integrations on DSAs platform. That way, users can get curated experience as per their needs, and developers can build their own businesses supporting those users. This virtuous circle creates new opportunities and benefits users, developers, and protocols.
Our SDK abstract all the complex internal (like handling addresses, ABIs etc) and provide developers with a simple interface to interact with DSA platform.
To get started, install the DSA SDK package from NPM:
```bash
npm install dsa-sdk
```
You can also import the build from CDN:
```js
<script src="https://cdn.jsdelivr.net/npm/dsa-sdk@1.1.12/build/dsa.min.js"></script>
```
2020-04-06 17:21:08 +00:00
For production, we recommend linking to a specific version number ([jsdeliver](https://www.jsdelivr.com/package/npm/dsa-sdk)).
2020-04-06 17:11:49 +00:00
Now instantiate Web3 and DSA.
```js
const dsa = new DSA()
if (window.ethereum) {
window.web3 = new Web3(window.ethereum)
} else if (window.web3) {
window.web3 = new Web3(window.web3.currentProvider)
} else {
console.log('Non-Ethereum browser detected. You should consider trying MetaMask!')
}
```
2020-04-06 17:21:08 +00:00
Once connected to a web3 client, get all the DSA where a specific address is authorised:
2020-04-06 17:11:49 +00:00
```js
const accounts = await web3.eth.getAccounts()
dsa.getAccounts(accounts[0])
.then(data => {
return data
})
.catch(error => {
return error
})
```
### Parameters
`address` - An ethereum address.
### Returns
2020-04-06 17:13:30 +00:00
An `Array` of `Object` of all the DSA authorised by `address`.
2020-04-06 17:11:49 +00:00
2020-04-06 17:13:30 +00:00
```js
2020-04-06 17:21:08 +00:00
[
{
id: 52, // DSA Number
account: "0x...", // DSA Address
version: 1 // DSA version
},
...
]
2020-04-06 17:11:49 +00:00
```
2020-04-06 17:21:08 +00:00
Web3 equivalent of the above:
2020-04-06 17:11:49 +00:00
```js
const ABI = [{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"origin","type":"address"}],"name":"LogAccountCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_newAccount","type":"address"},{"indexed":true,"internalType":"address","name":"_connectors","type":"address"},{"indexed":true,"internalType":"address","name":"_check","type":"address"}],"name":"LogNewAccount","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"accountVersion","type":"uint256"},{"indexed":true,"internalType":"address","name":"check","type":"address"}],"name":"LogNewCheck","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"master","type":"address"}],"name":"LogNewMaster","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"master","type":"address"}],"name":"LogUpdateMaster","type":"event"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"account","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newAccount","type":"address"},{"internalType":"address","name":"_connectors","type":"address"},{"internalType":"address","name":"_check","type":"address"}],"name":"addNewAccount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"uint256","name":"accountVersion","type":"uint256"},{"internalType":"address","name":"_origin","type":"address"}],"name":"build","outputs":[{"internalType":"address","name":"_account","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"uint256","name":"accountVersion","type":"uint256"},{"internalType":"address[]","name":"_targets","type":"address[]"},{"internalType":"bytes[]","name":"_datas","type":"bytes[]"},{"internalType":"address","name":"_origin","type":"address"}],"name":"buildWithCast","outputs":[{"internalType":"address","name":"_account","type":"address"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountVersion","type":"uint256"},{"internalType":"address","name":"_newCheck","type":"address"}],"name":"changeCheck","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newMaster","type":"address"}],"name":"changeMaster","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"check","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"connectors","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"version","type":"uint256"},{"internalType":"address","name":"query","type":"address"}],"name":"isClone","outputs":[{"internalType":"bool","name":"result","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"list","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"master","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_master","type":"address"},{"internalType":"address","name":"_list","type":"address"},{"internalType":"address","name":"_account","type":"address"},{"internalType":"address","name":"_connectors","type":"address"}],"name":"setBasics","outputs":[
2020-04-06 17:21:08 +00:00
const address = "0xD6fB4fd8b595d0A1dE727C35fe6F1D4aE5B60F51"
2020-04-06 17:11:49 +00:00
const accounts = await web3.eth.getAccounts()
new web3.eth.Contract(ABI, address);
.getOwnerDetails(accounts[0])
.call({ from: "0x..." })
.then((data) => {
return data
})
.catch((error) => {
return error
});
2020-04-06 17:21:08 +00:00
```
Our team is super active to assist you with all of your queries at our [TG developer group](https://t.me/instadevelopers) or [discord channel](https://discord.gg/83vvrnY).