先占位,后续有机会在补充细节,react-native
实现的Android钱包客户端:
Demo代码(仅登录)
import {WebView} from 'react-native-webview';
import {ethers} from 'ethers';
const nodeProvider = ''; // 改成可用的
const address = ''; // 改成自己的
const privateKey = ''; // 改成自己的
const providerMainnet = new ethers.providers.JsonRpcProvider(nodeProvider);
let walletProviderMainnet = new ethers.Wallet(privateKey, providerMainnet);
const injectedJavaScript = `
window.ethereum = {};
window.ethereum.isMetaMask = true;
window.ethereum.isConnected = function() { return true };
window.ethereum.provider = ${JSON.stringify(providerMainnet)};
window.ethereum.wallet = {};
window.ethereum.wallet.provider = ${JSON.stringify(
walletProviderMainnet.provider,
)};
window.ethereum.wallet.address = '${address}';
window.ethereum.selectedAddress = '${address}';
window.ethereum.eth_requestAccounts = async function(tx) {
console.log('---------eth_requestAccounts-----------', tx)
return '${address}';
};
window.ethereum.wallet.signTransaction = async function(tx) {
console.log('---------signTransaction-----------', tx)
const signedTx = await walletProviderMainnet.signTransaction(tx);
return signedTx;
};
window.ethereum.request = function(args = {}) {
console.log('---------request-----------', args)
const { method, params } = args
return window.ethereum.send(method, params)
};
window.ethereum.send = function(method, params) {
console.log('---------send-----------', method, params)
return new Promise(function(resolve, reject) {
window.ReactNativeWebView.postMessage(JSON.stringify({
type: 'bsc',
payload: {
method: method,
params: params,
}
}));
document.addEventListener("message", function(event) {
console.log('---------message-----------', event)
const data = JSON.parse(event.data) || {}
if (data.type === 'ethereum' && data.payload.id === method) {
if (data.payload.error) {
reject(data.payload.error);
} else {
resolve(data.payload.result);
}
}
}, { once: true });
});
};
window.ethereum.enable = async function() {
console.log('---------enable-----------')
let accounts = await window.ethereum.wallet.provider.listAccounts();
accounts = window.ethereum.wallet.address
return accounts;
};
window.ethereum.send('eth_accounts').then(accounts => {
console.log('---------eth_accounts-----------', accounts)
window.ReactNativeWebView.postMessage(JSON.stringify({
type: 'accounts',
data : accounts
}));
}).catch(error => {
console.log('Error:', error);
});
`;
const BrowserTab = function () {
const webviewRef = useRef(null);
const handleWebViewMessage = async function (event: any) {
console.log('-------onMessage-----------', event);
const {data} = event.nativeEvent;
const {type, payload = {}} = JSON.parse(data) || {};
const {method} = payload;
console.log(webviewRef.current);
if (webviewRef.current) {
method === 'eth_requestAccounts' &&
webviewRef.current.postMessage(
JSON.stringify({
type: 'ethereum',
payload: {
id: 'eth_requestAccounts',
result: [address],
},
}),
'*',
);
method === 'eth_chainId' &&
webviewRef.current.postMessage(
JSON.stringify({
type: 'ethereum',
payload: {
id: 'eth_chainId',
result: 5,
},
}),
'*',
);
}
};
return (
);
};
export default BrowserTab;
参考文章
https://stackoverflow.com/questions/75633905/how-to-inject-a-wallet-into-the-browser-from-mobile-react-native
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
参加此认证的考生应具备在实现、管理和监视组织的 Microsoft Azure 环境方面的学科专业知识,包括: 虚拟网络 存储 计算 标识 安全性 调控 此外,你还应具有以下方面的经验: PowerShell Azure CLI服务器托管网 Azure 门户 …