Created
March 28, 2022 21:19
-
-
Save vit0rr/3fb5dccbafe4b42da6f07a1cb05465f0 to your computer and use it in GitHub Desktop.
Transfer Token Ethereum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function TransferPlayerClash(ctx: any, req: any, res: any) { | |
try { | |
const { web3, settings } = ctx; | |
let interfaceJson = [ | |
{ | |
inputs: [], | |
stateMutability: "nonpayable", | |
type: "constructor", | |
}, | |
{ | |
inputs: [ | |
{ | |
internalType: "address", | |
name: "account", | |
type: "address", | |
}, | |
], | |
name: "balanceOf", | |
outputs: [ | |
{ | |
internalType: "uint256", | |
name: "", | |
type: "uint256", | |
}, | |
], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [], | |
name: "decimals", | |
outputs: [ | |
{ | |
internalType: "uint8", | |
name: "", | |
type: "uint8", | |
}, | |
], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [], | |
name: "name", | |
outputs: [ | |
{ | |
internalType: "string", | |
name: "", | |
type: "string", | |
}, | |
], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [], | |
name: "symbol", | |
outputs: [ | |
{ | |
internalType: "string", | |
name: "", | |
type: "string", | |
}, | |
], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [], | |
name: "totalSupply", | |
outputs: [ | |
{ | |
internalType: "uint256", | |
name: "", | |
type: "uint256", | |
}, | |
], | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
inputs: [ | |
{ | |
internalType: "address", | |
name: "_to", | |
type: "address", | |
}, | |
{ | |
internalType: "uint256", | |
name: "value", | |
type: "uint256", | |
}, | |
], | |
name: "transfer", | |
outputs: [ | |
{ | |
internalType: "bool", | |
name: "", | |
type: "bool", | |
}, | |
], | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
]; | |
let contract = new web3.eth.Contract( | |
interfaceJson, | |
settings.clashTokenAddress, | |
{ | |
from: "0x001F069d58Fd62fa8e92f8E062e04389210a91f5", | |
} | |
); | |
let keypair = web3.eth.accounts.privateKeyToAccount( | |
""//privatekey | |
); | |
let tx = contract.methods.transfer( | |
"0x001F069d58Fd62fa8e92f8E062e04389210a91f5", | |
3000000000 | |
); | |
tx.gas = 55000; | |
let txSigned = await keypair.signTransaction(tx); | |
await web3.eth.sendSignedTransaction(txSigned.rawTransaction); | |
res | |
.status(200) | |
.json({ success: true, transactionHash: txSigned.transactionHash }); | |
} catch (e: any) { | |
console.log(e); | |
res.status(500).json({ success: false, error: e.message }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment