microai
@microai

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

ERC20 で他人のトークンを他人に送れるのを防ぎたい

それほどプログラミングは独学なので、用語の使い方が間違っているかもしれません。予めご了承ください。

ERC20を何も考えずに使用すると他人のウォレットから自分にトークンを送れたりてしまう?

MyToken.sol

contract MyToken is ERC20, ERC20Burnable, Pausable, Ownable, ERC20Permit, ERC20Votes

openzeppelin を使用して独自トークンを作成しています。

ERC20.sol に

function transfer(address to, uint256 amount) public virtual override returns (bool) {
    address owner = _msgSender();
    _transfer(owner, to, amount);
    return true;
}

上記のように書かれており、MyToken.sol では、transfer をオーバーライドしていません
なお、環境は、Solidity 0.8.9 + Hardhat + Metamask です。

発生している不具合

HTMLに、

<script>

test();

async function test() {
    web3 = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:8545/'));
    token_contract = new web3.eth.Contract(token_abi, token_address);
    
    await token_contract.methods.transfer("0x70997970C51812dc3A010C7d01b50e0d17dc79C8", web3.utils.toWei("198", "ether")).send({
        from: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
        gas: 200000
    }).on("receipt", async (response) => {
    });
}
</script>

と記載しています。
Metamaskでは 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 のアカウントで接続しています。
この例は、自分から他人(0x70997970C51812dc3A010C7d01b50e0d17dc79C8) にTransfer しているので、問題ないのですが、

<script>

test();

async function test() {
    web3 = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:8545/'));
    token_contract = new web3.eth.Contract(token_abi, token_address);
    
    await token_contract.methods.transfer("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", web3.utils.toWei("198", "ether")).send({
        from: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
        gas: 200000
    }).on("receipt", async (response) => {
    });
}
</script>

このように、他人から自分へであったり、

<script>

test();

async function test() {
    web3 = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:8545/'));
    token_contract = new web3.eth.Contract(token_abi, token_address);
    
    await token_contract.methods.transfer("0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65", web3.utils.toWei("198", "ether")).send({
        from: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
        gas: 200000
    }).on("receipt", async (response) => {
    });
}
</script>

このように他人から他人へのTransfer も成功してしまいます。(Metamaskで確認すると実際に送金されています。)

解決策

全く思いつきません・・・
どなたかヒントだけでもいただけると助かります。

0

No Answers yet.

Your answer might help someone💌