@samudai_xyz/web3-sdk v0.0.60
web3-sdk-samudai
All in one web3 integrations for Samudai
Current Integrations on SDK
SDK currently has the following for the web3 integrations
- Gnosis - Gnosis for onchain payments
- Lit Protocol - For token gating
- NFT-PPFs - Fetching of NFT profile photos for users
- SIWE - Sign in with ethereum
- Snapshot - Snapshot for proposals
Installation
Dillinger requires Node.js.
npm i web3-sdk-samudaiUsage
The SDK has the following components and the below table provides an overview to initialize them.
| Plugin | README |
|---|---|
| Gnosis | const gnosis = new Gnosis(provider: Web3Provider, chaindId: number) |
| Lit Protocol | const litProtocol = new LitProtocol() |
| NFT PPFs | const nftPPfs = new NFTProfile() |
| SIWE | const siwe = new Siwe(provider: Web3Provider) |
| Snapshot | const snapshot = new Snapshot(spaceId: string, networkType: number, provider: Web3Provider) |
Gnosis APIs
Gnosis APis are used to create transactions on the multisig and fetch transactions.
To use Gnosis
Initialize gnosis:
const gnosis = new Gnosis(provider: Web3Provider, chaindId: number)To create a single gnosis transaction
const result = await gnosis.createSingleGnosisTx(receiverAddress: string, value: string,
safeAddress: string, senderAddress: string)Param 1:
safeAddressGnosis safe address. Param 2:receiverAddressWallet address of the user whom the funds is being sent. Param 3:valueETH value in wei. Param 4:senderAddressWaller address of the sender
To create a batch gnosis transaction
const result = await gnosis.createBatchGnosisTx(safeAddress: string, receiverAddresses: string[],
value: string, senderAddress: string)Param 1:
safeAddressGnosis safe address. Param 2:receiverAddressesWallet addresses of the users whom the funds is being sent. Param 3:valueETH value in wei. Param 4:senderAddressWaller address of the sender
To get pending transactions for a safe
const result = await gnosis.getPendingTransactions(safeAddress: string)Param 1:
safeAddressGnosis safe address.
Example
const result = await gnosis.getPendingTransactions("0xE666431e8Ba10B17D296aB16A4FF8d9A552eb488")To get past / executed transactions for a safe
const result = await gnosis.getExecutedTransactions(safeAddress: string)Param 1:
safeAddressGnosis safe address.
Example
const result = await gnosis.getExecutedTransactions("0xE666431e8Ba10B17D296aB16A4FF8d9A552eb488")To get transactions details, status of a transactions for a safe transaction hash
const result = await gnosis.getTransactionDetails(safeTxHash: string)Param 1:
safeTxHashTransaction hash of a particular safe transaction.
Example
const result = await gnosis.getTransactionDetails("0x4a429ae97dd5bac92e9eef8e28fba94cf8813474c485228e58d81f04c332c399")To connect a gnosis safe
const result = await gnosis.connectGnosis(userAddress: string)Param 1:
userAddressUser address
This will return the safes for which user is an owner and also list of all other owners for a safe
Example
const result = await gnosis.gnosisConnect("0x4a429ae97dd5bac92e9eef8e28fba94cf8813474c485228e58d81f04c332c399")NFT Profile APIs
NFT Profile APIs are used to fetch the NFTs owned by the user on ETH and Polygon which can later be set as profile photos
Initialize NFT Profile Photos:
const nftProfile = new NFTProfile()To get ETH based NFTs
const ethNFTs = await nftProfile.getEthProfilePPs(ethUserAddress: string)Param 1:
ethUserAddressWallet Address of the user.
Example
const ethNFTs = await nftProfile.getEthProfilePPs(0xB1BFB38a527D05442D48068ca9798FD3E5d6ce0F)To get Polygon based NFTs
const polygonNFTs = await nftProfile.getMaticProfilePPs(maticUserAddress: string)Param 1:
maticUserAddressWallet Address of the user.
Lit Protocol APIs
Lit Protocol APIs are used to for token gating
To use Lit Protocol
Initialize Lit Protocol:
const litProtocol = new LitProtocol()To create a Lit protocol gating
const tokenGating = await litProtocol.init(
chain: string,
contractAddress: string,
typeOfGating: TokenGatingType,
baseUrl: string,
path: string,
memberId: string,
tokenId?: string
)Param 1:
chainThe chain on which the Token Gating will be created. Refer the list of chains below the example. Param 2:contractAddressContract Address of the Token. Param 3:typeOfGatingEnum value of which type of Gating. Refer the enum list below the example. Param 4:baseUrlUrl of the url of frontend. Param 5:pathThe Path that requires the token gating. Param 6:memberIdMember UUID that is being authenticated. Param 7:tokenIdToken ID of a NFT for verification.Returns:
jwtJWT token can be set on cookies or anything on the frontend and needs to be sent to SDK for verification
Example
const tokenGating = await litProtocol.init(
chain: "rinkeby",
contractAddress: "0xB1BFB38a527D05442D48068ca9798FD3E5d6ce0F",
typeOfGating: 0,
baseUrl: "http://samudai.xyz",
path: '/dao/f298865a-c3a3-46e1-8ff6-ffd63ec23257',
memberId: aaaff17d-c166-430d-9afc-82c88394c7b8,
)List of chains | chain | | ------ | | ethereum | | rinkeby | | polygon | | goerli | | mumbai |
For further chain supports based on EVM use the following list https://developer.litprotocol.com/supportedChains
Enum for TokenGatingType
enum TokenGatingType = {
ERC20,
ERC721,
ERC1155,
}
ERC20 = 0
ERC721 = 1
ERC1155 = 2To verify the user
const result = await litProtocol.verifyLit(jwt: string, memberId: string)Param 1:
jwtJWT generated by the init functionality. Param 2:memberIdMember UUIDReturns: verifyLit returns true / false based on the access conditions
SIWE
SIWE is used for Sign in with ethereum
To use SIWE
Initialize SIWE:
const siwe = new Siwe(provider: Web3Provider)To sign in user, you need to ask the user to sign a message and push the users to required screen after successful signing
const result = siwe.walletSignIn(domain: string)Param 1:
domainURL of the frontend
Example
const result = siwe.walletSignIn("https://samudai.xyz")Snapshot
Snapshot is used for fetching proposals and voting for them.
To use snapshot
Initialize Snapshot:
const snapshot = new Snapshot(spaceId: string, networkType: number, provider: Web3Provider)Param 1:
spaceIdSpace ID in Snapshot Param 2:networkType0 for Ethereum, 1 for testnets Param 3:providerWeb3Provider
Example
const snapshot = new Snapshot("biryani.eth", 1, provider)To get information about a Space
const result = snapshot.getSpace()To get active proposals
const result = snapshot.getActiveProposals()To get Recent proposals
const result = snapshot.getRecentProposals()To cast a vote
const result = snapshot.castVote(proposalId: string, choice: number,account: any)2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago