创建基于区块链的电子商务市场
在区块链技术的浪潮下,构建一个基于区块链的电子商务市场成为了许多开发者的目标。下面将详细介绍如何创建这样一个市场,包括智能合约部署、各组件功能更新等内容。
智能合约部署与全局访问
当使用Truffle成功部署智能合约时,会创建一个 build 文件夹,其中包含了dApp可能需要的重要智能合约参数。为了让外部组件更方便地访问合约对象,我们需要修改 setup 函数,使其能全局访问合约对象。以下是修改后的代码:
async setup() {
// Create the contract instance
window.myWeb3 = new MyWeb3(ethereum)
try {
await ethereum.enable();
} catch (error) {
console.error('You must approve this dApp to interact with it')
}
window.user = (await myWeb3.eth.getAccounts())[0]
window.contract = new myWeb3.eth.Contract(ABI.abi,
ABI.networks['3'].address, {
from: user
})
await this.getLatestProducts(9)
await this.displayProducts
构建区块链电商市场
超级会员免费看
订阅专栏 解锁全文
90

被折叠的 条评论
为什么被折叠?



