#javascript #web3 #web3js #kovan
Вопрос:
У меня есть следующий код, который возвращает хэш tx, но когда я вызываю квитанцию, он возвращает значение null:
const privateKey1Buffer = Buffer.from(privateKey1, 'hex')
var _addressProvider = '0x506B0B2CF20FAA8f38a4E2B524EE43e1f4458Cc5';
var flashloanv1Contract = new web3.eth.Contract([{"inputs":[{"internalType":"address","name":"_addressProvider","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_assetAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"LogWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"addressesProvider","outputs":[{"internalType":"contract ILendingPoolAddressesProviderV1","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_reserve","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_fee","type":"uint256"},{"internalType":"bytes","name":"_params","type":"bytes"}],"name":"executeOperation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"flashloan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_assetAddress","type":"address"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]);
var flashloanv1 = flashloanv1Contract.deploy({
data: '0x608060405234801561001057600080fd5b506040516116d03803806116d08339818101604052602081101561003357600080fd5b810190808051906020019092919050505080600061005561013b60201b60201c565b9050806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508073ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35080600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050610143565b600033905090565b61157e806101526000396000f3fe6080604052600436106100745760003560e01c80638da5cb5b1161004e5780638da5cb5b14610139578063c72c4d1014610190578063ee872558146101e7578063f2fde38b146102a15761007b565b806336c404771461008057806351cff8d9146100d1578063715018a6146101225761007b565b3661007b57005b600080fd5b34801561008c57600080fd5b506100cf600480360360208110156100a357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506102f2565b005b3480156100dd57600080fd5b50610120600480360360208110156100f457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506105af565b005b34801561012e57600080fd5b5061013761084f565b005b34801561014557600080fd5b5061014e6109bd565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561019c57600080fd5b506101a56109e6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156101f357600080fd5b5061029f6004803603608081101561020a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001909291908035906020019064010000000081111561025b57600080fd5b82018360208201111561026d57600080fd5b8035906020019184600183028401116401000000008311171561028f57600080fd5b9091929391929390505050610a0c565b005b3480156102ad57600080fd5b506102f0600480360360208110156102c457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a97565b005b6102fa610c8a565b73ffffffffffffffffffffffffffffffffffffffff166103186109bd565b73ffffffffffffffffffffffffffffffffffffffff16146103a1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b60606040518060200160405280600081525090506000670de0b6b3a764000090506000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16630261bf8b6040518163ffffffff1660e01b815260040160206040518083038186803b15801561042c57600080fd5b505afa158015610440573d6000803e3d6000fd5b505050506040513d602081101561045657600080fd5b810190808051906020019092919050505090508073ffffffffffffffffffffffffffffffffffffffff16635cffe9de308685876040518563ffffffff1660e01b8152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610542578082015181840152602081019050610527565b50505050905090810190601f16801561056f5780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801561059157600080fd5b505af11580156105a5573d6000803e3d6000fd5b5050505050505050565b6105b7610c8a565b73ffffffffffffffffffffffffffffffffffffffff166105d56109bd565b73ffffffffffffffffffffffffffffffffffffffff161461065e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156107005760003090508073ffffffffffffffffffffffffffffffffffffffff163191503373ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f193505050501580156106f9573d6000803e3d6000fd5b50506107e6565b8173ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561077d57600080fd5b505afa158015610791573d6000803e3d6000fd5b505050506040513d60208110156107a757600080fd5b810190808051906020019092919050505090506107e533828473ffffffffffffffffffffffffffffffffffffffff16610c929092919063ffffffff16565b5b8173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f9207361cc2a04b9c7a06691df1eb87c6a63957ae88bf01d0d18c81e3d1272099836040518082815260200191505060405180910390a35050565b610857610c8a565b73ffffffffffffffffffffffffffffffffffffffff166108756109bd565b73ffffffffffffffffffffffffffffffffffffffff16146108fe576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b610a163086610d4a565b841115610a6e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e8152602001806114f1602e913960400191505060405180910390fd5b6000610a838486610e7490919063ffffffff16565b9050610a8f8682610efc565b505050505050565b610a9f610c8a565b73ffffffffffffffffffffffffffffffffffffffff16610abd6109bd565b73ffffffffffffffffffffffffffffffffffffffff1614610b46576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610bcc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806114a56026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600033905090565b610d458363a9059cbb60e01b8484604051602401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610fb3565b505050565b600073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610db3578273ffffffffffffffffffffffffffffffffffffffff16319050610e6e565b8173ffffffffffffffffffffffffffffffffffffffff166370a08231846040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015610e3057600080fd5b505afa158015610e44573d6000803e3d6000fd5b505050506040513d6020811015610e5a57600080fd5b810190808051906020019092919050505090505b92915050565b600080828401905083811015610ef2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ed6ff7606040518163ffffffff1660e01b815260040160206040518083038186803b158015610f6657600080fd5b505afa158015610f7a573d6000803e3d6000fd5b505050506040513d6020811015610f9057600080fd5b81019080805190602001909291905050509050610fae8184846110a2565b505050565b6060611015826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff166112049092919063ffffffff16565b905060008151111561109d5780806020019051602081101561103657600080fd5b810190808051906020019092919050505061109c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a81526020018061151f602a913960400191505060405180910390fd5b5b505050565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156111d35760008373ffffffffffffffffffffffffffffffffffffffff168260405180600001905060006040518083038185875af1925050503d806000811461114a576040519150601f19603f3d011682016040523d82523d6000602084013e61114f565b606091505b5050905060011515811515146111cd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260158152602001807f436f756c646e2774207472616e7366657220455448000000000000000000000081525060200191505060405180910390fd5b506111ff565b6111fe83828473ffffffffffffffffffffffffffffffffffffffff16610c929092919063ffffffff16565b5b505050565b6060611213848460008561121c565b90509392505050565b606082471015611277576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806114cb6026913960400191505060405180910390fd5b611280856113c5565b6112f2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601d8152602001807f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000081525060200191505060405180910390fd5b600060608673ffffffffffffffffffffffffffffffffffffffff1685876040518082805190602001908083835b60208310611342578051825260208201915060208101905060208303925061131f565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146113a4576040519150601f19603f3d011682016040523d82523d6000602084013e6113a9565b606091505b50915091506113b98282866113d8565b92505050949350505050565b600080823b905060008111915050919050565b606083156113e85782905061149d565b6000835111156113fb5782518084602001fd5b816040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611462578082015181840152602081019050611447565b50505050905090810190601f16801561148f5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b939250505056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c496e76616c69642062616c616e63652c207761732074686520666c6173684c6f616e207375636365737366756c3f5361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a2646970667358221220b6719207a7f420e483eabbd1c5e0e097deddbb9b28b60713b2508fc5de62bd0c64736f6c63430006060033',
arguments: [
_addressProvider,
]
});
const txObject = {from: account['address'],
nonce: 23,
gasLimit: web3.utils.toHex(500),
gas: web3.utils.toHex(4700000)
};
const tx = new Tx(txObject, { 'chain': 'kovan' });
tx.sign(privateKey1Buffer);
const serializedTx = tx.serialize();
const raw = '0x' serializedTx.toString('hex');
async function testBasicExample(){
const transaction = await web3.eth.sendSignedTransaction(raw, (err, tx) =>{
console.log(err, tx);
var receipt = web3.eth.getTransactionReceipt(tx)
.then(console.log);
})
}
testBasicExample();
Я использую пример (https://www.quicknode.com/guides/defi/how-to-make-a-flash-loan-using-aave) с поставщиком адресов 0x506B0B2CF20FAA8f38a4E2B524EE43e1f4458Cc5, но не удалось его развернуть.
Комментарии:
1. Квитанция может быть недоступна сразу после того, как вы ее подпишете.
sendSignedTransaction
решает, когда квитанция о транзакции доступна, чтобы вы могли попытаться войтиtransaction
2. При попытке зарегистрировать переменную транзакцию программа зависает..