宅D嘉
有著十年以上的軟體開發經驗,喜歡投資理財,目前喜歡研究區塊鏈相關,了解虛擬貨幣投資或者是區塊鏈開發,喜歡把複雜的東西簡單化,樂於分享我的理財投資生活。
// SPDX-License-Identifier: MITpragma solidity ^0.8.13;//建一個contract,需先佈署到區塊鏈上面,後面interface才能調用contract Counter {uint public count;function increment() external {count ++;//每次調用就+1}}//實現function接口interface ICounter {function increment() external;}contract MyContract {//從接口去調用另外一個smart contractfunction incrementCounter(address _counter) external {ICounter(_counter).increment();}}
// SPDX-License-Identifier: MITpragma solidity ^0.8.13;//Uniswap exampleinterface UniswapV2Factory {function getPair(address tokenA, address tokenB) external view returns(address pair);}interface UniswapV2Pair {function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLost);}contract UniswapExample {address private factory = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;address private dai = 0x6B175474E89094C44Da98b954EedeAC495271d0F;address private weth = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;function getTokenReserves() external view returns (uint, uint) {address pair = UniswapV2Factory(factory).getPair(dai, weth);(uint reserve0, uint reserve1, ) = UniswapV2Pair(pair).getReserves();return (reserve0, reserve1);}}