Surou 发布的文章

How to check if Ethereum address is valid or not


web3.js

const address = "0x0089d53F703f7E0843953D48133f74cE247184c2"
let result = Web3.utils.isAddress(address)
console.log(result)  // => true

web3j

社区fork为其增加了isAddress commit
https://github.com/bcskill/web3j

package org.web3j.utils;

import org.junit.Test;

import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertTrue;

import static org.web3j.utils.Account.isAddress;

public class AccountTest {
    @Test
    public void verifyIsAddress() {
        String validLowerCaseAddress = "0x3de8c14c8e7a956f5cc4d82beff749ee65fdc358";
        assertTrue(isAddress(validLowerCaseAddress));
        String validChecksumAddress = "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359";
        assertTrue(isAddress(validChecksumAddress));
        String invalidLengthAddress = "0x3de8c14c8e7a956f5cc4d82beff749ee65bac35";
        assertFalse(isAddress(invalidLengthAddress));
        String invalidChecksumAddress = "0x3de8c14c8E7a956f5cc4d82beff749ee65fdc358";
        assertFalse(isAddress(invalidChecksumAddress));
    }
} 

参考

https://piyopiyo.medium.com/how-to-check-if-ethereum-address-is-valid-or-not-ef587b6c4819
https://github.com/assafY/web3j.git


EOS 如何设置付款人


nodeos v2.2 发布后,可以使用资源支付者功能来赞助交易的资源。要设置一个事务相关的资源单独付款人,一个添加resource_payer对象到您的交易指定payer,max_net_bytes,max_cpu_us,和max_memory_bytes。此功能需要RESOURCE_PAYER在链上启用协议功能。

此功能的典型用例是服务或应用程序为交易的资源而不是其用户付费。由于交易中的用户和付款人都需要授权,因此可能的工作流程是交易由用户的钱包应用程序签名,然后在发送到 nodeos 之前也由服务/应用程序签名。

{
    resource_payer: {
        payer: 'alice',
        max_net_bytes: 4096,
        max_cpu_us: 400,
        max_memory_bytes: 0
    },
    actions: [{
        account: 'eosio.token',
        name: 'transfer',
        authorization: [{
            actor: 'bob',
            permission: 'active',
        }, {
            actor: 'alice',
            permission: 'active',
        }],
        data: {
            from: 'bob',
            to: 'alice',
            quantity: '0.0001 SYS',
            memo: 'resource payer',
        },
    }]
}