当连接到支持JWT公钥认证的Besu网络时,如何将令牌添加到JsonRpcProvider (醚5.0.8)?下面是当前代码(在添加JWT令牌之前):
let provider_url = "http://node-ip:80"
const provider = new ethers.providers.JsonRpcProvider(provider_url);
let wallet = new ethers.Wallet(privateKey, provider); //<<==generate wallet for the provider above根据上面的Besu文档,JWT令牌可以在header后面添加:
curl -X POST -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJwZXJtaXNzaW9ucyI6WyIqOioiXSwidXNlcm5hbWUiOiJ1c2VyMiIsImlhdCI6MTU1MDQ2MTQxNiwiZXhwIjoxNTUwNDYxNzE2fQ.WQ1mqpqzRLHaoL8gOSEZPvnRs_qf6j__7A3Sg8vf9RKvWdNTww_vRJF1gjcVy-FFh96AchVnQyXVx0aNUz9O0txt8VN3jqABVWbGMfSk2T_CFdSw5aDjuriCsves9BQpP70Vhj-tseaudg-XU5hCokX0tChbAqd9fB2138zYm5M' -d '{"jsonrpc":"2.0","method":"net_listening","params":[],"id":1}' http://localhost:8545发布于 2021-04-21 19:17:11
连接到启用JWT的Besu网络需要StaticJsonRpcProvider。以下是工作代码:
connection.url = GLOBAL.PROVIDER_URL; //url for besu rpc node
connection.headers = {
"Authorization" : `Bearer ${ tokenBesu }` //<<==tokenBesu is the JWT token for authorization
};
const provider = new ethers.providers.StaticJsonRpcProvider(connection, 2018); //2018 is network/chain IDhttps://ethereum.stackexchange.com/questions/96627
复制相似问题