Wallet Connect configuration with Binance smart chain not working - binance

I'm trying to link BSC chain with wallet connect in my react DAPP.
const walletConnectProvider = await new WalletConnectProvider({
rpc: {
56: "https://bsc-dataseed.binance.org",
},
});
await walletConnectProvider.enable();
console.log("walletConnectProvider", walletConnectProvider);
if (walletConnectProvider.connected) {
setAddr(walletConnectProvider.accounts[0]);
}
After trying to get connection with trust wallet. I'm getting this error:
Unhandled Rejection (Error): unknown account #0
(operation="getAddress", code=UNSUPPORTED_OPERATION,
version=providers/5.4.1)
While reviewing i identified that the chainid is still 1 and rpcurl is pointing to infura.
Please help me out in this issue. Thanks

Hi :) try to do something like this:
infuraId: "your_infura_id",
pollingInterval: 15000,
qrcode: true,
qrcodeModalOptions: {
mobileLinks: [
"trust",
]
},
chainId: integer number with chain id like in rpc (56 for example),
rpc: your rpc object here

Related

WalletConnect not showing metamask

Here's my code:
const provider = new WalletConnectProvider({
rpc: {
private-testnet-chainId: "private testnet",
},
qrcodeModalOptions: {
mobileLinks: [
"rainbow",
"metamask",
],
},
});
// Enable session (triggers QR Code modal)
await provider.enable();
const web3 = new Web3(provider);
However, I do not see the metamask option:
What am I missing here?
The mobileLinks array is specifically for mobile devices, and does not impact desktop usage or display. The QR code can be used to access Metamask on desktop.

Exception in fetchPairData() : call revert exception in method getReserves()

