@abridged/web-wallet-frame-sdk 中文文档教程
Abridged Web Wallet Frame Provider
该提供商通过使用父 iFrame 和子 dapp web3 polyfill 将 dapps 连接到 Abridged web wallet sdk。
<代码> npm 安装@abridged/web-wallet-frame-sdk
父 iFrame 应该构造如下:
import { FrameProvider } from "@abridged/web-wallet-frame-sdk";
// SDK - Abridged SDK reference
// window - browser window reference object
// WALLET_PUB_KEY - user's web wallet public key
let wallet = new FrameProvider(sdk, window, WALLET_PUB_KEY);
// Set custom UI transaction prompt
wallet.setPrompt( function(msg, approve, reject) {
var retVal = confirm("Do you want to continue? Transaction: " + msg);
// Approve transaction
if(retVal) approve();
// Reject transaction
else reject();
});
// Allows the dapp to request on/off ramp flow to trigger in the web wallet
// Can optionally be provided erc20 address to onramp directly to token if possible
// Handler is async to allow for waiting on on/off ramp completion
wallet.setRamp( aysnc function(action, token) {
if(action==="buy") {
if(token === null) console.log('wants to buy eth");
else console.log('wants to buy", token);
}
if(action==="sell") {
if(token === null) console.log('wants to sell eth");
else console.log('wants to buy", token);
}
return true; // if successful
});
// The setup function will change the iFrame object src to the target location and start listening for web3 calls from child.
//
// refiFrame - current iFrame reference to iFrame dom object
// frameSrc - url for the IFrame to load once provider is loaded
await wallet.setup(refiFrame, frameSrc);
// Be sure to call this if your React component unloads or redraws
wallet.destroy();
子 iFrame 应该导入 polyfill:
import '@jadbox/iframe-provider-polyfill'
或通过 html 添加:
<script src="https://cdn.jsdelivr.net/npm/@jadbox/iframe-provider-polyfill/dist/index.js" type="text/javascript"></script>
Abridged Web Wallet Frame Provider
This provider connects dapps into the Abridged web wallet sdk, by using a parent iFrame and a child dapp web3 polyfill.
npm install @abridged/web-wallet-frame-sdk
The parent iFrame should be constructed like:
import { FrameProvider } from "@abridged/web-wallet-frame-sdk";
// SDK - Abridged SDK reference
// window - browser window reference object
// WALLET_PUB_KEY - user's web wallet public key
let wallet = new FrameProvider(sdk, window, WALLET_PUB_KEY);
// Set custom UI transaction prompt
wallet.setPrompt( function(msg, approve, reject) {
var retVal = confirm("Do you want to continue? Transaction: " + msg);
// Approve transaction
if(retVal) approve();
// Reject transaction
else reject();
});
// Allows the dapp to request on/off ramp flow to trigger in the web wallet
// Can optionally be provided erc20 address to onramp directly to token if possible
// Handler is async to allow for waiting on on/off ramp completion
wallet.setRamp( aysnc function(action, token) {
if(action==="buy") {
if(token === null) console.log('wants to buy eth");
else console.log('wants to buy", token);
}
if(action==="sell") {
if(token === null) console.log('wants to sell eth");
else console.log('wants to buy", token);
}
return true; // if successful
});
// The setup function will change the iFrame object src to the target location and start listening for web3 calls from child.
//
// refiFrame - current iFrame reference to iFrame dom object
// frameSrc - url for the IFrame to load once provider is loaded
await wallet.setup(refiFrame, frameSrc);
// Be sure to call this if your React component unloads or redraws
wallet.destroy();
The child iFrame should import the polyfill:
import '@jadbox/iframe-provider-polyfill'
or add via html:
<script src="https://cdn.jsdelivr.net/npm/@jadbox/iframe-provider-polyfill/dist/index.js" type="text/javascript"></script>
更多
你可能也喜欢
- @0x706b/coc-diagnostic 中文文档教程
- @0xkilo/axe-sdk 中文文档教程
- @2bitlab/state 中文文档教程
- @2hats/react-native-fetch-blob 中文文档教程
- @36node/template-expo 中文文档教程
- @3fv/type-enum-events 中文文档教程
- @4geit/rct-project-builder 中文文档教程
- @51npm/freedom-middleware-serve 中文文档教程
- @555platform/555-js-sdk 中文文档教程
- @aacassandra/client-xlsx2json 中文文档教程