hi guys, i am working on a dapp i foung the repo on github but i am trying to make some change, as of now the dapp works only with metamask :
const metamaskIsInstalled = ethereum && ethereum.isMetaMask;
if (metamaskIsInstalled) {
Web3EthContract.setProvider(ethereum);
let web3 = new Web3(ethereum);
try {
const accounts = await ethereum.request({
method: "eth_requestAccounts",
});
const networkId = await ethereum.request({
method: "net_version",
});
if (networkId == CONFIG.NETWORK.ID) {
const SmartContractObj = new Web3EthContract(
abi,
CONFIG.CONTRACT_ADDRESS
);
dispatch(
connectSuccess({
account: accounts[0],
smartContract: SmartContractObj,
web3: web3,
})
);
// Add listeners start
ethereum.on("accountsChanged", (accounts) => {
dispatch(updateAccount(accounts[0]));
});
ethereum.on("chainChanged", () => {
window.location.reload();
});
// Add listeners end
} else {
dispatch(connectFailed(Change network to ${CONFIG.NETWORK.NAME}.));
}
} catch (err) {
dispatch(connectFailed("Something went wrong."));
}
} else {
dispatch(connectFailed("Install Metamask."));
}
};
};

how can integrate trust wallet in my dapp?

Jan 22, 2022, 12:39 PM
any suggestion with this?
Jan 22, 2022, 3:07 PM
I forget which repo had the code you are looking for for trustwallet but I think if you check Moralis react repo on github they have a section for connecting wallets and there they have a conditional statement for metamask and for trustwallet
Nevermind I just found the code and it's for MetaMask and WalletConnect. No trustwallet
On another note has anyone used Moralis in their projects? They seem to handle a lot of stuff frontend and even backend if you are onboarding ppl or dealing with NFTs. It seems way too good to be true and it's free so what is the catch? Why isn't everyone using it for front end and more?
Jan 22, 2022, 5:32 PM
I am
Works very good tbh easy and versatile
Jan 22, 2022, 5:45 PM
Good to know! I'm planning on using it after looking into it. Any issues/limitations so far? Some of the documentation is weak though
Jan 22, 2022, 5:48 PM
i think wallet connect will help connecting trustwallet, i need to find code then, if yyou have by hand please share
well really depends the use you need to do, atm i am using for my project to get a snapshot of their nft minted outside the marketplace and works good,
i am now testing another dapp that can live on moralis without any problem you can create servers using also the various blockchain avaialable they have got about 5 or 6
Regarding this i have been able to integrate wallet connect, but now i have a problem, is connecting(wallet to the website via trust wallet but is still telling me to install metamask, any idea?
// constants
import Web3EthContract from "web3-eth-contract";
import Web3 from "web3";
// log
import { fetchData } from "../data/dataActions";
import WalletConnect from "@walletconnect/client";
import QRCodeModal from "@walletconnect/qrcode-modal";

// Create a connector
const connector = new WalletConnect({
bridge: "https://bridge.walletconnect.org", // Required
qrcodeModal: QRCodeModal,
});

// Check if connection is already established
if (!connector.connected) {
// create new session
connector.createSession();
}

// Subscribe to connection events
connector.on("connect", (error, payload) => {
if (error) {
throw error;
}

// Get provided accounts and chainId
const { accounts, chainId } = payload.params[0];
});

connector.on("session_update", (error, payload) => {
if (error) {
throw error;
}

// Get updated accounts and chainId
const { accounts, chainId } = payload.params[0];
});

connector.on("disconnect", (error, payload) => {
if (error) {
throw error;
}

// Delete connector
});

const connectRequest = () => {
return {
type: "CONNECTION_REQUEST",
};
};
const connectSuccess = (payload) => {
return {
type: "CONNECTION_SUCCESS",
payload: payload,
};
};

const connectFailed = (payload) => {
return {
type: "CONNECTION_FAILED",
payload: payload,
};
};

const updateAccountRequest = (payload) => {
return {
type: "UPDATE_ACCOUNT",
payload: payload,
};
};

export const connect = () => {
return async (dispatch) => {
dispatch(connectRequest());
const abiResponse = await fetch("/config/abi.json", {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
});
const abi = await abiResponse.json();
const configResponse = await fetch("/config/config.json", {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
});
const CONFIG = await configResponse.json();
const { ethereum } = window;
const request = connector._formatRequest({
method: 'get_accounts',
});

connector
._sendCallRequest(request)
.then(result => {
// Returns the accounts
console.log(result);
})
.catch(error => {
// Error returned when rejected
console.error(error);
});
const walletconnectIsInstalled = ethereum && ethereum.isWalletConnect;
const metamaskIsInstalled = ethereum && ethereum.isMetaMask;
if (metamaskIsInstalled) {
Web3EthContract.setProvider(ethereum);
let web3 = new Web3(ethereum);
try {
const accounts = await ethereum.request({
method: "eth_requestAccounts",
});
const networkId = await ethereum.request({
method: "net_version",
});
if (networkId == CONFIG.NETWORK.ID) {
const SmartContractObj = new Web3EthContract(
abi,
CONFIG.CONTRACT_ADDRESS
);
dispatch(
connectSuccess({
account: accounts[0],
smartContract: SmartContractObj,
web3: web3,
})
);
// Add listeners start
ethereum.on("accountsChanged", (accounts) => {
dispatch(updateAccount(accounts[0]));
});
ethereum.on("chainChanged", () => {
window.location.reload();
});
// Add listeners end
}
else {
dispatch(connectFailed(Change network to ${CONFIG.NETWORK.NAME}.));
}
} catch (err) {
dispatch(connectFailed("Something went wrong."));
}
if (walletconnectIsInstalled){
const request = connector._formatRequest({
method: 'get_accounts',
});

connector
._sendCallRequest(request)
.then(result => {
// Returns the accounts
console.log(result);
})
.catch(error => {
// Error returned when rejected
console.error(error);
});
const network = 118; // Atom (SLIP-44)
const account = accounts.find((account) => account.network === network);
// Transaction structure based on Trust's protobuf messages.
const tx = {
accountNumber: "1035",
chainId: "cosmoshub-2",
fee: {
amounts: [
{
denom: "uatom",
amount: "5000"
}
],
gas: "200000"
},
sequence: "40",
sendCoinsMessage: {
fromAddress: account.address,
toAddress: "cosmos1zcax8gmr0ayhw2lvg6wadfytgdhen25wrxunxa",
amounts: [
{
denom: "uatom",
amount: "100000"
}
]
}
};

const request1 = connector._formatRequest({
method: 'trust_signTransaction',
params: [
{
network,
transaction: JSON.stringify(tx),
},
],
});

connector
._sendCallRequest(request1)
.then(result => {
// Returns transaction signed in json or encoded format
console.log(result);
})
.catch(error => {
// Error returned when rejected
console.error(error);
});
}
} else {
dispatch(connectFailed("Install Metamask."));
}
};
};

export const updateAccount = (account) => {
return async (dispatch) => {
dispatch(updateAccountRequest({ account: account }));
dispatch(fetchData(account));
};
};
https://developer.trustwallet.com/wallet-connect#web3modal
i have followed this guide
https://pastebin.com/3rDrmGkr
which is the name of you project - contracts/nameproject.sol
that is the contract code that you need to copy to verify
and make sure you have copied the ABI to verify
any help with this? i was suggestedd to deleted service workers which i believe is this one but still not able to make trust wallet working with my dapp despite is connecting
still having issue with this any help?
Jan 23, 2022, 8:12 AM

© 2024 Draquery.com All rights reserved.