singularity-client-script
v1.8.8
Published
Singularity client script
Downloads
6,092
Readme
Singularity-client-script
Inject the following script in your index.html
(function (w, d, s, o, f, js, fjs) {
w[o] =
w[o] ||
function () {
(w[o].q = w[o].q || []).push(arguments);
};
(js = d.createElement(s)), (fjs = d.getElementsByTagName(s)[0]);
js.id = o;
js.src = f;
js.async = 1;
fjs.parentNode.insertBefore(js, fjs);
})(window, document, "script", "Singularity", "https://unpkg.com/singularity-client-script@latest/index.js");
There are two ways of communication between client and Singualarity SDK
1. Subscription based
- walletInfo
- drawerOpen
- drawerClose
const handleWalletInfo = (event) => {
const walletDetails = event.detail.callback();
console.log('Wallet details', walletDetails);
};
window.SingularityEvent.subscribe('walletInfo', handleWalletInfo);
const handleDrawerOpen = () => {
console.log('Drawer open');
};
window.SingularityEvent.subscribe('drawerOpen', handleDrawerOpen);
const handleDrawerClose = () => {
console.log('Drawer close');
};
window.SingularityEvent.subscribe('drawerClose', handleDrawerClose);
2. Function based
- close
- open
- getConnectUserInfo
- transactionFlow
- requestPersonalSignature
- requestTypedSignature
- logout
window.SingularityEvent.close();
window.SingularityEvent.open();
const data = await window.SingularityEvent.getConnectUserInfo();
window.SingularityEvent.logout();
const signature = await window.SingularityEvent.requestPersonalSignature("hello world")
const domain = {
name: 'GamePay',
version: '1',
chainId: 97,
verifyingContract: '0xED975dB5192aB41713f0080E7306E08188e53E7f'
};
const types = {
bid: [
{ name: 'bidder', type: 'address' },
{ name: 'collectableId', type: 'uint256' },
{ name: 'amount', type: 'uint256' },
{ name: 'nounce', type: 'uint' }
]
};
const message = {
bidder: '0xAa81f641d4b3546F05260F49DEc69Eb0314c47De',
collectableId: 1,
amount: 100,
nounce: 1
};
const primaryType ="bid";
const signature = await window.SingularityEvent.requestTypedSignature(domain, primaryType, types, message)
window.SingularityEvent.transactionFlow('INIT_COLLECT_PAYMENT',{
"transactionId": "bd3d2555-d70c-4059-8c4d-94b6f15eff55",
"clientReferenceId": "897",
"singularityTransactionStatus": "SINGULARITY_TRANSACTION_INITIATED",
"clientId": "15de55a2-c0a7-420d-97a7-1d907c61ba71",
"userId": "bdbad93d-4ba7-42d1-a52a-f5911c194a72",
"transactionLabel": "Test wert flow",
"transactionIconLink": "https://singularity-icon-assets.s3.ap-south-1.amazonaws.com/currency/matic.svg",
"transactionDescription": "Description",
"clientProjectName": "test-project-1",
"primaryWalletDetails": {
"singularityWalletAccountId": "4e20c721-5021-41a3-a92c-3e84ccc1828b",
"chainId": "80001",
"chainCategory": "EVM",
"walletAddress": "0x0191b5aa45555ea59e8653b314a77e6a9818126f"
},
"clientRequestedAsset": {
"assetId": "66",
"chainId": "80001",
"chainName": "MUMBAI",
"chainCategory": "EVM",
"chainIconURL": "https://singularity-icon-assets.s3.ap-south-1.amazonaws.com/chain/mumbai.svg",
"currencyType": "USDC",
"currencyIconURL": "https://singularity-icon-assets.s3.ap-south-1.amazonaws.com/currency/usdc.svg"
},
"paymentOptions": {
"fiat": {
"paymentMode": {
"credit_card": [
{
"provider": "wert",
"collectCurrencyAmountInUSD": "0.01",
"selected": false,
"currencyIconURL": "https://singularity-icon-assets.s3.ap-south-1.amazonaws.com/currency/creditcard.svg",
"data": {
"signedData": {
"address": "0x0191b5aa45555ea59e8653b314a77e6a9818126f",
"commodity": "TT",
"commodity_amount": "1.5",
"pk_id": "key1",
"sc_address": "0x43b40335Fe283502Aaf08c810e4772cbd4b8107D",
"sc_id": "ea84b5ee-1b8a-4a86-b87a-e73dbb40b155",
"sc_input_data": "0x8fd8a3120000000000000000000000000191b5aa45555ea59e8653b314a77e6a9818126f00000000000000000000000017f547ae02a94a0339c4cfe034102423907c459200000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000016e36000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000025454000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002462643364323535352d643730632d343035392d386334642d39346236663135656666353500000000000000000000000000000000000000000000000000000000",
"signature": "D117CDBECE0588FFF60EFCEE7E346A6BD8CB4C1663186BA813A29002E84ED8C2F1522705B0C6E0CE9DAF0F69FA5C1A11F19E4C2E614D7BB305F0F821FEFA8105"
},
"commodity": "TT",
"partnerId": "01GH9K0D7HF976CMVX233RGV9E"
}
}
]
}
},
"crypto": [
{
"assetId": "55",
"chainId": "80001",
"chainName": "MUMBAI",
"chainCategory": "EVM",
"currencyType": "MATIC",
"chainIconURL": "https://singularity-icon-assets.s3.ap-south-1.amazonaws.com/chain/mumbai.svg",
"decimal": 18,
"currencyIconURL": "https://singularity-icon-assets.s3.ap-south-1.amazonaws.com/currency/matic.svg",
"collectCurrencyAmount": "1.4878453364448143",
"collectCurrencyAmountInUSD": "1.9163447933409208",
"collectGasInformation": {
"collectGasAmount": "3.1500000336E-5",
"collectGasAmountInUSD": "4.0572000432768E-5",
"currencyType": "MATIC",
"currencyIconURL": "https://singularity-icon-assets.s3.ap-south-1.amazonaws.com/currency/matic.svg"
},
"selected": false,
"userBalanceDetails": [
{
"singularityUserAccountId": "4e20c721-5021-41a3-a92c-3e84ccc1828b",
"userAddress": "0x0191b5aa45555ea59e8653b314a77e6a9818126f",
"userBalance": "0.714047505448309524",
"userBalanceInUSD": "0.9196931870174226"
}
],
"native": true
},
{
"assetId": "66",
"chainId": "80001",
"chainName": "MUMBAI",
"chainCategory": "EVM",
"currencyType": "USDC",
"chainIconURL": "https://singularity-icon-assets.s3.ap-south-1.amazonaws.com/chain/mumbai.svg",
"decimal": 6,
"currencyIconURL": "https://singularity-icon-assets.s3.ap-south-1.amazonaws.com/currency/usdc.svg",
"collectCurrencyAmount": "1.5",
"collectCurrencyAmountInUSD": "1.49985",
"collectGasInformation": {
"collectGasAmount": "3.1500000336E-5",
"collectGasAmountInUSD": "4.0603500433104E-5",
"currencyType": "MATIC",
"currencyIconURL": "https://singularity-icon-assets.s3.ap-south-1.amazonaws.com/currency/matic.svg"
},
"selected": false,
"userBalanceDetails": [
{
"singularityUserAccountId": "4e20c721-5021-41a3-a92c-3e84ccc1828b",
"userAddress": "0x0191b5aa45555ea59e8653b314a77e6a9818126f",
"userBalance": "12.286171",
"userBalanceInUSD": "12.284942382899999"
}
],
"native": false
}
]
},
"clientRequestedAssetQuantity": "1.5",
"userSelectedAsset": null,
"userSelectedAssetQuantity": null,
"singularityTransactionType": "RECEIVE",
"singularityTransactionSubType": null,
"singularityTransactionExchangeMode": null,
"status": "SUCCESS",
"error": null
});