I am trying to call the "fetchPairData" function (https://uniswap.org/docs/v2/SDK/fetcher/) but I am getting the following error.
Error: call revert exception (method="getReserves()", errorSignature=null, errorArgs=[null], reason=null, code=CALL_EXCEPTION, version=abi/5.1.2)
at Logger.makeError (C:\Users\*\Desktop\ProyectoTransaccion\v2\node_modules\#ethersproject\logger\lib\index.js:180:21)
at Logger.throwError (C:\Users\*\Desktop\ProyectoTransaccion\v2\node_modules\#ethersproject\logger\lib\index.js:189:20)
at Interface.decodeFunctionResult (C:\Users\*\Desktop\ProyectoTransaccion\v2\node_modules\#ethersproject\abi\lib\interface.js:289:23)
at Contract.<anonymous> (C:\Users\*\Desktop\ProyectoTransaccion\v2\node_modules\#ethersproject\contracts\lib\index.js:329:56)
at step (C:\Users\*\Desktop\ProyectoTransaccion\v2\node_modules\#ethersproject\contracts\lib\index.js:48:23)
at Object.next (C:\Users\*\Desktop\ProyectoTransaccion\v2\node_modules\#ethersproject\contracts\lib\index.js:29:53)
at fulfilled (C:\Users\*\Desktop\ProyectoTransaccion\v2\node_modules\#ethersproject\contracts\lib\index.js:20:58)
at processTicksAndRejections (internal/process/task_queues.js:93:5) {
reason: null,
code: 'CALL_EXCEPTION',
method: 'getReserves()',
errorSignature: null,
errorArgs: [ null ],
address: '0x80f836E71a6C92acebf6A49ad39038609c780070',
args: [],
transaction: {
data: '0x0902f1ac',
to: '0x80f836E71a6C92acebf6A49ad39038609c780070'
}
}
Relevant code:
const {ChainId, Token, TokenAmount, Fetcher, Pair, Route, Trade, TradeType, Percent} = require('#pancakeswap-libs/sdk');
const INPUT_TOKEN = new Token(ChainId.MAINNET,InputTokenAddr, 18);
const OUTPUT_TOKEN = new Token(ChainId.MAINNET, OutputTokenAddr, 18);
try {
pair = await Fetcher.fetchPairData(INPUT_TOKEN, OUTPUT_TOKEN, provider);
} catch (ex)
{
console.log("Debug.INPUT_TOKEN: " + JSON.stringify(INPUT_TOKEN));
console.log("Debug.OUTPUT_TOKEN: " + JSON.stringify(OUTPUT_TOKEN));
console.log("Debug.provider: " + JSON.stringify(provider));
console.log(ex)
pair = null;
}
Debug:
Debug.INPUT_TOKEN: {"decimals":18,"chainId":56,"address":"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"}
Debug.OUTPUT_TOKEN: {"decimals":18,"chainId":56,"address":"0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56"}
Debug.provider: {"_isProvider":true,"_events":[],"_emitted":{"block":-2},"formatter":{"formats":{"transaction":{},"transactionRequest":{},"receiptLog":{},"receipt":{},"block":{},"blockWithTransactions":{},"filter":{},"filterLog":{}}},"anyNetwork":false,"_networkPromise":{},"_maxInternalBlockNumber":-1024,"_lastBlockNumber":-2,"_pollingInterval":4000,"_fastQueryDate":0,"connection":{"url":"https://bsc-dataseed.binance.org/"},"_nextId":45,"_eventLoopCache":{"detectNetwork":null,"eth_chainId":null},"_network":{"chainId":56,"name":"unknown"}}
I have verified that the swap works correctly in the pancakeswap web interface. It does not indicate route on the web, so it seems that it is a direct swap.
With other tokens the call returns what is expected. For example with the pair WBNB, BUSD.
I found for this error on another site with this comment
I faced the same issue and the problem was that I was trying to fetch
price for a pool that did not exist.
The pool exists. It has liquidity and it is also direct, it does not require a route.
The call revert exception happens when
the client doesn't receive a response
(no contract deployed on the address)
or when the contract code performs a revert.
pragma solidity ^0.8;
contract MyContract {
function foo() external view {
revert();
}
}
(Can also be when you're calling an undefined function and there's no fallback() in the contract)
Your question doesn't specify on which network you tried to perform the call, but there's no contract on the failing address on both mainnet and testnet.
So either your client app is trying to call this non-existing contract directly, or some contract in the chain of calls is trying to call it.
transaction: {
data: '0x0902f1ac',
to: '0x80f836E71a6C92acebf6A49ad39038609c780070'
}
me also facing the same issue for some tokens but i'm sure there is some issue in our end because some tokens have different routes for swapping. If token have different routes not direct swap that tokens will get same error.enter image description here

AccessException: composer network ping does not generate certificates

I am trying to issue a new identity to a participant, create a composer card and import it.
My base.cto file is
namespace com.algorythmix.base
participant Department identified by departmentId {
o String departmentId
}
My function to issue an identity
const initIdentities = () => {
return new Promise(async function(resolve, reject) {
try {
const businessNetworkConnection = new BusinessNetworkConnection();
await businessNetworkConnection.connect(adminCardName);
let departmentRegistry = await businessNetworkConnection.getParticipantRegistry(`${BASE_NS}.Department`);
let departmentOne = await departmentRegistry.get('departmentOne');
let deptOne = await businessNetworkConnection.issueIdentity(`${BASE_NS}.Department#${departmentOne.departmentId}`, 'departmentOne');
console.log(`userID = ${deptOne.userID}`);
console.log(`userSecret = ${deptOne.userSecret}`);
let departmentTwo = await departmentRegistry.get('departmentTwo');
let deptTwo = await businessNetworkConnection.issueIdentity(`${BASE_NS}.Department#${departmentTwo.departmentId}`, 'departmentTwo');
console.log(`userID = ${deptTwo.userID}`);
console.log(`userSecret = ${deptTwo.userSecret}`);
const adminConnection = new AdminConnection(); // { cardStore: $SOME_PATH_VARIABLE } to change def2ault card storage path
await adminConnection.connect(adminCardName); // Confirm this
console.log('connected');
const cardOne = new IdCard({
userName: 'departmentOne',
version: 1,
enrollmentSecret: deptOne.userSecret,
businessNetwork: 'chips'
}, connectionProfile);
const cardTwo = new IdCard({
userName: 'departmentTwo',
version: 1,
enrollmentSecret: deptTwo.userSecret,
businessNetwork: 'chips'
}, connectionProfile);
console.log('importing card one');
await adminConnection.importCard('departmentOne', cardOne);
await adminConnection.importCard('departmentTwo', cardTwo);
console.log('imported card two');
await businessNetworkConnection.disconnect();
await adminConnection.disconnect();
resolve();
} catch (e) {
reject(e);
};
});
};
Where adminCardName is the one generated when using composer network start command as per the basic tutorial provided here https://hyperledger.github.io/composer/latest/tutorials/deploy-to-fabric-single-org
And connectionProfile is taken from the above page as well. I have double checked the connection profile used by the admin#chips card and the one I have used is exactly the same.
Once I run the function, in composer card list, a card called departmentOne and departmentTwo is listed with the Business network shown as chips (as expected).
Now when I run composer network ping -c departmentOne, I get the error
Error: 2 UNKNOWN: error executing chaincode: transaction returned with failure: AccessException: Participant 'com.algorythmix.base.Department#departmentOne' does not have 'READ' access to resource 'org.hyperledger.composer.system.Network#chips#0.2.0'
Command failed
I have
1) Deleted permissions.acl which as per the documentation results in everyone getting full access
2) used following permissions.acl file
rule Default {
description: "Allow all participants access to all resources"
participant: "com.algorythmix.base.Department"
operation: ALL
resource: "org.hyperledger.composer.system.Network"
action: ALLOW
}
rule NetworkAdminUser {
description: "Grant business network administrators full access to user resources"
participant: "org.hyperledger.composer.system.NetworkAdmin"
operation: ALL
resource: "**"
action: ALLOW
}
rule NetworkAdminSystem {
description: "Grant business network administrators full access to system resources"
participant: "org.hyperledger.composer.system.NetworkAdmin"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}
To specifically give the participant access to the network. I have also uploaded the .bna to composer-playground and it works over there as expected.
Can someone please guide me, as to what I am doing wrong?
Info:
Ubuntu - 16.0.4
Fabric - 1.1
Composer - 0.19.11
Node - 8.9.1
the error 'org.hyperledger.composer.system.Network#chips#0.2.0' suggests the underlying participant does not have the minimal READ access to the actual business network.
I would suggest a rule (rule 2) something like this:
rule ReadNetwork {
description: "Allow all participants to read network"
participant: "org.hyperledger.composer.system.Participant"
operation: READ
resource: "org.hyperledger.composer.system.Network"
action: ALLOW
}
I solved the same issue by changing the version in package.json file.

Hyperledger Composer issue identity but missing business card

I am working in a proof of concept with a Node.js application and 'composer-client' npm module.
I have tried different commands such as adding a participant, adding an asset and performing a transaction and everything seems to work correctly.
However, when I try to issue a new identity I do not get the results that I expect. I execute my Node.js application with the following code:
var businessNetwork = new BusinessNetworkConnection();
return businessNetwork.connect('admin#tutorial-network')
.then(() => {
return businessNetwork.issueIdentity('org.acme.biznet.Trader#Trader_001', 'usr001')
})
.then((result) => {
console.log(`userID = ${result.userID}`);
console.log(`userSecret = ${result.userSecret}`);
})
.catch((error) => {
console.error(error);
});
Then, UserId and UserSecret are displayed at console log. After that, I try to do a ping to Business Network:
var businessNetwork = new BusinessNetworkConnection();
return businessNetwork.connect('usr001#tutorial-network')
.then(() => {
return businessNetwork.ping();
})
.then((result) => {
console.log(`participant = ${result.participant ? result.participant : '<no participant found>'}`);
})
.catch((error) => {
console.error(error);
});
However, I get the following error message:
{ Error: Card not found: usr001#tutorial-network
at IdCard.fromDirectory.catch.cause (/home/user.name/git_repositories/nodejs/first.blockchain.test/node_modules/composer-common/lib/cardstore/filesystemcardstore.js:73:27)
at <anonymous>
cause:
{ Error: Unable to read card directory: /home/user.name/.composer/cards/user001#tutorial-network
If I execute the command composer identity list -c admin#tutorial-network, I get the following output:
$class: org.hyperledger.composer.system.Identity
identityId: 9b49f67c262c0ae23e1e0c4a8dc61c4a12b5119df2b6a49fa2e02fa56b8818c3
name: usr001
issuer: 27c582d674ddf0f230854814b7cfd04553f3d0eac55e37d915386c614a5a1de9
certificate:
state: ISSUED
participant: resource:org.acme.biznet.Trader#Trader_001
But, I am not able to find the business card.
It works for me. I'm using composer 0.15.1.
var businessNetwork = new BusinessNetworkConnection();
return businessNetwork.connect('admin#carauction-network')
.then(() => {
return businessNetwork.ping();
})
.then((result) => {
console.log(`participant = ${result.participant ? result.participant : '<no participant found>'}`);
})
.catch((error) => {
console.error(error);
});
Output is like this
linux1#fabric:~/eventclient$ node event.js
participant = org.hyperledger.composer.system.NetworkAdmin#admin
You may need to import ID card to wallet ?
composer card import --file networkadmin.card
I had a similar issue late last week. Part of the upgrade instructions from V0.14 to V0.15 states that we have to delete the (if existing) ~/.composer, ~/.composer-connection-profiles and ~/.composer-credentials. I skipped that step on my first upgrade to v01.5 and encountered the error you are seeing. Went back and deleted those three folders, reinstalled the binaries and rechecked docker image status. Error went away and has not reappeared.
You named the new card user001, not user001##tutorial-network. Try connecting with just user001 as your connection card name.
I used the following command to create a card for the participant using the enrollment secret obtained from the javascript.
composer card create -u usr001 -s <enrollment_secret> -f usr001.card -n tutorial-network -p connection.json
You probably created the connection.json needed in some step before in the tutorial you are following. If this file is not available explicitly, you may get it from the composer wallet. In the current version, it can be located in /home/your_user/.composer/cards/. If you are only following the tutorial, any connection.json in this directory will do.
After that, you must add the credential created to the wallet using:
composer card import -f usr001.card
Your code for testing the issued identity is correct.

Hyperledger Composer BusinessNetwork Connection - 0.14.3 cannot connect

I am trying to use BusinessNetworkConnection for NodeJS, but how do I get the credentials from a deployed BNA on playground and save it in my server directory?
I am getting
2017-11-03T13:07:32.83-0400 [APP/PROC/WEB/0] ERR (node:62)
UnhandledPromiseRejectionWarning: Unhandled promise rejection
(rejection id: 1): Error: Error trying login and get user Context.
Error: Error trying to enroll user or load channel configuration.
Error: Enrollment failed with errors
[[{"code":400,"message":"Authorization failure"}]]
when I try using the code
const BusinessNetworkConnection = require("composer-client").BusinessNetworkConnection;
this.businessNetworkConnection = new BusinessNetworkConnection();
this.CONNECTION_PROFILE_NAME = "ibm-bc-org1";
this.businessNetworkIdentifier = "giveback";
this.businessNetworkConnection
.connect(
this.CONNECTION_PROFILE_NAME,
this.businessNetworkIdentifier,
"admin",
"adminpw"
)
.then(result => {
this.businessNetworkDefinition = result;
console.log("BusinessNetworkConnection: ", result);
})
I have a directory /home/vcap/app/.composer-connection-profiles/ibm-bc-org1 with a connection.json file that references /home/vcap/app/.composer-credentials/ibm-bc-org1 for my credentials. The code worked for composer#0.13.2 but now I moved over to composer#0.14.3. I removed the previous credentials and created a new playground etc, everything is fresh and clean.
There is a work around when something like this happens. Because I am trying to connect with the credentials that Composer created the with admin || adminpw. You can just define a new participant in your model file and then give that participant system permissions to query and listen for events that the Historian emits.
For example in your model.cto:
participant ServerAdmin identified by serverhash {
// ServerAdmin is a type of participant
o String serverhash
}
And in your permissions.acl add :
rule ServerAdminUser {
description: "Grant business network administrators full access to
user resources"
participant: "org.acme.sample.ServerAdmin"
operation: ALL
resource: "**"
action: ALLOW
}
rule ServerAdminSystem {
description: "Grant business network administrators full access to system resources"
participant: "org.acme.sample.ServerAdmin"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}
Then after the network has been deployed by Composer on playground, you can add this participant VIA the REST API, and issue it a new identity. This will give you a User ID and User Secret with which you can use in BusinessNetworkConnection.connect()

Resources